public ActionResult Retrieve([Bind(Include = "CollectionDate")] RetrievalItemsWithDateDTO listWithDate) { if (ModelState.IsValid) { var selectedDate = DateTime.ParseExact(listWithDate.CollectionDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); var disbursements = CreateDisbursement(selectedDate); foreach (var disbursement in disbursements) { var repEmail = _employeeRepo.GetRepByDeptCode(disbursement.DeptCode).EmailAddress; var collectionPoint = _collectionRepo.GetById((int)disbursement.CollectionPointId); var email = new LUSSISEmail.Builder().From(User.Identity.Name).To(repEmail) .ForNewDisbursement(disbursement, collectionPoint).Build(); new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); } return(RedirectToAction("RetrievalInProcess")); } return(View("Consolidated", new RetrievalItemsWithDateDTO { RetrievalItems = CreateRetrievalList().List.ToPagedList(1, 15), CollectionDate = DateTime.Today.ToString("dd/MM/yyyy"), HasInprocessDisbursement = _disbursementRepo.HasInprocessDisbursements() })); }
public ActionResult AddDelegate(string delegateEmp, string from, string to) { if (ModelState.IsValid) { var empNum = Convert.ToInt32(delegateEmp); var newDelegate = _employeeRepo.GetById(empNum); var newDelegateEmailAdd = newDelegate.EmailAddress; var startDate = DateTime.ParseExact(from, "dd/MM/yyyy", CultureInfo.InvariantCulture); var endDate = DateTime.ParseExact(to, "dd/MM/yyyy", CultureInfo.InvariantCulture); var loginUser = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var sender = _employeeRepo.GetById(loginUser); var del = new Models.Delegate() { EmpNum = empNum, StartDate = startDate, EndDate = endDate }; _delegateRepo.Add(del); //email to new delegate var emailToNewDelegate = new LUSSISEmail.Builder().From(sender.EmailAddress) .To(newDelegateEmailAdd).ForNewDelegate().Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(emailToNewDelegate); }).Start(); } return(RedirectToAction("MyDelegate")); }
// POST api/Delegate/Create public IHttpActionResult CreateDelegate(int empnum, [FromBody] DelegateDTO delegateDto) { var d = new Delegate() { StartDate = delegateDto.StartDate, EndDate = delegateDto.EndDate, EmpNum = empnum }; _delegateRepo.Add(d); //Send email on new thread var employee = _employeeRepo.GetById(empnum); var headEmail = _employeeRepo.GetDepartmentHead(employee.DeptCode).EmailAddress; var email = new LUSSISEmail.Builder().From(headEmail).To(employee.EmailAddress) .ForNewDelegate().Build(); new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); //return delegate with id included var id = _delegateRepo.FindExistingByDeptCode(employee.DeptCode).DelegateId; delegateDto.DelegateId = id; return(Ok(delegateDto)); }
public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { try { var userManager = HttpContext.Current.GetOwinContext().Get <ApplicationUserManager>(); var user = await userManager.FindByNameAsync(model.Email); if (user == null) { return(BadRequest("No email exists in the database.")); } // Send an email with the reset password link var code = await userManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Link("Default", new { controller = "Account", action = "ResetPassword", userId = user.Id, code }); var fullName = _employeeRepo.GetEmployeeByEmail(model.Email).FullName; var email = new LUSSISEmail.Builder().From("*****@*****.**").To(model.Email) .ForResetPassword(fullName, callbackUrl).Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); } catch (Exception e) { return(Ok(e)); } return(Ok(new { Message = "Reset link sent to your email." })); } return(BadRequest("Something is wrong. Please try again.")); }
public ActionResult CreateAdjustment([Bind(Include = "Quantity,Reason,ItemNum,Sign")] AdjustmentVoucherDTO adjVoucherDto) { if (ModelState.IsValid) { var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var self = _employeeRepo.GetById(empNum); if (adjVoucherDto.Sign == false) { adjVoucherDto.Quantity = adjVoucherDto.Quantity * -1; } var stationery = _stationeryRepo.GetById(adjVoucherDto.ItemNum); stationery.AvailableQty = stationery.AvailableQty + adjVoucherDto.Quantity; stationery.CurrentQty = stationery.CurrentQty + adjVoucherDto.Quantity; _stationeryRepo.Update(stationery); var adjustment = new AdjVoucher { ItemNum = adjVoucherDto.ItemNum, Quantity = adjVoucherDto.Quantity, Reason = adjVoucherDto.Reason, Status = Pending, RequestEmpNum = empNum, CreateDate = DateTime.Today }; adjustment.Stationery = _stockAdjustmentRepo.AddStockAdjustment(adjustment); var managerEmail = _employeeRepo.GetStoreManager().EmailAddress; var supervisorEmail = _employeeRepo.GetStoreSupervisor().EmailAddress; var email1 = new LUSSISEmail.Builder().From(self.EmailAddress) .To(managerEmail).ForNewStockAdjustment(self.FullName, adjustment).Build(); var email2 = new LUSSISEmail.Builder().From(self.EmailAddress) .To(supervisorEmail).ForNewStockAdjustment(self.FullName, adjustment).Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email1); }).Start(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email2); }).Start(); return(RedirectToAction("History")); } adjVoucherDto.Stationery = _stationeryRepo.GetById(adjVoucherDto.ItemNum); return(View(adjVoucherDto)); }
// POST api/Delegate/Delete public IHttpActionResult DeleteDelegate([FromBody] DelegateDTO delegateDto) { var del = _delegateRepo.GetById(delegateDto.DelegateId); var toEmail = _employeeRepo.GetById(del.EmpNum).EmailAddress; var deptCode = _employeeRepo.GetById(del.EmpNum).DeptCode; _delegateRepo.Delete(del); //Send email var headEmail = _employeeRepo.GetDepartmentHead(deptCode).EmailAddress; var email = new LUSSISEmail.Builder().From(headEmail).To(toEmail) .ForOldDelegate().Build(); new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); return(Ok(new { Message = "Delegate has been revoked" })); }
public IHttpActionResult CreateRequisition([FromBody] RequisitionDTO requisitionDto) { var empNum = requisitionDto.RequisitionEmpNum; var employee = _employeeRepo.GetById(empNum); var isDelegated = _delegateRepo.FindCurrentByEmpNum(empNum) != null; if (isDelegated) { return(BadRequest("Delegated staff cannot make request")); } var detail = requisitionDto.RequisitionDetails.First(); var requisitionDetail = new RequisitionDetail() { ItemNum = detail.ItemNum, Quantity = detail.Quantity, }; var requisition = new Requisition() { RequisitionEmpNum = requisitionDto.RequisitionEmpNum, DeptCode = employee.DeptCode, RequestRemarks = requisitionDto.RequestRemarks, RequisitionDate = DateTime.Today, Status = RequisitionStatus.Pending, RequisitionDetails = new List <RequisitionDetail>() { requisitionDetail } }; _requistionRepo.Add(requisition); requisition.RequisitionDetails.First().Stationery = _stationeryRepo.GetById(detail.ItemNum); //Send email on new thread var headEmail = _employeeRepo.GetDepartmentHead(employee.DeptCode).EmailAddress; var email = new LUSSISEmail.Builder().From(employee.EmailAddress).To(headEmail) .ForNewRequistion(employee.FullName, requisition).Build(); new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); return(Ok(new { Message = "Requisition created" })); }
public ActionResult SubmitReq() { var deptCode = Request.Cookies["Employee"]?["DeptCode"]; var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var fullName = Request.Cookies["Employee"]?["Name"]; if (Session["MyCart"] is ShoppingCartDTO shoppingCart && shoppingCart.GetCartItemCount() > 0) { var requisition = new Requisition() { RequestRemarks = Request["remarks"], RequisitionDate = DateTime.Today, RequisitionEmpNum = empNum, Status = RequisitionStatus.Pending, DeptCode = deptCode }; _requisitionRepo.Add(requisition); foreach (var cart in shoppingCart.GetAllCartItem()) { var requisitionDetail = new RequisitionDetail() { RequisitionId = requisition.RequisitionId, ItemNum = cart.Stationery.ItemNum, Quantity = cart.Quantity }; requisitionDetail.Stationery = _requisitionRepo.AddRequisitionDetail(requisitionDetail); } Session["MyCart"] = new ShoppingCartDTO(); //Send email var headEmail = _employeeRepo.GetDepartmentHead(deptCode).EmailAddress; var email = new LUSSISEmail.Builder().From(User.Identity.Name) .To(headEmail).ForNewRequistion(fullName, requisition).Build(); new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); return(RedirectToAction("MyRequisitions")); } return(RedirectToAction("MyCart")); }
public ActionResult DeleteDelegate() { if (ModelState.IsValid) { var deptCode = Request.Cookies["Employee"]?["DeptCode"]; var oldDelegate = _delegateRepo.FindExistingByDeptCode(deptCode); var oldDelegateEmailAdd = oldDelegate.Employee.EmailAddress; var loginUser = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var sender = _employeeRepo.GetById(loginUser); //email to old delegate var emailToOldDelegate = new LUSSISEmail.Builder().From(sender.EmailAddress) .To(oldDelegateEmailAdd).ForOldDelegate().Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(emailToOldDelegate); }).Start(); _delegateRepo.DeleteByDeptCode(deptCode); } return(RedirectToAction("Index")); }
public async Task <IHttpActionResult> Process([FromBody] RequisitionDTO requisition) { if (requisition.RequisitionEmpNum == requisition.ApprovalEmpNum) { return(BadRequest("Employee cannot process its own requisition")); } var employee = _employeeRepo.GetById(requisition.ApprovalEmpNum); if (_delegateRepo.FindCurrentByDeptCode(employee.DeptCode) != null) { return(BadRequest("Must revoke current delegate to approve.")); } try { var req = await _requistionRepo.GetByIdAsync(requisition.RequisitionId); req.ApprovalEmpNum = requisition.ApprovalEmpNum; req.ApprovalRemarks = requisition.ApprovalRemarks; req.ApprovalDate = DateTime.Today; req.Status = requisition.Status; await _requistionRepo.UpdateAsync(req); //Send email var toEmail = _employeeRepo.GetById(requisition.RequisitionEmpNum).EmailAddress; var approvalEmail = _employeeRepo.GetById(requisition.ApprovalEmpNum).EmailAddress; var email = new LUSSISEmail.Builder().From(approvalEmail).To(toEmail) .ForRequisitionApproval(req).Build(); new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); return(Ok(new { Message = "Updated" })); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult Edit([Bind(Include = "DisbursementId, CollectionDate, CollectionPointId, AcknowledgeEmpNum, DeptCode, Status")] Disbursement disbursement) { if (ModelState.IsValid) { _disbursementRepo.Update(disbursement); var repEmail = _employeeRepo.GetRepByDeptCode(disbursement.DeptCode).EmailAddress; if (disbursement.CollectionPointId != null) { var collectionPoint = _collectionRepo.GetById((int)disbursement.CollectionPointId); var email = new LUSSISEmail.Builder().From(User.Identity.Name).To(repEmail) .ForUpdateDisbursement(disbursement, collectionPoint).Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); } return(RedirectToAction("Upcoming")); } ViewBag.CollectionPointId = new SelectList(_collectionRepo.GetAll(), "CollectionPointId", "CollectionName", disbursement.CollectionPointId); return(View(disbursement)); }
public ActionResult UpdateRep(string repEmp) { if (ModelState.IsValid) { var context = new ApplicationDbContext(); var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var deptCode = Request.Cookies["Employee"]?["DeptCode"]; var department = _departmentRepo.GetById(deptCode); var oldRepEmpNum = department.RepEmpNum != null; var loginUser = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var sender = _employeeRepo.GetById(loginUser); var newRepEmpNum = Convert.ToInt32(repEmp); var newRep = _employeeRepo.GetById(newRepEmpNum); var newRepEmailAdd = newRep.EmailAddress; newRep.JobTitle = Role.Representative; if (!oldRepEmpNum) { //update two tables: Employee and Department _employeeRepo.Update(newRep); department.RepEmpNum = newRepEmpNum; _departmentRepo.Update(department); //update aspnetroles var newRepUser = context.Users.FirstOrDefault(u => u.Email == newRep.EmailAddress); userManager.RemoveFromRole(newRepUser?.Id, Role.Staff); userManager.AddToRole(newRepUser?.Id, Role.Representative); } else { //switch roles rep and staff. update both aspnetroles and jobtitles var oldEmpNum = department.RepEmpNum; var oldRep = _employeeRepo.GetById((int)oldEmpNum); var oldRepEmailAdd = oldRep.EmailAddress; oldRep.JobTitle = Role.Staff; var oldRepUser = context.Users.FirstOrDefault(u => u.Email == oldRep.EmailAddress); userManager.RemoveFromRole(oldRepUser?.Id, Role.Representative); userManager.AddToRole(oldRepUser?.Id, Role.Staff); _employeeRepo.Update(newRep); _employeeRepo.Update(oldRep); department.RepEmpNum = newRep.EmpNum; _departmentRepo.Update(department); var newRepUser = context.Users.FirstOrDefault(u => u.Email == newRep.EmailAddress); userManager.RemoveFromRole(newRepUser?.Id, Role.Staff); userManager.AddToRole(newRepUser?.Id, Role.Representative); //email to old rep var emailToOldRep = new LUSSISEmail.Builder().From(sender.EmailAddress) .To(oldRepEmailAdd).ForOldRepresentative().Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(emailToOldRep); }).Start(); } //email to new rep var emailToNewRep = new LUSSISEmail.Builder().From(sender.EmailAddress) .To(newRepEmailAdd).ForNewRepresentative().Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(emailToNewRep); }).Start(); } return(RedirectToAction("DeptRep")); }
public ActionResult CreateAdjustments(AdjVoucherColView adjVoucherColView) { var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var self = _employeeRepo.GetById(empNum); if (ModelState.IsValid) { if (adjVoucherColView.MyList != null) { var vouchers = new List <AdjVoucher>(); foreach (var adjVoucherDto in adjVoucherColView.MyList) { if (adjVoucherDto.Sign == false) { adjVoucherDto.Quantity = adjVoucherDto.Quantity * -1; } var stationery = _stationeryRepo.GetById(adjVoucherDto.ItemNum); stationery.AvailableQty = stationery.AvailableQty + adjVoucherDto.Quantity; stationery.CurrentQty = stationery.CurrentQty + adjVoucherDto.Quantity; _stationeryRepo.Update(stationery); var adjustment = new AdjVoucher { ItemNum = adjVoucherDto.ItemNum, Quantity = adjVoucherDto.Quantity, Reason = adjVoucherDto.Reason, Status = Pending, RequestEmpNum = empNum, CreateDate = DateTime.Today }; adjustment.Stationery = _stockAdjustmentRepo.AddStockAdjustment(adjustment); vouchers.Add(adjustment); } //Although there is a threshold of $250, both supervisor and manager will be informed of all adjustments regardless of price //If desired, the threshold can be applied by getting price * quantity and setting if (total price > 250) foreach (AdjVoucher av in vouchers) { av.Stationery = _stationeryRepo.GetById(av.ItemNum); } var managerEmail = _employeeRepo.GetStoreManager().EmailAddress; var supervisorEmail = _employeeRepo.GetStoreSupervisor().EmailAddress; var email1 = new LUSSISEmail.Builder().From(self.EmailAddress) .To(managerEmail).ForNewStockAdjustments(self.FullName, vouchers).Build(); var email2 = new LUSSISEmail.Builder().From(self.EmailAddress) .To(supervisorEmail).ForNewStockAdjustments(self.FullName, vouchers).Build(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email1); }).Start(); new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email2); }).Start(); return(RedirectToAction("History")); } return(View(adjVoucherColView)); } return(View(adjVoucherColView)); }
public ActionResult Create(PurchaseOrderDTO purchaseOrderDto) { try { //validate PO if (purchaseOrderDto.SupplierContact == null) { throw new Exception("Please input the supplier contact"); } else if (!ModelState.IsValid) { throw new Exception("IT Error: please contact your administrator"); } //fill any missing data with default values var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); var fullName = Request.Cookies["Employee"]?["Name"]; purchaseOrderDto.OrderEmpNum = empNum; if (purchaseOrderDto.CreateDate == new DateTime()) { purchaseOrderDto.CreateDate = DateTime.Today; } //create PO purchaseOrderDto.CreatePurchaseOrder(out var purchaseOrder); //save to database po and the updated available qty _poRepo.Add(purchaseOrder); foreach (PurchaseOrderDetail pdetail in purchaseOrder.PurchaseOrderDetails) { Stationery stationery = _stationeryRepo.GetById(pdetail.ItemNum); stationery.AvailableQty += pdetail.OrderQty; _stationeryRepo.Update(stationery); } //send email to supervisor var supervisorEmail = new EmployeeRepository().GetStoreSupervisor().EmailAddress; var email = new LUSSISEmail.Builder().From(User.Identity.Name) .To(supervisorEmail).ForNewPo(purchaseOrder, fullName).Build(); //start new thread to send email new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); //send email if using non=primary supplier var stationerys = purchaseOrder.PurchaseOrderDetails .Select(orderDetail => _stationeryRepo.GetById(orderDetail.ItemNum)) .Where(stationery => stationery.PrimarySupplier().SupplierId != purchaseOrder.SupplierId).ToList(); if (stationerys.Count > 0) { var supplierName = _supplierRepo.GetById(purchaseOrder.SupplierId).SupplierName; var email2 = new LUSSISEmail.Builder().From(User.Identity.Name).To(supervisorEmail) .ForNonPrimaryNewPo(supplierName, purchaseOrder, stationerys).Build(); new Thread(delegate() { EmailHelper.SendEmail(email2); }).Start(); } return(RedirectToAction("Summary")); } catch (Exception e) { return(RedirectToAction("Create", new { supplierId = purchaseOrderDto.SupplierId.ToString(), error = e.Message })); } }
public ActionResult ApproveReq(ReqApproveRejectDTO reqApprovalDto) { var req = _requisitionRepo.GetById(reqApprovalDto.RequisitionId); if (req == null || req.Status != RequisitionStatus.Pending) { return(PartialView("_unauthoriseAccess")); } var deptCode = Request.Cookies["Employee"]?["DeptCode"]; var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]); //must be pending for approval and reject if (User.IsInRole(Role.DepartmentHead) && !HasDelegate || IsDelegate) { //if (user is head and there is no delegate) or (user is currently delegate) if (deptCode != _departmentRepo.GetDepartmentByEmpNum(req.RequisitionEmpNum).DeptCode) { //if user is trying to approve for other department return(PartialView("_unauthoriseAccess")); } if (empNum == req.RequisitionEmpNum) { //if user is trying to self approve return(PartialView("_unauthoriseAccess")); } if (ModelState.IsValid) { req.Status = reqApprovalDto.Status; req.ApprovalRemarks = reqApprovalDto.ApprovalRemarks; req.ApprovalEmpNum = empNum; req.ApprovalDate = DateTime.Today; if (reqApprovalDto.Status == Approved) { foreach (var requisitionDetail in req.RequisitionDetails) { var stationery = _stationeryRepo.GetById(requisitionDetail.ItemNum); stationery.AvailableQty = stationery.AvailableQty - requisitionDetail.Quantity; _stationeryRepo.Update(stationery); } } _requisitionRepo.Update(req); //Send email var toEmail = req.RequisitionEmployee.EmailAddress; var email = new LUSSISEmail.Builder().From(User.Identity.Name) .To(toEmail).ForRequisitionApproval(req).Build(); new Thread(delegate() { EmailHelper.SendEmail(email); }).Start(); return(RedirectToAction("Pending")); } return(PartialView("_ApproveReq", reqApprovalDto)); } return(PartialView("_hasDelegate")); }