public ActionResult CreateAdjustments() { var adjVoucherColView = new AdjVoucherColView(); var adjustmentVoucherDtos = new List <AdjustmentVoucherDTO>(); var adjustmentVoucherDto = new AdjustmentVoucherDTO(); adjustmentVoucherDtos.Add(adjustmentVoucherDto); adjVoucherColView.MyList = adjustmentVoucherDtos; return(View("CreateAdjustments", adjVoucherColView)); }
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)); }