public bool AssignDelegate(Employee emp, string deptid) { List <Employee> emplist = erepo.FindEmpByDept(deptid); foreach (Employee e in emplist) { if (emp.DelegateFromDate >= e.DelegateFromDate && emp.DelegateFromDate <= e.DelegateToDate) { if (emp.Id != e.Id) { throw new Exception("Conflict of delegate dates with " + e.Name + ". Please try again"); } } if (emp.DelegateToDate >= e.DelegateFromDate && emp.DelegateToDate <= e.DelegateToDate) { if (emp.Id != e.Id) { throw new Exception("Conflict of delegate dates with " + e.Name + ". Please try again"); } } } try { Employee delegateemp = erepo.AssignDelegateDate(emp); Employee depthead = erepo.FindSupervisorByEmpId(delegateemp.Id); EmailModel email = new EmailModel(); Task.Run(async() => { EmailTemplates.AssignDelTemplate adt = new EmailTemplates.AssignDelTemplate(delegateemp, depthead); email.emailTo = delegateemp.Email; email.emailSubject = adt.subject; email.emailBody = adt.body; await mailservice.SendEmailwithccallAsync(email, emplist); }); return(true); } catch (Exception e) { throw e; } }
public bool ApprovRejAdjustmentVoucher(AdjustmentVoucher av, int approvalId) { Employee emp = erepo.FindEmpById(approvalId); DateTime dateTime = DateTime.UtcNow.Date; DateTimeOffset dt = new DateTimeOffset(dateTime, TimeSpan.Zero).ToUniversalTime(); long date = dt.ToUnixTimeMilliseconds(); try { if (emp.Role == "sm") //persist to correct column based on supervisor or manager role { av.ApprovedMgrId = emp.Id; av.ApprovedMgrDate = date; //For all approvals by manager, it will jump to final state of "approved" if (av.Status != Status.AdjVoucherStatus.rejected) { av.Status = Status.AdjVoucherStatus.approved; } avrepo.ManagerUpdateAdjustmentVoucherApprovals(av); } if (emp.Role == "ss") { av.ApprovedSupId = emp.Id; av.ApprovedSupDate = date; avrepo.SupervisorUpdateAdjustmentVoucherApprovals(av); } if (av.Status == Status.AdjVoucherStatus.pendmanapprov) { AdjustmentVoucher av1 = avrepo.FindAdjustmentVoucherById(av.Id); Employee manager = erepo.FindSupervisorByEmpId(emp.Id); Employee sup = erepo.FindEmpById(emp.Id); EmailModel email = new EmailModel(); Task.Run(async() => { EmailTemplates.PendingManagerApprovalAVTemplate apt = new EmailTemplates.PendingManagerApprovalAVTemplate(av1, manager, sup); email.emailTo = manager.Email; email.emailSubject = apt.subject; email.emailBody = apt.body; await mailservice.SendEmailAsync(email); }); } else //approved or rejected { AdjustmentVoucher av1 = avrepo.FindAdjustmentVoucherById(av.Id); if (av1.Status == Status.AdjVoucherStatus.approved) //new method for auto update of stock card upon approved adjustment vouchers { UpdateStockCardForApprovedAdjustmentVoucher(av1); } Employee clerk = erepo.FindEmpById(av1.InitiatedClerkId); Employee sup = erepo.FindEmpById((int)clerk.ManagerId); Employee manager = erepo.FindEmpById((int)sup.ManagerId); List <Employee> elist = new List <Employee>(); //Regardless of approval hierarchy or who approved, as long as its in final state of approved or rejected, clerk + supervisor + manager will get email elist.Add(sup); elist.Add(manager); EmailModel email = new EmailModel(); Task.Run(async() => { EmailTemplates.ApproveRejectAVTemplate apt = new EmailTemplates.ApproveRejectAVTemplate(av1, clerk, sup); email.emailTo = clerk.Email; email.emailSubject = apt.subject; email.emailBody = apt.body; await mailservice.SendEmailwithccallAsync(email, elist); }); } return(true); } catch (Exception m) { throw m; } }
public bool SubmiTrf(List <RequisitionDetail> rdlist) { foreach (RequisitionDetail r in rdlist) //Delete all old entries based on requisitionId { rdrepo.DeleteRequisitionDetailByRequisitionId(r); } foreach (RequisitionDetail rd in rdlist) //Create new latest entries based on requisitionId { if (rd.QtyNeeded != 0) { rdrepo.AddReqFormItem(rd); } } // Updating Requisition to "Pending Approval" status int requisitionId = (int)rdlist[0].RequisitionId; Requisition req = rrepo.FindReqByReqId(requisitionId); req.Status = Status.RequsitionStatus.pendapprov; //add the current date to be the submitted date. DateTime dateTime = DateTime.UtcNow.Date; DateTimeOffset dt = new DateTimeOffset(dateTime, TimeSpan.Zero).ToUniversalTime(); long submitdate = dt.ToUnixTimeMilliseconds(); req.SubmittedDate = submitdate; //Finding deptemp Requisition updatedreq = rrepo.UpdateRequisition(req); int deptempid = updatedreq.ReqByEmpId; Employee deptemp = erepo.FindEmpById(deptempid); //send to manager Employee depthead = erepo.FindSupervisorByEmpId(deptempid); EmailModel email = new EmailModel(); Task.Run(async() => { EmailTemplates.SubmitreqformTemplate srf = new EmailTemplates.SubmitreqformTemplate(updatedreq, depthead, deptemp); email.emailTo = depthead.Email; email.emailSubject = srf.subject; email.emailBody = srf.body; await mailservice.SendEmailAsync(email); }); //check if there is delegate Employee delegateemp = erepo.GetCurrentDelegate(submitdate, deptemp.DepartmentId); if (delegateemp != null) { //send email to delegate EmailModel email2 = new EmailModel(); Task.Run(async() => { EmailTemplates.SubmitreqformTemplate srf = new EmailTemplates.SubmitreqformTemplate(updatedreq, delegateemp, deptemp); email.emailTo = delegateemp.Email; email.emailSubject = srf.subject; email.emailBody = srf.body; await mailservice.SendEmailAsync(email); }); } return(true); }