public ActionResult Submit(int id, string IndexType, string TransactionType) { #region DocTypeTimeLineValidation PackingHeader s = db.PackingHeader.Find(id); try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(s), DocumentTimePlanTypeConstants.Submit, User.Identity.Name, out ExceptionMsg, out Continue); TempData["CSEXC"] += ExceptionMsg; } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation && !Continue) { return(RedirectToAction("Index", new { id = s.DocTypeId, IndexType = IndexType })); } #endregion return(RedirectToAction("Detail", new { id = id, IndexType = IndexType, transactionType = string.IsNullOrEmpty(TransactionType) ? "submit" : TransactionType })); }
// GET: /PurchaseOrderHeader/Delete/5 private ActionResult Remove(int id) { PurchaseIndentCancelHeader PurchaseIndentCancelHeader = _PurchaseIndentCancelHeaderService.Find(id); if (PurchaseIndentCancelHeader == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(PurchaseIndentCancelHeader), DocumentTimePlanTypeConstants.Delete, User.Identity.Name, out ExceptionMsg, out Continue); TempData["CSEXC"] += ExceptionMsg; } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation && !Continue) { return(PartialView("AjaxError")); } #endregion ReasonViewModel rvm = new ReasonViewModel() { id = id, }; return(PartialView("_Reason", rvm)); }
public ActionResult Submit(int id, string IndexType, string TransactionType) { MaterialPlanHeader s = db.MaterialPlanHeader.Find(id); if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, s.DocTypeId, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Submit") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(s), DocumentTimePlanTypeConstants.Submit, User.Identity.Name, out ExceptionMsg, out Continue); TempData["CSEXC"] += ExceptionMsg; } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation && !Continue) { return(RedirectToAction("Index", new { id = s.DocTypeId, IndexType = IndexType })); } #endregion return(RedirectToAction("Detail", new { id = id, IndexType = IndexType, transactionType = string.IsNullOrEmpty(TransactionType) ? "submit" : TransactionType })); }
private ActionResult Remove(int id) { ReasonViewModel rvm = new ReasonViewModel() { id = id, }; PackingHeader PackingHeader = db.PackingHeader.Find(id); if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, PackingHeader.DocTypeId, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Remove") == false) { return(PartialView("~/Views/Shared/PermissionDenied_Modal.cshtml").Warning("You don't have permission to do this task.")); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(PackingHeader), DocumentTimePlanTypeConstants.Delete, User.Identity.Name, out ExceptionMsg, out Continue); TempData["CSEXC"] += ExceptionMsg; } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation && !Continue) { return(PartialView("AjaxError")); } #endregion return(PartialView("_Reason", rvm)); }
// GET: /ProductMaster/Edit/5 private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; SaleOrderAmendmentHeader pt = _SaleOrderAmendmentHeaderService.Find(id); if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, pt.DocTypeId, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Edit") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } if (pt == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(pt), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion SaleOrderAmendmentHeaderViewModel temp = AutoMapper.Mapper.Map <SaleOrderAmendmentHeader, SaleOrderAmendmentHeaderViewModel>(pt); PrepareViewBag(pt.DocTypeId); if ((!TimePlanValidation && !Continue)) { return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType })); } ViewBag.Mode = "Edit"; if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.SaleOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); } return(View("Create", temp)); }
private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; PackingHeaderViewModel svm = _PackingHeaderService.GetPackingHeaderViewModel(id); if (svm == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if ((!TimePlanValidation && !Continue)) { return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType })); } PrepareViewBag(svm); ViewBag.Mode = "Edit"; PackingSetting temp = new PackingSettingService(_unitOfWork).GetPackingSettingForDocument(svm.DocTypeId, svm.DivisionId, svm.SiteId); svm.PackingSettings = Mapper.Map <PackingSetting, PackingSettingsViewModel>(temp); if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = svm.DocTypeId, DocId = svm.PackingHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = svm.DocNo, DocDate = svm.DocDate, DocStatus = svm.Status, })); } return(View("Create", svm)); }
// GET: /ProductMaster/Delete/5 private ActionResult Remove(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PurchaseOrderAmendmentHeader PurchaseOrderAmendmentHeader = db.PurchaseOrderAmendmentHeader.Find(id); if (PurchaseOrderAmendmentHeader == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation bool TimePlanValidation = true; string ExceptionMsg = ""; try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(PurchaseOrderAmendmentHeader), DocumentTimePlanTypeConstants.Delete, User.Identity.Name, out ExceptionMsg, out Continue); TempData["CSEXC"] += ExceptionMsg; } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation && !Continue) { return(PartialView("AjaxError")); } #endregion ReasonViewModel vm = new ReasonViewModel() { id = id, }; return(PartialView("_Reason", vm)); }
// GET: /ProductMaster/Edit/5 private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; MaterialPlanHeader pt = _MaterialPlanHeaderService.Find(id); MaterialPlanHeaderViewModel vm = AutoMapper.Mapper.Map <MaterialPlanHeader, MaterialPlanHeaderViewModel>(pt); if (pt == null) { return(HttpNotFound()); } if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, pt.DocTypeId, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Edit") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(pt), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if ((!TimePlanValidation && !Continue)) { return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType })); } //Getting Settings var settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(pt.DocTypeId, vm.DivisionId, vm.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "MaterialPlanSettings", new { id = pt.DocTypeId }).Warning("Please create Material plan settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } vm.MaterialPlanSettings = Mapper.Map <MaterialPlanSettings, MaterialPlanSettingsViewModel>(settings); ViewBag.Mode = "Edit"; ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(pt.DocTypeId).DocumentTypeName; ViewBag.id = pt.DocTypeId; if (string.IsNullOrEmpty(vm.MaterialPlanSettings.PlanType)) { TempData["CSEXC"] += "Please configure PlanType"; } if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.MaterialPlanHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); } return(View("Create", vm)); }
public ActionResult Post(MaterialPlanHeaderViewModel vm) { MaterialPlanHeader pt = AutoMapper.Mapper.Map <MaterialPlanHeaderViewModel, MaterialPlanHeader>(vm); #region DocTypeTimeLineValidation try { if (vm.MaterialPlanHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (vm.MaterialPlanSettings.isMandatoryMachine == true && vm.MachineId == null) { ModelState.AddModelError("MachineId", "Machine field is required"); } if (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (vm.MaterialPlanHeaderId <= 0) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _MaterialPlanHeaderService.Create(pt); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Add"; ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(vm.DocTypeId).DocumentTypeName; ViewBag.id = vm.DocTypeId; return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.MaterialPlanHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); return(RedirectToAction("Modify", new { id = pt.MaterialPlanHeaderId }).Success("Data saved successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); MaterialPlanHeader temp = _MaterialPlanHeaderService.Find(pt.MaterialPlanHeaderId); MaterialPlanHeader ExRec = Mapper.Map <MaterialPlanHeader>(temp); temp.DocNo = pt.DocNo; temp.DocDate = pt.DocDate; temp.DueDate = pt.DueDate; temp.Remark = pt.Remark; temp.BuyerId = pt.BuyerId; temp.MachineId = pt.MachineId; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _MaterialPlanHeaderService.Update(temp); //PurchaseIndentHeader ExistingIndent = new PurchaseIndentHeaderService(_unitOfWork).GetPurchaseIndentForMaterialPlan(temp.MaterialPlanHeaderId); ProdOrderHeader ExistingIndent = new ProdOrderHeaderService(_unitOfWork).GetPurchOrProdForMaterialPlan(temp.MaterialPlanHeaderId, vm.MaterialPlanSettings.DocTypePurchaseIndentId ?? 0); //ProdOrderHeader ExistingProdOrder = new ProdOrderHeaderService(_unitOfWork).GetProdOrderForMaterialPlan(temp.MaterialPlanHeaderId); ProdOrderHeader ExistingProdOrder = new ProdOrderHeaderService(_unitOfWork).GetPurchOrProdForMaterialPlan(temp.MaterialPlanHeaderId, vm.MaterialPlanSettings.DocTypeProductionOrderId ?? 0); if (ExistingIndent != null) { ExistingIndent.ModifiedBy = User.Identity.Name; ExistingIndent.ModifiedDate = DateTime.Now; ExistingIndent.Remark = temp.Remark; ExistingIndent.ObjectState = Model.ObjectState.Added; //new PurchaseIndentHeaderService(_unitOfWork).Update(ExistingIndent); new ProdOrderHeaderService(_unitOfWork).Update(ExistingIndent); } if (ExistingProdOrder != null) { ExistingProdOrder.ModifiedBy = User.Identity.Name; ExistingProdOrder.ModifiedDate = DateTime.Now; ExistingProdOrder.Remark = temp.Remark; ExistingProdOrder.ObjectState = Model.ObjectState.Added; new ProdOrderHeaderService(_unitOfWork).Update(ExistingProdOrder); } LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Edit"; ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(vm.DocTypeId).DocumentTypeName; ViewBag.id = vm.DocTypeId; return(View("Create", pt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.MaterialPlanHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = vm.DocTypeId }).Success("Data saved successfully")); } #endregion } ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(vm.DocTypeId).DocumentTypeName; ViewBag.id = vm.DocTypeId; ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult HeaderPost(ProdOrderCancelHeaderViewModel svm) { #region DocTypeTimeLineValidation try { if (svm.ProdOrderCancelHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (svm.ProdOrderCancelHeaderId <= 0) { ProdOrderCancelHeader s = new ProdOrderCancelHeader(); s.DocTypeId = svm.DocTypeId; s.DocDate = svm.DocDate; s.DocNo = svm.DocNo; s.Remark = svm.Remark; s.CreatedDate = DateTime.Now; s.SiteId = svm.SiteId; s.DivisionId = svm.DivisionId; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; _ProdOrderCancelHeaderService.Create(s); try { _unitOfWork.Save(); } catch (Exception ex) { PrepareViewBag(s.DocTypeId); string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.ProdOrderCancelHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); return(RedirectToAction("Modify", new { id = s.ProdOrderCancelHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StringBuilder logstring = new StringBuilder(); ProdOrderCancelHeader temp = _ProdOrderCancelHeaderService.Find(svm.ProdOrderCancelHeaderId); ProdOrderCancelHeader ExRec = new ProdOrderCancelHeader(); ExRec = Mapper.Map <ProdOrderCancelHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; } temp.DocDate = svm.DocDate; temp.DocNo = svm.DocNo; temp.Remark = svm.Remark; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; _ProdOrderCancelHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { PrepareViewBag(temp.DocTypeId); string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Edit"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.ProdOrderCancelHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = temp.DocTypeId, IndexType = "" }).Success("Data saved successfully")); } #endregion } PrepareViewBag(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); }
public ActionResult Create(PackingHeaderViewModel svm) { string DataValidationMsg = DataValidation(svm); if (DataValidationMsg != "") { PrepareViewBag(svm); return(View(svm).Danger(DataValidationMsg)); } #region DocTypeTimeLineValidation try { if (svm.PackingHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (svm.PackingHeaderId == 0) { PackingHeader packingheader = Mapper.Map <PackingHeaderViewModel, PackingHeader>(svm); packingheader.CreatedDate = DateTime.Now; packingheader.ModifiedDate = DateTime.Now; packingheader.CreatedBy = User.Identity.Name; packingheader.ModifiedBy = User.Identity.Name; packingheader.Status = (int)StatusConstants.Drafted; _PackingHeaderService.Create(packingheader); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(svm); ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = packingheader.DocTypeId, DocId = packingheader.PackingHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = packingheader.DocNo, DocDate = packingheader.DocDate, DocStatus = packingheader.Status, })); return(RedirectToAction("Modify", new { id = packingheader.PackingHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PackingHeader packingheader = new PackingHeaderService(_unitOfWork).Find(svm.PackingHeaderId); PackingHeader ExRec = new PackingHeader(); ExRec = Mapper.Map <PackingHeader>(packingheader); StringBuilder logstring = new StringBuilder(); int status = packingheader.Status; if (packingheader.Status != (int)StatusConstants.Drafted) { packingheader.Status = (int)StatusConstants.Modified; } packingheader.DocNo = svm.DocNo; packingheader.DocDate = svm.DocDate; packingheader.BuyerId = svm.BuyerId; packingheader.GodownId = svm.GodownId; packingheader.DealUnitId = svm.DealUnitId; packingheader.Remark = svm.Remark; packingheader.JobWorkerId = svm.JobWorkerId; packingheader.BaleNoPattern = svm.BaleNoPattern; packingheader.ShipMethodId = svm.ShipMethodId; packingheader.ModifiedDate = DateTime.Now; packingheader.ModifiedBy = User.Identity.Name; _PackingHeaderService.Update(packingheader); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = packingheader, }); if (packingheader.StockHeaderId != null) { StockHeaderViewModel S = new StockHeaderViewModel(); S.StockHeaderId = (int)packingheader.StockHeaderId; S.DocTypeId = packingheader.DocTypeId; S.DocDate = packingheader.DocDate; S.DocNo = packingheader.DocNo; S.DivisionId = packingheader.DivisionId; S.SiteId = packingheader.SiteId; S.PersonId = packingheader.JobWorkerId; S.GodownId = packingheader.GodownId; S.Remark = packingheader.Remark; S.Status = packingheader.Status; S.ModifiedBy = packingheader.ModifiedBy; S.ModifiedDate = packingheader.ModifiedDate; new StockHeaderService(_unitOfWork).UpdateStockHeader(S); } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Edit"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = packingheader.DocTypeId, DocId = packingheader.PackingHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = packingheader.DocNo, xEModifications = Modifications, DocDate = packingheader.DocDate, DocStatus = packingheader.Status, })); return(RedirectToAction("Index").Success("Data saved successfully")); } #endregion } PrepareViewBag(svm); ViewBag.Mode = "Add"; return(View("Create", svm)); }
public ActionResult Post(PurchaseQuotationHeaderViewModel vm) { PurchaseQuotationHeader pt = AutoMapper.Mapper.Map <PurchaseQuotationHeaderViewModel, PurchaseQuotationHeader>(vm); //Getting Settings var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(vm.DocTypeId, vm.DivisionId, vm.SiteId); if (vm.BillingAccountId <= 0) { ModelState.AddModelError("BillingAccountId", "The Billing Account field is required"); } #region BeforeSave bool BeforeSave = true; //try //{ // if (vm.PurchaseQuotationHeaderId <= 0) // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationHeaderId, EventModeConstants.Add), ref db); // else // BeforeSave = PurchaseQuotationReceiveDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseQuotationHeaderId, EventModeConstants.Edit), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; // EventException = true; //} //if (!BeforeSave) // TempData["CSEXC"] += "Failed validation before save"; #endregion #region DocTypeTimeLineValidation try { if (vm.PurchaseQuotationHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue)) { #region CreateRecord if (vm.PurchaseQuotationHeaderId <= 0) { pt.CalculateDiscountOnRate = vm.CalculateDiscountOnRate; pt.DivisionId = vm.DivisionId; pt.SiteId = vm.SiteId; pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; db.PurchaseQuotationHeader.Add(pt); //_PurchaseQuotationHeaderService.Create(pt); //try //{ // PurchaseQuotationReceiveDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseQuotationHeaderId, 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 //{ // PurchaseQuotationReceiveDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseQuotationHeaderId, EventModeConstants.Add), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseQuotationHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); //return Edit(pt.PurchaseQuotationHeaderId).Success("Data saved successfully"); return(RedirectToAction("Modify", new { id = pt.PurchaseQuotationHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseQuotationHeader temp = _PurchaseQuotationHeaderService.Find(pt.PurchaseQuotationHeaderId); PurchaseQuotationHeader ExRec = new PurchaseQuotationHeader(); ExRec = Mapper.Map <PurchaseQuotationHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; } temp.DocTypeId = pt.DocTypeId; temp.CurrencyId = pt.CurrencyId; temp.VendorQuotationNo = pt.VendorQuotationNo; temp.VendorQuotationDate = pt.VendorQuotationDate; temp.TermsAndConditions = pt.TermsAndConditions; temp.SalesTaxGroupId = pt.SalesTaxGroupId; temp.UnitConversionForId = pt.UnitConversionForId; temp.CreditDays = pt.CreditDays; temp.Remark = pt.Remark; temp.SupplierId = pt.SupplierId; temp.BillingAccountId = pt.BillingAccountId; temp.DocDate = pt.DocDate; temp.DocNo = pt.DocNo; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; db.PurchaseQuotationHeader.Add(temp); //_PurchaseQuotationHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); //try //{ // PurchaseQuotationReceiveDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseQuotationHeaderId, EventModeConstants.Edit), 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 = "Edit"; return(View("Create", pt)); } //try //{ // PurchaseQuotationReceiveDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseQuotationHeaderId, EventModeConstants.Edit), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXC"] += message; //} LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.PurchaseQuotationHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = vm.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult Post(SaleOrderAmendmentHeaderViewModel vm) { SaleOrderAmendmentHeader pt = AutoMapper.Mapper.Map <SaleOrderAmendmentHeaderViewModel, SaleOrderAmendmentHeader>(vm); if (vm.BuyerId <= 0) { ModelState.AddModelError("BuyerId", "The Buyer field is required"); } #region DocTypeTimeLineValidation try { if (vm.SaleOrderAmendmentHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (vm.SaleOrderAmendmentHeaderId <= 0) { 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; _SaleOrderAmendmentHeaderService.Create(pt); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.SaleOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); return(RedirectToAction("Modify", new { id = pt.SaleOrderAmendmentHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); SaleOrderAmendmentHeader temp = _SaleOrderAmendmentHeaderService.Find(pt.SaleOrderAmendmentHeaderId); SaleOrderAmendmentHeader ExRec = new SaleOrderAmendmentHeader(); ExRec = Mapper.Map <SaleOrderAmendmentHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; } temp.DocDate = pt.DocDate; temp.DocNo = pt.DocNo; temp.ReasonId = pt.ReasonId; temp.BuyerId = pt.BuyerId; temp.Remark = pt.Remark; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _SaleOrderAmendmentHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(pt.DocTypeId); ViewBag.Mode = "Edit"; return(View("Create", pt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.SaleOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = pt.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(pt.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult Post(JobOrderHeaderViewModel svm) { JobOrderHeader s = Mapper.Map <JobOrderHeaderViewModel, JobOrderHeader>(svm); ProdOrderCancelHeader cHeader = new ProdOrderCancelHeader(); if (svm.JobOrderSettings != null) { if (svm.JobOrderSettings.isMandatoryCostCenter == true && (svm.CostCenterId <= 0 || svm.CostCenterId == null)) { ModelState.AddModelError("CostCenterId", "The CostCenter field is required"); } if (svm.JobOrderSettings.isMandatoryMachine == true && (svm.MachineId <= 0 || svm.MachineId == null)) { ModelState.AddModelError("MachineId", "The Machine field is required"); } if (svm.JobOrderSettings.isPostedInStock == true && !svm.GodownId.HasValue) { ModelState.AddModelError("GodownId", "The Godown field is required"); } } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { List <ProdOrderHeaderListViewModel> ProdOrderIds = (List <ProdOrderHeaderListViewModel>)System.Web.HttpContext.Current.Session["ConfirmProdOrderIds"]; bool CancelBalProdOrders = (bool)System.Web.HttpContext.Current.Session["CancelBalProdOrdrs"]; bool CreateDyeingOrder = ProdOrderIds.Any(m => m.Qty > 0); var ProdOrderLineIds = ProdOrderIds.Select(m => m.ProdOrderLineId).ToArray(); var BalProdOrders = (from p in db.ViewProdOrderBalance.AsNoTracking() where ProdOrderLineIds.Contains(p.ProdOrderLineId) select p).ToList(); var ProdOrderLines = (from p in db.ProdOrderLine.AsNoTracking() where ProdOrderLineIds.Contains(p.ProdOrderLineId) select p).ToList(); var ProductIds = BalProdOrders.Select(m => m.ProductId).ToList(); var Products = (from p in db.Product.AsNoTracking() where ProductIds.Contains(p.ProductId) select p).ToList(); bool CancelQty = (from p in ProdOrderIds join t in BalProdOrders on p.ProdOrderLineId equals t.ProdOrderLineId where (t.BalanceQty - p.Qty) > 0 select p).Any(); CancelBalProdOrders = (CancelBalProdOrders && CancelQty); if (CreateDyeingOrder) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.ActualDueDate = s.DueDate; s.ActualDocDate = s.DocDate; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; _JobOrderHeaderService.Create(s); new JobOrderHeaderStatusService(_unitOfWork).CreateHeaderStatus(s.JobOrderHeaderId, ref db, false); if (svm.PerkViewModel != null) { foreach (PerkViewModel item in svm.PerkViewModel) { JobOrderPerk perk = Mapper.Map <PerkViewModel, JobOrderPerk>(item); perk.CreatedBy = User.Identity.Name; perk.CreatedDate = DateTime.Now; perk.ModifiedBy = User.Identity.Name; perk.ModifiedDate = DateTime.Now; perk.JobOrderHeaderId = s.JobOrderHeaderId; new JobOrderPerkService(_unitOfWork).Create(perk); } } } if (CancelBalProdOrders) { cHeader.DocNo = s.DocNo; cHeader.DocDate = s.DocDate; cHeader.DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDoctypeConstants.DyeingPlanCancel).DocumentTypeId; cHeader.DivisionId = s.DivisionId; cHeader.SiteId = s.SiteId; cHeader.CreatedBy = User.Identity.Name; cHeader.CreatedDate = DateTime.Now; cHeader.ModifiedBy = User.Identity.Name; cHeader.ModifiedDate = DateTime.Now; cHeader.ReferenceDocId = s.JobOrderHeaderId; cHeader.ReferenceDocTypeId = s.DocTypeId; cHeader.Remark = s.Remark; cHeader.ObjectState = Model.ObjectState.Added; new ProdOrderCancelHeaderService(_unitOfWork).Create(cHeader); } int Cnt = 0; List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); int pk = 0; bool HeaderChargeEdit = false; JobOrderSettings Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId); int?MaxLineId = new JobOrderLineChargeService(_unitOfWork).GetMaxProductCharge(s.JobOrderHeaderId, "Web.JobOrderLines", "JobOrderHeaderId", "JobOrderLineId"); int PersonCount = 0; //if (!Settings.CalculationId.HasValue) //{ // throw new Exception("Calculation not configured in Job order settings"); //} int CalculationId = Settings.CalculationId ?? 0; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); foreach (var ProdORderLineId in ProdOrderIds) { var BalProdOrderLine = BalProdOrders.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault(); var Product = Products.Where(m => m.ProductId == BalProdOrderLine.ProductId).FirstOrDefault(); if (ProdORderLineId.Qty <= BalProdOrderLine.BalanceQty && ProdORderLineId.Qty > 0) { if (((Settings.isVisibleRate == false || Settings.isVisibleRate == true))) { JobOrderLine line = new JobOrderLine(); if (Settings.isPostedInStock ?? false) { StockViewModel StockViewModel = new StockViewModel(); if (Cnt == 0) { StockViewModel.StockHeaderId = s.StockHeaderId ?? 0; } else { if (s.StockHeaderId != null && s.StockHeaderId != 0) { StockViewModel.StockHeaderId = (int)s.StockHeaderId; } else { StockViewModel.StockHeaderId = -1; } } StockViewModel.StockId = -Cnt; StockViewModel.DocHeaderId = s.JobOrderHeaderId; StockViewModel.DocLineId = line.JobOrderLineId; StockViewModel.DocTypeId = s.DocTypeId; StockViewModel.StockHeaderDocDate = s.DocDate; StockViewModel.StockDocDate = s.DocDate; StockViewModel.DocNo = s.DocNo; StockViewModel.DivisionId = s.DivisionId; StockViewModel.SiteId = s.SiteId; StockViewModel.CurrencyId = null; StockViewModel.PersonId = s.JobWorkerId; StockViewModel.ProductId = BalProdOrderLine.ProductId; StockViewModel.HeaderFromGodownId = null; StockViewModel.HeaderGodownId = s.GodownId; StockViewModel.HeaderProcessId = s.ProcessId; StockViewModel.GodownId = (int)s.GodownId; StockViewModel.Remark = s.Remark; StockViewModel.Status = s.Status; StockViewModel.ProcessId = s.ProcessId; StockViewModel.LotNo = null; StockViewModel.CostCenterId = s.CostCenterId; StockViewModel.Qty_Iss = ProdORderLineId.Qty; StockViewModel.Qty_Rec = 0; StockViewModel.Rate = 0; StockViewModel.ExpiryDate = null; StockViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification; StockViewModel.Dimension1Id = BalProdOrderLine.Dimension1Id; StockViewModel.Dimension2Id = BalProdOrderLine.Dimension2Id; StockViewModel.CreatedBy = User.Identity.Name; StockViewModel.CreatedDate = DateTime.Now; StockViewModel.ModifiedBy = User.Identity.Name; StockViewModel.ModifiedDate = DateTime.Now; string StockPostingError = ""; StockPostingError = new StockService(_unitOfWork).StockPost(ref StockViewModel); if (StockPostingError != "") { string message = StockPostingError; ModelState.AddModelError("", message); return(View("Create", svm)); } if (Cnt == 0) { s.StockHeaderId = StockViewModel.StockHeaderId; } line.StockId = StockViewModel.StockId; } if (Settings.isPostedInStockProcess ?? false) { StockProcessViewModel StockProcessViewModel = new StockProcessViewModel(); if (s.StockHeaderId != null && s.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here. { StockProcessViewModel.StockHeaderId = (int)s.StockHeaderId; } else if (Settings.isPostedInStock ?? false)//If Stok Header is already posted during stock posting then this statement will Execute.So theat Stock Header will not generate again. { StockProcessViewModel.StockHeaderId = -1; } else if (Cnt > 0)//If function will only post in stock process then after first iteration of loop the stock header id will go -1 { StockProcessViewModel.StockHeaderId = -1; } else//If function will only post in stock process then this statement will execute.For Example Job consumption. { StockProcessViewModel.StockHeaderId = 0; } StockProcessViewModel.StockProcessId = -Cnt; StockProcessViewModel.DocHeaderId = s.JobOrderHeaderId; StockProcessViewModel.DocLineId = line.JobOrderLineId; StockProcessViewModel.DocTypeId = s.DocTypeId; StockProcessViewModel.StockHeaderDocDate = s.DocDate; StockProcessViewModel.StockProcessDocDate = s.DocDate; StockProcessViewModel.DocNo = s.DocNo; StockProcessViewModel.DivisionId = s.DivisionId; StockProcessViewModel.SiteId = s.SiteId; StockProcessViewModel.CurrencyId = null; StockProcessViewModel.PersonId = s.JobWorkerId; StockProcessViewModel.ProductId = BalProdOrderLine.ProductId; StockProcessViewModel.HeaderFromGodownId = null; StockProcessViewModel.HeaderGodownId = s.GodownId; StockProcessViewModel.HeaderProcessId = s.ProcessId; StockProcessViewModel.GodownId = s.GodownId; StockProcessViewModel.Remark = s.Remark; StockProcessViewModel.Status = s.Status; StockProcessViewModel.ProcessId = s.ProcessId; StockProcessViewModel.LotNo = null; StockProcessViewModel.CostCenterId = s.CostCenterId; StockProcessViewModel.Qty_Iss = 0; StockProcessViewModel.Qty_Rec = ProdORderLineId.Qty; StockProcessViewModel.Rate = 0; StockProcessViewModel.ExpiryDate = null; StockProcessViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification; StockProcessViewModel.Dimension1Id = BalProdOrderLine.Dimension1Id; StockProcessViewModel.Dimension2Id = BalProdOrderLine.Dimension2Id; StockProcessViewModel.CreatedBy = User.Identity.Name; StockProcessViewModel.CreatedDate = DateTime.Now; StockProcessViewModel.ModifiedBy = User.Identity.Name; StockProcessViewModel.ModifiedDate = DateTime.Now; string StockProcessPostingError = ""; StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPost(ref StockProcessViewModel); if (StockProcessPostingError != "") { string message = StockProcessPostingError; ModelState.AddModelError("", message); return(PartialView("_Results", svm)); } if ((Settings.isPostedInStock ?? false) == false) { if (Cnt == 0) { s.StockHeaderId = StockProcessViewModel.StockHeaderId; } } line.StockProcessId = StockProcessViewModel.StockProcessId; } line.JobOrderHeaderId = s.JobOrderHeaderId; line.ProdOrderLineId = BalProdOrderLine.ProdOrderLineId; line.ProductId = BalProdOrderLine.ProductId; line.Dimension1Id = BalProdOrderLine.Dimension1Id; line.Dimension2Id = BalProdOrderLine.Dimension2Id; line.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification; line.Qty = ProdORderLineId.Qty; line.Rate = ProdORderLineId.Rate; line.DealQty = ProdORderLineId.Qty; line.UnitId = Product.UnitId; line.DealUnitId = Product.UnitId; line.Amount = (line.DealQty * line.Rate); line.UnitConversionMultiplier = 1; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.JobOrderLineId = pk; line.Sr = pk; line.ObjectState = Model.ObjectState.Added; new JobOrderLineService(_unitOfWork).Create(line); new JobOrderLineStatusService(_unitOfWork).CreateLineStatus(line.JobOrderLineId, ref db, false); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobOrderLineId, HeaderTableId = s.JobOrderHeaderId, PersonID = s.JobWorkerId, DealQty = line.DealQty }); pk++; Cnt++; } } if (CancelBalProdOrders && (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty > 0)) { ProdOrderCancelLine cLine = new ProdOrderCancelLine(); cLine.CreatedBy = User.Identity.Name; cLine.CreatedDate = DateTime.Now; cLine.ModifiedBy = User.Identity.Name; cLine.ModifiedDate = DateTime.Now; cLine.ProdOrderCancelHeaderId = cHeader.ProdOrderCancelHeaderId; cLine.ProdOrderLineId = ProdORderLineId.ProdOrderLineId; cLine.Qty = (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty); cLine.ReferenceDocTypeId = cHeader.ReferenceDocTypeId; cLine.ObjectState = Model.ObjectState.Added; new ProdOrderCancelLineService(_unitOfWork).Create(cLine); } } //new JobOrderHeaderService(_unitOfWork).Update(s); new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, s.JobOrderHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobOrderHeaderCharges", "Web.JobOrderLineCharges", out PersonCount, s.DocTypeId, s.SiteId, s.DivisionId); //Saving Charges foreach (var item in LineCharges) { JobOrderLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, JobOrderLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; new JobOrderLineChargeService(_unitOfWork).Create(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { JobOrderHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, JobOrderHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = s.JobOrderHeaderId; POHeaderCharge.PersonID = s.JobWorkerId; POHeaderCharge.ObjectState = Model.ObjectState.Added; new JobOrderHeaderChargeService(_unitOfWork).Create(POHeaderCharge); } else { var footercharge = new JobOrderHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; new JobOrderHeaderChargeService(_unitOfWork).Update(footercharge); } } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.JobOrderHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); System.Web.HttpContext.Current.Session.Remove("ConfirmProdOrderIds"); System.Web.HttpContext.Current.Session.Remove("CancelBalProdOrdrs"); if (CreateDyeingOrder) { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Submit/" + s.JobOrderHeaderId)); } else { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Index/" + s.DocTypeId)); } } PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); }
public ActionResult Post(JobReceiveHeaderViewModel svm) { bool TimePlanValidation = true; string ExceptionMsg = ""; bool Continue = true; JobReceiveHeader s = Mapper.Map <JobReceiveHeaderViewModel, JobReceiveHeader>(svm); List <WeavingReceiveWizardViewModel> JobOrdersAndQtys = (List <WeavingReceiveWizardViewModel>)System.Web.HttpContext.Current.Session["BarCodesWeavingWizardJobOrder"]; if (JobOrdersAndQtys.Count() <= 0) { ModelState.AddModelError("", "No Records Selected"); } int JobWorkerCnt = (from l in JobOrdersAndQtys group l by l.JobWorkerId into g select new { JobWorkerId = g.Key, }).Distinct().Count(); if (JobWorkerCnt > 1) { ModelState.AddModelError("", "Select any one Job Worker Orders."); } s.JobWorkerId = JobOrdersAndQtys.FirstOrDefault().JobWorkerId; svm.JobWorkerId = JobOrdersAndQtys.FirstOrDefault().JobWorkerId; #region DocTypeTimeLineValidation try { if (svm.JobReceiveHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { if (svm.JobReceiveHeaderId <= 0) { if (JobOrdersAndQtys.Count() > 0) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; _JobReceiveHeaderService.Create(s); int Cnt = 0; int Sr = 0; JobReceiveSettings Settings = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId); int ProductUidCountForJobOrderLine = 0; int pk = 0; var JobOrderLineIds = JobOrdersAndQtys.Select(m => m.JobOrderLineId).ToArray(); var BalQtyandUnits = (from p in db.ViewJobOrderBalance join t in db.Product on p.ProductId equals t.ProductId where JobOrderLineIds.Contains(p.JobOrderLineId) select new { BalQty = p.BalanceQty, JobOrderLineId = p.JobOrderLineId, UnitId = t.UnitId, }).ToList(); if (ModelState.IsValid) { foreach (var SelectedJobOrderLine in JobOrdersAndQtys) { if (SelectedJobOrderLine.JobOrderLineId > 0) { if (SelectedJobOrderLine.ToProductUidName != "" && SelectedJobOrderLine.ToProductUidName != null && SelectedJobOrderLine.FromProductUidName != "" && SelectedJobOrderLine.FromProductUidName != null) { if (SelectedJobOrderLine.Qty != (Convert.ToInt32(SelectedJobOrderLine.ToProductUidName) - Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + 1)) { string Msg = ""; Msg = "Qty and Barcode series does not match."; ModelState.AddModelError("", Msg); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } } ProductUidCountForJobOrderLine = 0; var JobOrderLine = new JobOrderLineService(_unitOfWork).Find((SelectedJobOrderLine.JobOrderLineId)); var Product = new ProductService(_unitOfWork).Find(JobOrderLine.ProductId); var bal = BalQtyandUnits.Where(m => m.JobOrderLineId == SelectedJobOrderLine.JobOrderLineId).FirstOrDefault(); if (SelectedJobOrderLine.Qty <= bal.BalQty) { for (int i = 0; i <= SelectedJobOrderLine.Qty - 1; i++) { int?ProductUidHeaderId = null; int?ProductUidId = null; var SisterSite = (from S in db.Site where S.PersonId == s.JobWorkerId select S).FirstOrDefault(); //if (!string.IsNullOrEmpty(Settings.SqlProcGenProductUID)) if (SisterSite == null) { ProductUidHeader ProdUidHeader = new ProductUidHeader(); ProdUidHeader.ProductUidHeaderId = Cnt; ProdUidHeader.ProductId = JobOrderLine.ProductId; ProdUidHeader.Dimension1Id = JobOrderLine.Dimension1Id; ProdUidHeader.Dimension2Id = JobOrderLine.Dimension2Id; ProdUidHeader.GenDocId = s.JobReceiveHeaderId; ProdUidHeader.GenDocNo = s.DocNo; ProdUidHeader.GenDocTypeId = s.DocTypeId; ProdUidHeader.GenDocDate = s.DocDate; ProdUidHeader.GenPersonId = s.JobWorkerId; ProdUidHeader.CreatedBy = User.Identity.Name; ProdUidHeader.CreatedDate = DateTime.Now; ProdUidHeader.ModifiedBy = User.Identity.Name; ProdUidHeader.ModifiedDate = DateTime.Now; ProdUidHeader.ObjectState = Model.ObjectState.Added; new ProductUidHeaderService(_unitOfWork).Create(ProdUidHeader); ProductUidHeaderId = ProdUidHeader.ProductUidHeaderId; string ProductUidName = (Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + ProductUidCountForJobOrderLine).ToString(); ProductUid ProdUid = new ProductUid(); ProdUid.ProductUidHeaderId = ProdUidHeader.ProductUidHeaderId; ProdUid.ProductUidName = ProductUidName; ProdUid.ProductId = JobOrderLine.ProductId; ProdUid.IsActive = true; ProdUid.CreatedBy = User.Identity.Name; ProdUid.CreatedDate = DateTime.Now; ProdUid.ModifiedBy = User.Identity.Name; ProdUid.ModifiedDate = DateTime.Now; ProdUid.GenLineId = null; ProdUid.GenDocId = s.JobReceiveHeaderId; ProdUid.GenDocNo = s.DocNo; ProdUid.GenDocTypeId = s.DocTypeId; ProdUid.GenDocDate = s.DocDate; ProdUid.GenPersonId = s.JobWorkerId; ProdUid.Dimension1Id = JobOrderLine.Dimension1Id; ProdUid.Dimension2Id = JobOrderLine.Dimension2Id; ProdUid.CurrenctProcessId = s.ProcessId; ProdUid.CurrenctGodownId = s.GodownId; ProdUid.Status = "Receive"; ProdUid.LastTransactionDocId = s.JobReceiveHeaderId; ProdUid.LastTransactionDocNo = s.DocNo; ProdUid.LastTransactionDocTypeId = s.DocTypeId; ProdUid.LastTransactionDocDate = s.DocDate; ProdUid.LastTransactionPersonId = s.JobWorkerId; ProdUid.LastTransactionLineId = null; ProdUid.ProductUIDId = pk; new ProductUidService(_unitOfWork).Create(ProdUid); ProductUidId = ProdUid.ProductUIDId; } if (ProductUidId == null) { string ProductUidName = (Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + ProductUidCountForJobOrderLine).ToString(); var temp = new ProductUidService(_unitOfWork).Find(ProductUidName); if (temp != null) { ProductUidId = temp.ProductUIDId; } else { string Msg = ProductUidName + " is not a valid barcode."; ModelState.AddModelError("", Msg); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } if (temp.CurrenctGodownId != null) { string Msg = ProductUidName + " is already in Stock at Godown " + new GodownService(_unitOfWork).Find(temp.CurrenctGodownId ?? 0).GodownName; ModelState.AddModelError("", Msg); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } if (temp.LastTransactionPersonId != s.JobWorkerId) { string Msg = ProductUidName + ProductUidName + " does not belong to this Job Worker"; ModelState.AddModelError("", Msg); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } } StockViewModel StockViewModel = new StockViewModel(); if (Cnt == 0) { StockViewModel.StockHeaderId = s.StockHeaderId ?? 0; } else { if (s.StockHeaderId != null && s.StockHeaderId != 0) { StockViewModel.StockHeaderId = (int)s.StockHeaderId; } else { StockViewModel.StockHeaderId = -1; } } StockViewModel.StockId = -Cnt; StockViewModel.DocHeaderId = s.JobReceiveHeaderId; StockViewModel.DocLineId = null; StockViewModel.DocTypeId = s.DocTypeId; StockViewModel.StockHeaderDocDate = s.DocDate; StockViewModel.StockDocDate = s.DocDate; StockViewModel.DocNo = s.DocNo; StockViewModel.DivisionId = s.DivisionId; StockViewModel.SiteId = s.SiteId; StockViewModel.CurrencyId = null; StockViewModel.PersonId = s.JobWorkerId; StockViewModel.ProductId = JobOrderLine.ProductId; //StockViewModel.ProductUidId = ProdUid.ProductUIDId; StockViewModel.ProductUidId = ProductUidId; StockViewModel.HeaderFromGodownId = null; StockViewModel.HeaderGodownId = s.GodownId; StockViewModel.HeaderProcessId = s.ProcessId; StockViewModel.GodownId = (int)s.GodownId; StockViewModel.Remark = s.Remark; StockViewModel.Status = s.Status; StockViewModel.ProcessId = s.ProcessId; StockViewModel.LotNo = null; StockViewModel.CostCenterId = SelectedJobOrderLine.CostCenterId; StockViewModel.Qty_Iss = 0; StockViewModel.Qty_Rec = 1; StockViewModel.Rate = SelectedJobOrderLine.Rate; StockViewModel.ExpiryDate = null; StockViewModel.Specification = JobOrderLine.Specification; StockViewModel.Dimension1Id = JobOrderLine.Dimension1Id; StockViewModel.Dimension2Id = JobOrderLine.Dimension2Id; StockViewModel.CreatedBy = User.Identity.Name; StockViewModel.CreatedDate = DateTime.Now; StockViewModel.ModifiedBy = User.Identity.Name; StockViewModel.ModifiedDate = DateTime.Now; string StockPostingError = ""; StockPostingError = new StockService(_unitOfWork).StockPost(ref StockViewModel); if (StockPostingError != "") { string message = StockPostingError; ModelState.AddModelError("", message); return(View("Create", svm)); } if (Cnt == 0) { s.StockHeaderId = StockViewModel.StockHeaderId; } JobReceiveLine line = new JobReceiveLine(); line.StockId = StockViewModel.StockId; //line.ProductUidHeaderId = ProdUidHeader.ProductUidHeaderId; line.ProductUidHeaderId = ProductUidHeaderId; //line.ProductUidId = ProdUid.ProductUIDId; line.ProductUidId = ProductUidId; line.JobReceiveHeaderId = s.JobReceiveHeaderId; line.JobOrderLineId = JobOrderLine.JobOrderLineId; line.Qty = 1; line.PassQty = 1; line.LossQty = 0; line.UnitConversionMultiplier = JobOrderLine.UnitConversionMultiplier; line.DealQty = 1 * JobOrderLine.UnitConversionMultiplier; line.DealUnitId = JobOrderLine.DealUnitId; line.Sr = Sr++; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.JobReceiveLineId = pk; line.ObjectState = Model.ObjectState.Added; new JobReceiveLineService(_unitOfWork).Create(line); new JobReceiveLineStatusService(_unitOfWork).CreateLineStatus(line.JobReceiveLineId, ref db, false); pk++; Cnt = Cnt + 1; ProductUidCountForJobOrderLine++; } } } } } string Errormessage = ""; try { _unitOfWork.Save(); } catch (Exception ex) { Errormessage = _exception.HandleException(ex); ModelState.AddModelError("", Errormessage); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } IEnumerable <JobReceiveLine> JobReceiveLineList = new JobReceiveLineService(_unitOfWork).GetJobReceiveLineList(s.JobReceiveHeaderId); foreach (JobReceiveLine Line in JobReceiveLineList) { if (Line.ProductUidId != null) { ProductUid ProductUid = new ProductUidService(_unitOfWork).Find((int)Line.ProductUidId); ProductUid.GenDocId = Line.JobReceiveHeaderId; ProductUid.LastTransactionDocId = Line.JobReceiveHeaderId; ProductUid.GenLineId = Line.JobReceiveLineId; ProductUid.LastTransactionLineId = Line.JobReceiveLineId; new ProductUidService(_unitOfWork).Update(ProductUid); } } try { _unitOfWork.Save(); } catch (Exception ex) { Errormessage = _exception.HandleException(ex); ModelState.AddModelError("", Errormessage); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.JobReceiveHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); System.Web.HttpContext.Current.Session.Remove("BarCodesWeavingWizardJobOrder"); return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Modify/" + s.JobReceiveHeaderId)); } else { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + s.DocTypeId)); } } else { } } PrepareViewBag(); ViewBag.Mode = "Add"; //return Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Submit/"+s.JobReceiveHeaderId); return(View("Create", svm)); }
public ActionResult HeaderPost(SaleOrderHeaderIndexViewModel svm) { if (svm.DocDate > svm.DueDate) { ModelState.AddModelError("DueDate", "DueDate cannot be greater than DocDate"); } #region DocTypeTimeLineValidation try { if (svm.SaleOrderHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (svm.SaleOrderHeaderId == 0) { SaleOrderHeader s = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm); s.ActualDueDate = s.DueDate; s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; _SaleOrderHeaderService.Create(s); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(svm); ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.SaleOrderHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); return(RedirectToAction("Modify", new { id = s.SaleOrderHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); //string tempredirect = (Request["Redirect"].ToString()); SaleOrderHeader s = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm); StringBuilder logstring = new StringBuilder(); SaleOrderHeader temp = _SaleOrderHeaderService.Find(s.SaleOrderHeaderId); SaleOrderHeader ExRec = new SaleOrderHeader(); ExRec = Mapper.Map <SaleOrderHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; } temp.DocTypeId = s.DocTypeId; temp.DocDate = s.DocDate; temp.DocNo = s.DocNo; temp.BuyerOrderNo = s.BuyerOrderNo; temp.SaleToBuyerId = s.SaleToBuyerId; temp.BillToBuyerId = s.BillToBuyerId; temp.CurrencyId = s.CurrencyId; temp.Priority = s.Priority; temp.UnitConversionForId = s.UnitConversionForId; temp.ShipMethodId = s.ShipMethodId; temp.ShipAddress = s.ShipAddress; temp.DeliveryTermsId = s.DeliveryTermsId; temp.Remark = s.Remark; temp.DueDate = s.DueDate; temp.Advance = s.Advance; temp.FinancierId = s.FinancierId; temp.SalesExecutiveId = s.SalesExecutiveId; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; _SaleOrderHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(svm); ViewBag.Mode = "Edit"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.SaleOrderHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(svm); ViewBag.Mode = "Add"; return(View("Create", svm)); }
private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; PackingHeader PackingHeader = _PackingHeaderService.Find(id); if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, PackingHeader.DocTypeId, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Edit") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(PackingHeader), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if ((!TimePlanValidation && !Continue)) { return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType })); } PackingHeaderViewModel vm = new PackingHeaderViewModel(); vm = Mapper.Map <PackingHeader, PackingHeaderViewModel>(PackingHeader); vm.BuyerId = PackingHeader.BuyerId; vm.GodownId = PackingHeader.GodownId; //Getting Settings var settings = new PackingSettingService(_unitOfWork).GetPackingSettingForDocument(PackingHeader.DocTypeId, vm.DivisionId, vm.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "PackingSetting", new { id = PackingHeader.DocTypeId }).Warning("Please create Sale Dispatch settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } if (settings != null) { vm.ProcessId = settings.ProcessId; } vm.PackingSettings = Mapper.Map <PackingSetting, PackingSettingsViewModel>(settings); PrepareViewBag(PackingHeader.DocTypeId); ViewBag.Mode = "Edit"; if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = PackingHeader.DocTypeId, DocId = PackingHeader.PackingHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = PackingHeader.DocNo, DocDate = PackingHeader.DocDate, DocStatus = PackingHeader.Status, })); } return(View("Create", vm)); }
// GET: /ProductMaster/Edit/5 private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; PurchaseOrderAmendmentHeader pt = _PurchaseOrderAmendmentHeaderService.Find(id); if (pt == null) { return(HttpNotFound()); } PurchaseOrderAmendmentHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderAmendmentHeader, PurchaseOrderAmendmentHeaderViewModel>(pt); #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(pt), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if ((!TimePlanValidation && !Continue)) { return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType })); } //Purchase Order Settings var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "PurchaseOrderSettings", new { id = pt.DocTypeId }).Warning("Please create Purchase order settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings); PrepareViewBag(pt.DocTypeId); ViewBag.Mode = "Edit"; if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.PurchaseOrderAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = pt.DocNo, DocDate = pt.DocDate, DocStatus = pt.Status, })); } return(View("Create", temp)); }
public ActionResult Post(ExcessMaterialHeaderViewModel svm) { ExcessMaterialHeader s = Mapper.Map <ExcessMaterialHeaderViewModel, ExcessMaterialHeader>(svm); System.Web.HttpContext.Current.Session["ExcessMaterialDocDate"] = svm.DocDate; #region BeforeSave bool BeforeSave = true; try { if (svm.ExcessMaterialHeaderId <= 0) { BeforeSave = ExcessMaterialDocEvents.beforeHeaderSaveEvent(this, new StockEventArgs(svm.ExcessMaterialHeaderId, EventModeConstants.Add), ref context); } else { BeforeSave = ExcessMaterialDocEvents.beforeHeaderSaveEvent(this, new StockEventArgs(svm.ExcessMaterialHeaderId, EventModeConstants.Edit), ref context); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } #endregion #region DocTypeTimeLineValidation try { if (svm.ExcessMaterialHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue)) { #region CreateRecord if (svm.ExcessMaterialHeaderId <= 0) { s.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".ExcessMaterialHeaders", s.DocTypeId, s.DocDate, s.DivisionId, s.SiteId); s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; //_ExcessMaterialHeaderService.Create(s); s.ObjectState = Model.ObjectState.Added; context.ExcessMaterialHeader.Add(s); try { ExcessMaterialDocEvents.onHeaderSaveEvent(this, new StockEventArgs(s.ExcessMaterialHeaderId, EventModeConstants.Add), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } context.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); } try { ExcessMaterialDocEvents.afterHeaderSaveEvent(this, new StockEventArgs(s.ExcessMaterialHeaderId, EventModeConstants.Add), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.ExcessMaterialHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); return(RedirectToAction("Modify", "ExcessMaterialHeader", new { Id = s.ExcessMaterialHeaderId }).Success("Data saved successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); ExcessMaterialHeader temp = _ExcessMaterialHeaderService.Find(s.ExcessMaterialHeaderId); ExcessMaterialHeader ExRec = new ExcessMaterialHeader(); ExRec = Mapper.Map <ExcessMaterialHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; } temp.DocDate = s.DocDate; temp.DocNo = s.DocNo; temp.PersonId = s.PersonId; temp.ProcessId = s.ProcessId; temp.GodownId = s.GodownId; temp.Remark = s.Remark; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; context.ExcessMaterialHeader.Add(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { ExcessMaterialDocEvents.onHeaderSaveEvent(this, new StockEventArgs(temp.ExcessMaterialHeaderId, EventModeConstants.Edit), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } context.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(svm.DocTypeId); ViewBag.id = svm.DocTypeId; return(View("Create", svm)); } try { ExcessMaterialDocEvents.afterHeaderSaveEvent(this, new StockEventArgs(s.ExcessMaterialHeaderId, EventModeConstants.Edit), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.ExcessMaterialHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); }
public ActionResult Create(DispatchWaybillHeaderViewModel svm) { string DataValidationMsg = DataValidation(svm); if (DataValidationMsg != "") { PrepareViewBag(svm); PrepareViewBag(svm.DocTypeId); return(View(svm).Danger(DataValidationMsg)); } #region DocTypeTimeLineValidation try { if (svm.DispatchWaybillHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (svm.DispatchWaybillHeaderId == 0) { DispatchWaybillHeader DispatchWaybillHeader = Mapper.Map <DispatchWaybillHeaderViewModel, DispatchWaybillHeader>(svm); DispatchWaybillHeader.CreatedDate = DateTime.Now; DispatchWaybillHeader.ModifiedDate = DateTime.Now; DispatchWaybillHeader.CreatedBy = User.Identity.Name; DispatchWaybillHeader.ModifiedBy = User.Identity.Name; DispatchWaybillHeader.Status = (int)StatusConstants.Drafted; if (svm.DocTypeId == new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.PreDispatchWaybill).DocumentTypeId) { DispatchWaybillHeader.IsPreCarriage = true; } else { DispatchWaybillHeader.IsPreCarriage = false; } _DispatchWaybillHeaderService.Create(DispatchWaybillHeader); var routecities = new RouteLineService(_unitOfWork).GetRouteLineListForIndex(svm.RouteId).ToList(); foreach (var item in routecities) { DispatchWaybillLine DispatchWaybillLine = new DispatchWaybillLine(); DispatchWaybillLine.CityId = item.CityId; DispatchWaybillLine.CreatedDate = DateTime.Now; DispatchWaybillLine.ModifiedDate = DateTime.Now; DispatchWaybillLine.CreatedBy = User.Identity.Name; DispatchWaybillLine.ModifiedBy = User.Identity.Name; new DispatchWaybillLineService(_unitOfWork).Create(DispatchWaybillLine); } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(svm); ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = DispatchWaybillHeader.DocTypeId, DocId = DispatchWaybillHeader.DispatchWaybillHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = DispatchWaybillHeader.DocNo, DocDate = DispatchWaybillHeader.DocDate, DocStatus = DispatchWaybillHeader.Status, })); return(RedirectToAction("Modify", new { id = DispatchWaybillHeader.DispatchWaybillHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { int routeid = _DispatchWaybillHeaderService.GetDispatchWaybillHeaderViewModel(svm.DispatchWaybillHeaderId).RouteId; DispatchWaybillHeader DispatchWaybillHeader = Mapper.Map <DispatchWaybillHeaderViewModel, DispatchWaybillHeader>(svm); int status = DispatchWaybillHeader.Status; if (DispatchWaybillHeader.Status != (int)StatusConstants.Drafted && DispatchWaybillHeader.Status != (int)StatusConstants.Import) { DispatchWaybillHeader.Status = (int)StatusConstants.Modified; } DispatchWaybillHeader.Status = (int)StatusConstants.Modified; DispatchWaybillHeader.ModifiedDate = DateTime.Now; DispatchWaybillHeader.ModifiedBy = User.Identity.Name; _DispatchWaybillHeaderService.Update(DispatchWaybillHeader); if (routeid != svm.RouteId) { var dispatchwaybillline = new DispatchWaybillLineService(_unitOfWork).GetDispatchWaybillLineForHeaderId(svm.DispatchWaybillHeaderId); foreach (var item in dispatchwaybillline) { new DispatchWaybillLineService(_unitOfWork).Delete(item.DispatchWaybillLineId); } var routecities = new RouteLineService(_unitOfWork).GetRouteLineListForIndex(svm.RouteId).ToList(); foreach (var item in routecities) { DispatchWaybillLine DispatchWaybillLine = new DispatchWaybillLine(); DispatchWaybillLine.DispatchWaybillHeaderId = DispatchWaybillHeader.DispatchWaybillHeaderId; DispatchWaybillLine.CityId = item.CityId; DispatchWaybillLine.CreatedDate = DateTime.Now; DispatchWaybillLine.ModifiedDate = DateTime.Now; DispatchWaybillLine.CreatedBy = User.Identity.Name; DispatchWaybillLine.ModifiedBy = User.Identity.Name; new DispatchWaybillLineService(_unitOfWork).Create(DispatchWaybillLine); } } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Edit"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = DispatchWaybillHeader.DocTypeId, DocId = DispatchWaybillHeader.DispatchWaybillHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = DispatchWaybillHeader.DocNo, DocDate = DispatchWaybillHeader.DocDate, DocStatus = DispatchWaybillHeader.Status, })); return(RedirectToAction("Index", new { id = svm.DocTypeId, IndexType = "" }).Success("Data saved successfully")); } #endregion } PrepareViewBag(svm); PrepareViewBag(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); }
public ActionResult Post(RequisitionCancelHeaderViewModel vm) { RequisitionCancelHeader pt = AutoMapper.Mapper.Map <RequisitionCancelHeaderViewModel, RequisitionCancelHeader>(vm); if (vm.PersonId <= 0) { ModelState.AddModelError("PersonId", "The Person field is required"); } #region BeforeSave bool BeforeSave = true; try { if (vm.RequisitionCancelHeaderId <= 0) { BeforeSave = MaterialRequestCancelDocEvents.beforeHeaderSaveEvent(this, new StockEventArgs(vm.RequisitionCancelHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = MaterialRequestCancelDocEvents.beforeHeaderSaveEvent(this, new StockEventArgs(vm.RequisitionCancelHeaderId, EventModeConstants.Edit), ref db); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } #endregion #region DocTypeTimeLineValidation try { if (vm.RequisitionCancelHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue)) { #region CreateRecord if (vm.RequisitionCancelHeaderId <= 0) { 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; pt.ObjectState = Model.ObjectState.Added; db.RequisitionCancelHeader.Add(pt); //_RequisitionCancelHeaderService.Create(pt); try { MaterialRequestCancelDocEvents.onHeaderSaveEvent(this, new StockEventArgs(pt.RequisitionCancelHeaderId, 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(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); } try { MaterialRequestCancelDocEvents.afterHeaderSaveEvent(this, new StockEventArgs(pt.RequisitionCancelHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pt.DocTypeId, DocId = pt.RequisitionCancelHeaderId, DocNo = pt.DocNo, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Modify", new { id = pt.RequisitionCancelHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); RequisitionCancelHeader temp = _RequisitionCancelHeaderService.Find(pt.RequisitionCancelHeaderId); RequisitionCancelHeader ExRec = new RequisitionCancelHeader(); ExRec = Mapper.Map <RequisitionCancelHeader>(temp); if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; } temp.DocDate = pt.DocDate; temp.DocNo = pt.DocNo; temp.ReasonId = pt.ReasonId; temp.Remark = pt.Remark; temp.PersonId = pt.PersonId; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; db.RequisitionCancelHeader.Add(temp); //_RequisitionCancelHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { MaterialRequestCancelDocEvents.onHeaderSaveEvent(this, new StockEventArgs(temp.RequisitionCancelHeaderId, EventModeConstants.Edit), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Edit"; return(View("Create", pt)); } try { MaterialRequestCancelDocEvents.afterHeaderSaveEvent(this, new StockEventArgs(temp.RequisitionCancelHeaderId, EventModeConstants.Edit), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.RequisitionCancelHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = temp.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult CreatePost(PackingHeaderViewModel vm) { #region DocTypeTimeLineValidation try { if (vm.PackingHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (vm.PackingHeaderId == 0) { PackingHeader Packingheader = Mapper.Map <PackingHeaderViewModel, PackingHeader>(vm); Packingheader.BuyerId = vm.BuyerId; Packingheader.CreatedBy = User.Identity.Name; Packingheader.ModifiedBy = User.Identity.Name; Packingheader.CreatedDate = DateTime.Now; Packingheader.ModifiedDate = DateTime.Now; Packingheader.ObjectState = Model.ObjectState.Added; _PackingHeaderService.Create(Packingheader); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Packingheader.DocTypeId, DocId = Packingheader.PackingHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = Packingheader.DocNo, DocDate = Packingheader.DocDate, DocStatus = Packingheader.Status, })); return(RedirectToAction("Modify", new { id = Packingheader.PackingHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PackingHeader Packingheader = _PackingHeaderService.Find(vm.PackingHeaderId); PackingHeader ExRec = Mapper.Map <PackingHeader>(Packingheader); StockHeader StockHeader = new StockHeaderService(_unitOfWork).Find(Packingheader.StockHeaderId ?? 0); int status = Packingheader.Status; if (Packingheader.Status != (int)StatusConstants.Drafted) { Packingheader.Status = (int)StatusConstants.Modified; } Packingheader.DocNo = vm.DocNo; Packingheader.DocDate = vm.DocDate; Packingheader.BuyerId = vm.BuyerId; Packingheader.GodownId = vm.GodownId; Packingheader.Remark = vm.Remark; Packingheader.ModifiedDate = DateTime.Now; Packingheader.ModifiedBy = User.Identity.Name; _PackingHeaderService.Update(Packingheader); if (StockHeader != null) { StockHeader.DocDate = vm.DocDate; StockHeader.PersonId = vm.BuyerId; StockHeader.GodownId = vm.GodownId; StockHeader.Remark = vm.Remark; StockHeader.ModifiedDate = DateTime.Now; StockHeader.ModifiedBy = User.Identity.Name; new StockHeaderService(_unitOfWork).Update(StockHeader); } LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = Packingheader, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Edit"; return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Packingheader.DocTypeId, DocId = Packingheader.PackingHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = Packingheader.DocNo, xEModifications = Modifications, DocDate = Packingheader.DocDate, DocStatus = Packingheader.Status, })); return(RedirectToAction("Index", new { id = vm.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult Post(QAGroupViewModel svm) { bool BeforeSave = true; bool CostCenterGenerated = false; QAGroup s = Mapper.Map <QAGroupViewModel, QAGroup>(svm); #region BeforeSaveEvents try { if (svm.QAGroupId <= 0) { BeforeSave = JobOrderDocEvents.beforeHeaderSaveEvent(this, new JobEventArgs(svm.QAGroupId, EventModeConstants.Add), ref context); } else { BeforeSave = JobOrderDocEvents.beforeHeaderSaveEvent(this, new JobEventArgs(svm.QAGroupId, EventModeConstants.Edit), ref context); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } #endregion #region DocTypeTimeLineValidation try { if (svm.QAGroupId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue)) { //CreateLogic #region CreateRecord if (svm.QAGroupId <= 0) { // s.GodownId= (int)System.Web.HttpContext.Current.Session["DefaultGodownId"]; s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; s.ObjectState = Model.ObjectState.Added; context.QAGroup.Add(s); try { JobOrderDocEvents.onHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Add), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } //_unitOfWork.Save(); context.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; PrepareViewBag(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); } try { JobOrderDocEvents.afterHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Add), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.QAGroupId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.QaGroupName, DocDate = s.CreatedDate, DocStatus = s.Status, })); //Update DocId in COstCenter return(RedirectToAction("Modify", "QAGroup", new { Id = s.QAGroupId }).Success("Data saved successfully")); } #endregion //EditLogic #region EditRecord else { bool GodownChanged = false; List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); QAGroup temp = context.QAGroup.Find(s.QAGroupId); QAGroup ExRec = Mapper.Map <QAGroup>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; } temp.QaGroupName = s.QaGroupName; temp.Description = s.Description; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; context.QAGroup.Add(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { JobOrderDocEvents.onHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Edit), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } context.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); PrepareViewBag(svm.DocTypeId); TempData["CSEXC"] += message; ViewBag.id = svm.DocTypeId; ViewBag.Mode = "Edit"; return(View("Create", svm)); } try { JobOrderDocEvents.afterHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Edit), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.QAGroupId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.QaGroupName, xEModifications = Modifications, DocDate = temp.CreatedDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); }
public ActionResult Post(StockHeaderViewModel svm) { StockHeader s = Mapper.Map <StockHeaderViewModel, StockHeader>(svm); #region BeforeSave bool BeforeSave = true; try { if (svm.StockHeaderId <= 0) { BeforeSave = JobConsumptionDocEvents.beforeHeaderSaveEvent(this, new StockEventArgs(svm.StockHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = JobConsumptionDocEvents.beforeHeaderSaveEvent(this, new StockEventArgs(svm.StockHeaderId, EventModeConstants.Edit), ref db); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } #endregion #region DocTypeTimeLineValidation try { if (svm.StockHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (svm.StockHeaderSettings != null) { if (svm.StockHeaderSettings.isMandatoryMachine == true && (svm.MachineId <= 0 || svm.MachineId == null)) { ModelState.AddModelError("MachineId", "The Machine field is required"); } } if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue)) { #region CreateRecord if (svm.StockHeaderId <= 0) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; s.ObjectState = Model.ObjectState.Added; db.StockHeader.Add(s); //_StockHeaderService.Create(s); try { JobConsumptionDocEvents.onHeaderSaveEvent(this, new StockEventArgs(s.StockHeaderId, 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(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); } try { JobConsumptionDocEvents.afterHeaderSaveEvent(this, new StockEventArgs(s.StockHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.StockHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); return(RedirectToAction("Modify", "JobConsumptionHeader", new { Id = s.StockHeaderId }).Success("Data saved successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StockHeader temp = _StockHeaderService.Find(s.StockHeaderId); StockHeader ExRec = new StockHeader(); ExRec = Mapper.Map <StockHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; } temp.DocDate = s.DocDate; temp.DocNo = s.DocNo; temp.CostCenterId = s.CostCenterId; temp.MachineId = s.MachineId; temp.PersonId = s.PersonId; temp.ProcessId = s.ProcessId; temp.GodownId = s.GodownId; temp.Remark = s.Remark; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; db.StockHeader.Add(temp); //_StockHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { JobConsumptionDocEvents.onHeaderSaveEvent(this, new StockEventArgs(temp.StockHeaderId, EventModeConstants.Edit), 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(svm.DocTypeId); ViewBag.id = svm.DocTypeId; return(View("Create", svm)); } try { JobConsumptionDocEvents.afterHeaderSaveEvent(this, new StockEventArgs(s.StockHeaderId, EventModeConstants.Edit), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.StockHeaderId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully")); } #endregion } PrepareViewBag(svm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", svm)); }
// GET: /StockHeader/Edit/5 private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; StockHeaderViewModel s = _StockHeaderService.GetStockHeader(id); if (s == null) { return(HttpNotFound()); } if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, s.DocTypeId, s.ProcessId, this.ControllerContext.RouteData.Values["controller"].ToString(), "Edit") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(s), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if ((!TimePlanValidation && !Continue)) { return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType })); } //Job Order Settings var settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreateForJobConsumption", "StockHeaderSettings", new { id = s.DocTypeId }).Warning("Please create Job Consumption settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } s.StockHeaderSettings = Mapper.Map <StockHeaderSettings, StockHeaderSettingsViewModel>(settings); ViewBag.Mode = "Edit"; PrepareViewBag(s.DocTypeId); if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.StockHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); } return(View("Create", s)); }
public ActionResult Post(JobInvoiceAmendmentHeaderViewModel vm) { int Serial = 1; bool TimePlanValidation = true; string ExceptionMsg = ""; bool Continue = true; int pk = 0; Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>(); var SelectedJobInvoices = (List <JobInvoiceAmendmentWizardViewModel>)System.Web.HttpContext.Current.Session["RateAmendmentWizardOrders"]; JobInvoiceAmendmentHeader Header = AutoMapper.Mapper.Map <JobInvoiceAmendmentHeaderViewModel, JobInvoiceAmendmentHeader>(vm); List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>(); List <LineChargeViewModel> LineCharges = new List <LineChargeViewModel>(); List <LineReferenceIds> RefIds = new List <LineReferenceIds>(); bool HeaderChargeEdit = false; int PersonCount = 0; var settings = new JobInvoiceSettingsService(_unitOfWork).GetJobInvoiceSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); //int? CalculationId = settings.CalculationId; List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>(); if (vm.JobInvoiceSettings.isVisibleHeaderJobWorker && !vm.JobWorkerId.HasValue) { ModelState.AddModelError("JobWorkerId", "The JobWorker field is required"); } #region BeforeSave bool BeforeSave = true; try { BeforeSave = JobInvoiceAmendmentDocEvents.beforeWizardSaveEvent(this, new JobEventArgs(vm.JobInvoiceAmendmentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before save"; } #endregion #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue)) { if (SelectedJobInvoices.Count > 0) { Header.Status = (int)StatusConstants.Drafted; Header.CreatedDate = DateTime.Now; Header.ModifiedDate = DateTime.Now; Header.CreatedBy = User.Identity.Name; Header.ModifiedBy = User.Identity.Name; Header.ObjectState = Model.ObjectState.Added; db.JobInvoiceAmendmentHeader.Add(Header); //_JobInvoiceAmendmentHeaderService.Create(pt); var JobInvoiceLineIds = SelectedJobInvoices.Select(m => m.JobInvoiceLineId).ToArray(); var JobInvoiceBalanceRecords = (from p in db.ViewJobInvoiceBalanceForRateAmendment where JobInvoiceLineIds.Contains(p.JobInvoiceLineId) select p).AsNoTracking().ToList(); var JobInvoiceRecords = (from p in db.JobInvoiceLine where JobInvoiceLineIds.Contains(p.JobInvoiceLineId) select p).AsNoTracking().ToList(); int?CalculationId = 0; int JobInvoiceLineId = JobInvoiceBalanceRecords.FirstOrDefault().JobInvoiceLineId; var SalesTaxGroupPerson = (from L in db.JobInvoiceLine where L.JobInvoiceLineId == JobInvoiceLineId select new { SalesTaxGroupPersonId = (int?)L.JobInvoiceHeader.SalesTaxGroupPerson.ChargeGroupPersonId ?? 0 }).FirstOrDefault(); if (SalesTaxGroupPerson != null) { CalculationId = new ChargeGroupPersonCalculationService(_unitOfWork).GetChargeGroupPersonCalculation(Header.DocTypeId, SalesTaxGroupPerson.SalesTaxGroupPersonId, Header.SiteId, Header.DivisionId) ?? 0; } if (CalculationId == 0) { CalculationId = settings.CalculationId ?? 0; } foreach (var item in SelectedJobInvoices) { if (item.Rate - JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate != 0) { JobInvoiceRateAmendmentLine line = new JobInvoiceRateAmendmentLine(); line.JobInvoiceAmendmentHeaderId = Header.JobInvoiceAmendmentHeaderId; line.JobInvoiceLineId = item.JobInvoiceLineId; line.Qty = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().BalanceQty; line.AmendedRate = item.Rate; line.Rate = line.AmendedRate - JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate; line.Amount = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().BalanceQty *JobInvoiceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().UnitConversionMultiplier *line.Rate; line.Amount = DecimalRoundOff.amountToFixed(line.Amount, settings.AmountRoundOff); line.JobInvoiceRate = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().Rate; line.JobWorkerId = JobInvoiceBalanceRecords.Where(m => m.JobInvoiceLineId == item.JobInvoiceLineId).FirstOrDefault().JobWorkerId; line.Sr = Serial++; line.JobInvoiceRateAmendmentLineId = pk; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; LineStatus.Add(line.JobInvoiceLineId, line.Rate); RefIds.Add(new LineReferenceIds { LineId = line.JobInvoiceRateAmendmentLineId, RefLineId = line.JobInvoiceLineId }); line.ObjectState = Model.ObjectState.Added; db.JobInvoiceRateAmendmentLine.Add(line); LineList.Add(new LineDetailListViewModel { Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobInvoiceRateAmendmentLineId, HeaderTableId = Header.JobInvoiceAmendmentHeaderId, PersonID = line.JobWorkerId, DealQty = 0 }); pk++; } } //new JobInvoiceLineStatusService(_unitOfWork).UpdateJobRateOnAmendmentMultiple(LineStatus, pt.DocDate, ref db); int[] RecLineIds = null; RecLineIds = RefIds.Select(m => m.RefLineId).ToArray(); var Charges = (from p in db.JobInvoiceLine where RecLineIds.Contains(p.JobInvoiceLineId) join LineCharge in db.JobInvoiceLineCharge on p.JobInvoiceLineId equals LineCharge.LineTableId join HeaderCharge in db.JobInvoiceHeaderCharges on p.JobInvoiceHeaderId equals HeaderCharge.HeaderTableId group new { p, LineCharge, HeaderCharge } by new { p.JobInvoiceLineId } into g select new { LineId = g.Key.JobInvoiceLineId, HeaderCharges = g.Select(m => m.HeaderCharge).ToList(), Linecharges = g.Select(m => m.LineCharge).ToList(), }).ToList(); var LineListWithReferences = (from p in LineList join t in RefIds on p.LineTableId equals t.LineId join t2 in Charges on t.RefLineId equals t2.LineId into table from LineLis in table.DefaultIfEmpty() orderby p.LineTableId select new LineDetailListViewModel { Amount = p.Amount, DealQty = p.DealQty, HeaderTableId = p.HeaderTableId, LineTableId = p.LineTableId, PersonID = p.PersonID, Rate = p.Rate, CostCenterId = p.CostCenterId, RLineCharges = (LineLis == null ? null : Mapper.Map <List <LineChargeViewModel> >(LineLis.Linecharges)), }).ToList(); if (CalculationId != null) { new ChargesCalculationService(_unitOfWork).CalculateCharges(LineListWithReferences, Header.JobInvoiceAmendmentHeaderId, (int)CalculationId, 0, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobInvoiceAmendmentHeaderCharges", "Web.JobInvoiceRateAmendmentLineCharges", out PersonCount, Header.DocTypeId, Header.SiteId, Header.DivisionId); } //Saving Charges foreach (var item in LineCharges) { JobInvoiceRateAmendmentLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, JobInvoiceRateAmendmentLineCharge>(item); PoLineCharge.ObjectState = Model.ObjectState.Added; db.JobInvoiceRateAmendmentLineCharge.Add(PoLineCharge); } //Saving Header charges for (int i = 0; i < HeaderCharges.Count(); i++) { if (!HeaderChargeEdit) { JobInvoiceAmendmentHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, JobInvoiceAmendmentHeaderCharge>(HeaderCharges[i]); POHeaderCharge.HeaderTableId = Header.JobInvoiceAmendmentHeaderId; POHeaderCharge.PersonID = Header.JobWorkerId; POHeaderCharge.ObjectState = Model.ObjectState.Added; db.JobInvoiceAmendmentHeaderCharge.Add(POHeaderCharge); } else { var footercharge = new JobInvoiceAmendmentHeaderChargeService(db).Find(HeaderCharges[i].Id); footercharge.Rate = HeaderCharges[i].Rate; footercharge.Amount = HeaderCharges[i].Amount; footercharge.ObjectState = Model.ObjectState.Modified; db.JobInvoiceAmendmentHeaderCharge.Add(footercharge); } } try { JobInvoiceAmendmentDocEvents.onWizardSaveEvent(this, new JobEventArgs(Header.JobInvoiceAmendmentHeaderId, 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 { JobInvoiceAmendmentDocEvents.afterWizardSaveEvent(this, new JobEventArgs(Header.JobInvoiceAmendmentHeaderId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = Header.DocTypeId, DocId = Header.JobInvoiceAmendmentHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, DocNo = Header.DocNo, DocDate = Header.DocDate, DocStatus = Header.Status, })); Session.Remove("RateAmendmentWizardOrders"); } return(RedirectToAction("Index", "JobInvoiceAmendmentHeader", new { id = Header.DocTypeId }).Success("Data saved Successfully")); } PrepareViewBag(vm.DocTypeId); ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult Post(SaleDeliveryHeaderViewModel svm) { bool TimePlanValidation = true; string ExceptionMsg = ""; bool Continue = true; SaleDeliveryHeader s = Mapper.Map <SaleDeliveryHeaderViewModel, SaleDeliveryHeader>(svm); List <SaleDeliveryWizardViewModel> SaleInvoiceAndQtys = (List <SaleDeliveryWizardViewModel>)System.Web.HttpContext.Current.Session["PendingInvoiceForSaleDelivery"]; if (svm.SaleDeliverySettings != null) { //if (svm.SaleDeliverySettings.isMandatoryCostCenter == true && (string.IsNullOrEmpty(svm.CostCenterName))) //{ // ModelState.AddModelError("CostCenterName", "The CostCenter field is required"); //} } if (SaleInvoiceAndQtys.Count() <= 0) { ModelState.AddModelError("", "No Records Selected"); } int SaleToBuyerCnt = (from l in SaleInvoiceAndQtys group l by l.SaleToBuyerId into g select new { SaleToBuyerId = g.Key, }).Distinct().Count(); if (SaleToBuyerCnt > 1) { ModelState.AddModelError("", "Select any one Buyer Orders."); } List <SaleDeliveryLine> BarCodesToUpdate = new List <SaleDeliveryLine>(); bool CostCenterGenerated = false; #region DocTypeTimeLineValidation try { if (svm.SaleDeliveryHeaderId <= 0) { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue); } else { TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXC"] += ExceptionMsg; } #endregion if (ModelState.IsValid && (TimePlanValidation || Continue)) { if (svm.SaleDeliveryHeaderId <= 0) { if (SaleInvoiceAndQtys.Count() > 0) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; _SaleDeliveryHeaderService.Create(s); int Cnt = 0; int Sr = 0; int pk = 0; SaleDeliverySetting Settings = new SaleDeliverySettingService(_unitOfWork).GetSaleDeliverySettingForDocument(s.DocTypeId, s.DivisionId, s.SiteId); var SaleInvoiceLineIds = SaleInvoiceAndQtys.Select(m => m.SaleInvoiceLineId).ToArray(); var BalQtyandUnits = (from p in db.ViewSaleInvoiceBalanceForDelivery join t in db.Product on p.ProductId equals t.ProductId where SaleInvoiceLineIds.Contains(p.SaleInvoiceLineId) select new { BalQty = p.BalanceQty, SaleInvoiceLineId = p.SaleInvoiceLineId, UnitId = t.UnitId, }).ToList(); if (ModelState.IsValid) { foreach (var SelectedSaleInvoice in SaleInvoiceAndQtys) { if (SelectedSaleInvoice.SaleInvoiceLineId > 0) { var SaleInvoiceLine = new SaleInvoiceLineService(_unitOfWork).Find((SelectedSaleInvoice.SaleInvoiceLineId)); var Product = new ProductService(_unitOfWork).Find(SaleInvoiceLine.ProductId); var bal = BalQtyandUnits.Where(m => m.SaleInvoiceLineId == SelectedSaleInvoice.SaleInvoiceLineId).FirstOrDefault(); if (SelectedSaleInvoice.Qty <= bal.BalQty) { SaleDeliveryLine line = new SaleDeliveryLine(); line.SaleDeliveryHeaderId = s.SaleDeliveryHeaderId; line.SaleInvoiceLineId = SaleInvoiceLine.SaleInvoiceLineId; line.Qty = SelectedSaleInvoice.Qty; line.UnitConversionMultiplier = SaleInvoiceLine.UnitConversionMultiplier ?? 1; line.DealQty = SelectedSaleInvoice.Qty * line.UnitConversionMultiplier; line.DealUnitId = SaleInvoiceLine.DealUnitId; line.Sr = Sr++; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.SaleDeliveryLineId = pk; line.ObjectState = Model.ObjectState.Added; new SaleDeliveryLineService(_unitOfWork).Create(line); pk++; Cnt = Cnt + 1; } } } } string Errormessage = ""; try { _unitOfWork.Save(); } catch (Exception ex) { Errormessage = _exception.HandleException(ex); ModelState.AddModelError("", Errormessage); PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.SaleDeliveryHeaderId, ActivityType = (int)ActivityTypeContants.WizardCreate, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); System.Web.HttpContext.Current.Session.Remove("PendingInvoiceForSaleDelivery"); return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/SaleDeliveryHeader/Submit/" + s.SaleDeliveryHeaderId)); } else { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/SaleDeliveryHeader/Index/" + s.DocTypeId)); } } else { } } PrepareViewBag(); ViewBag.Mode = "Add"; return(View("Create", svm)); }