using Comal.Classes; using InABox.Clients; using InABox.Core; using Org.BouncyCastle.Asn1.X509; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PRSDesktop { public static class FormUtils { public static void Register() { DFUtils.AddFormUtils(CanEditAssignmentForm); DFUtils.AddFormUtils(CanEditEmployeeForm); DFUtils.AddFormUtils(CanEditJobForm); DFUtils.AddFormUtils(CanEditJobITPForm); DFUtils.AddFormUtils(CanEditKanbanForm, NewKanban, KanbanOnSave); DFUtils.AddFormUtils(CanEditLeaveRequestForm); DFUtils.AddFormUtils(CanEditPurchaseOrderItemForm); DFUtils.AddFormUtils(CanEditTimeSheetForm); } public static bool CanEditAssignmentForm(AssignmentForm form, Assignment assignment) { return assignment.EmployeeLink.ID == App.EmployeeID; } public static bool CanEditEmployeeForm(EmployeeForm form, Employee employee) { return employee.ID == App.EmployeeID; } public static bool CanEditJobForm(JobForm form, Job job) { return false; } public static bool CanEditJobITPForm(JobITPForm form, JobITP jobITP) { return false; } public static bool CanEditKanbanForm(KanbanForm form, Kanban kanban) { return kanban.EmployeeLink.ID == App.EmployeeID; } private static Kanban NewKanban(DigitalForm form) { var kanban = new Kanban(); kanban.EmployeeLink.ID = App.EmployeeID; kanban.DueDate = DateTime.Today; kanban.Title = $"Form - {form.Description}"; kanban.Notes = new[] { "Created by desktop forms" }; kanban.Category = "In Progress"; return kanban; } private static void KanbanOnSave(KanbanForm form, Kanban entity) { var subscriber = new KanbanSubscriber { Assignee = true }; subscriber.Kanban.ID = entity.ID; subscriber.Employee.ID = entity.EmployeeLink.ID; new Client().Save(subscriber, ""); } public static bool CanEditLeaveRequestForm(LeaveRequestForm form, LeaveRequest leaveRequest) { return leaveRequest.EmployeeLink.ID == App.EmployeeID; } public static bool CanEditPurchaseOrderItemForm(PurchaseOrderItemForm form, PurchaseOrderItem purchaseOrderItem) { return false; } public static bool CanEditTimeSheetForm(TimeSheetForm form, TimeSheet timeSheet) { return timeSheet.EmployeeLink.ID == App.EmployeeID; } } }