public ActionResult Post(JobOrderAmendmentHeaderViewModel vm) { bool BeforeSave = true; int Serial = 1; Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); JobOrderAmendmentHeader pt = AutoMapper.Mapper.Map <JobOrderAmendmentHeaderViewModel, JobOrderAmendmentHeader>(vm); var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId); if (!vm.JobOrderSettings.isVisibleJobWorkerLine && !vm.JobWorkerId.HasValue) { ModelState.AddModelError("JobWorkerId", "The JobWorker field is required"); } try { BeforeSave = JobOrderAmendmentDocEvents.beforeWizardSaveEvent(this, new JobEventArgs(vm.JobOrderAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } if (ModelState.IsValid && BeforeSave && !EventException) { pt.Status = (int)StatusConstants.Drafted; pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; db.JobOrderAmendmentHeader.Add(pt); //_JobOrderAmendmentHeaderService.Create(pt); var SelectedJobOrders = (List <JobOrderAmendmentWizardViewModel>)System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"]; var JobOrderLineIds = SelectedJobOrders.Select(m => m.JobOrderLineId).ToArray(); var JobOrderBalanceRecords = (from p in db.ViewJobOrderBalanceForInvoice where JobOrderLineIds.Contains(p.JobOrderLineId) select p).AsNoTracking().ToList(); var JobOrderRecords = (from p in db.JobOrderLine where JobOrderLineIds.Contains(p.JobOrderLineId) select p).AsNoTracking().ToList(); foreach (var item in SelectedJobOrders) { if (item.Rate - JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate != 0) { JobOrderRateAmendmentLine line = new JobOrderRateAmendmentLine(); line.JobOrderAmendmentHeaderId = pt.JobOrderAmendmentHeaderId; line.JobOrderLineId = item.JobOrderLineId; line.Qty = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().BalanceQty; line.AmendedRate = item.Rate; line.Rate = line.AmendedRate - JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate; line.Amount = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().BalanceQty *JobOrderRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().UnitConversionMultiplier *line.Rate; line.Amount = DecimalRoundOff.amountToFixed(line.Amount, settings.AmountRoundOff); line.JobOrderRate = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().Rate; line.JobWorkerId = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().JobWorkerId; line.Sr = Serial++; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; LineStatus.Add(line.JobOrderLineId, line.Rate); line.ObjectState = Model.ObjectState.Added; db.JobOrderRateAmendmentLine.Add(line); } } new JobOrderLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db); try { JobOrderAmendmentDocEvents.onWizardSaveEvent(this, new JobEventArgs(pt.JobOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); } try { JobOrderAmendmentDocEvents.afterWizardSaveEvent(this, new JobEventArgs(pt.JobOrderAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.JobOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, User = User.Identity.Name, DocNo = pt.DocNo, DocDate = pt.DocDate }); Session.Remove("RateAmendmentWizardOrders"); return(RedirectToAction("Index", "JobOrderAmendmentHeader", new { id = pt.DocTypeId }).Success("Data saved Successfully")); } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public void Update(JobOrderAmendmentHeader pt) { pt.ObjectState = ObjectState.Modified; _unitOfWork.Repository <JobOrderAmendmentHeader>().Update(pt); }
public JobOrderAmendmentHeader Create(JobOrderAmendmentHeader pt) { pt.ObjectState = ObjectState.Added; _unitOfWork.Repository <JobOrderAmendmentHeader>().Insert(pt); return(pt); }
public void Delete(JobOrderAmendmentHeader pt) { _unitOfWork.Repository <JobOrderAmendmentHeader>().Delete(pt); }
public JobOrderAmendmentHeader Add(JobOrderAmendmentHeader pt) { _unitOfWork.Repository <JobOrderAmendmentHeader>().Insert(pt); return(pt); }