public ActionResult Wizard(int id)//Document Type Id { //ControllerAction ca = new ControllerActionService(_unitOfWork).Find(id); MaterialPlanHeaderViewModel vm = new MaterialPlanHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; var settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(id, vm.DivisionId, vm.SiteId); if (settings != null) { if (settings.WizardMenuId != null) { MenuViewModel menuviewmodel = new MenuService(_unitOfWork).GetMenu((int)settings.WizardMenuId); if (menuviewmodel == null) { return(View("~/Views/Shared/UnderImplementation.cshtml")); } else if (!string.IsNullOrEmpty(menuviewmodel.URL)) { return(Redirect(System.Configuration.ConfigurationManager.AppSettings[menuviewmodel.URL] + "/" + menuviewmodel.ControllerName + "/" + menuviewmodel.ActionName + "/" + menuviewmodel.RouteId + "?MenuId=" + menuviewmodel.MenuId)); } else { return(RedirectToAction(menuviewmodel.ActionName, menuviewmodel.ControllerName, new { MenuId = menuviewmodel.MenuId, id = menuviewmodel.RouteId })); } } } return(RedirectToAction("Index", new { id = id })); }
public ActionResult Create(int id)//DocumentTypeID { MaterialPlanHeaderViewModel vm = new MaterialPlanHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; vm.CreatedDate = DateTime.Now; //Getting Settings var settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(id, vm.DivisionId, vm.SiteId); vm.MaterialPlanSettings = Mapper.Map <MaterialPlanSettings, MaterialPlanSettingsViewModel>(settings); vm.BuyerId = (int)System.Web.HttpContext.Current.Session["BuyerId"]; List <MaterialPlanForSaleOrderViewModel> svm = new List <MaterialPlanForSaleOrderViewModel>(); svm = (List <MaterialPlanForSaleOrderViewModel>)System.Web.HttpContext.Current.Session["SODyeingPlan"]; vm.DocDate = DateTime.Now; vm.DueDate = DateTime.Now; vm.DocTypeId = id; vm.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".MaterialPlanHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId); ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; ViewBag.id = id; ViewBag.Mode = "Add"; return(View("Create", vm)); }
public ActionResult Detail(int id, string transactionType, string IndexType, int?DocLineId) { if (DocLineId.HasValue) { ViewBag.DocLineId = DocLineId; } ViewBag.transactionType = transactionType; ViewBag.IndexStatus = IndexType; MaterialPlanHeader pt = _MaterialPlanHeaderService.Find(id); MaterialPlanHeaderViewModel vm = AutoMapper.Mapper.Map <MaterialPlanHeader, MaterialPlanHeaderViewModel>(pt); if (pt == null) { return(HttpNotFound()); } //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.Name = new DocumentTypeService(_unitOfWork).Find(pt.DocTypeId).DocumentTypeName; ViewBag.id = pt.DocTypeId; if (String.IsNullOrEmpty(transactionType) || transactionType == "detail") { 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)); }
// GET: /MaterialPlanHeaderMaster/Create public ActionResult Create(int id)//DocumentTypeID { MaterialPlanHeaderViewModel vm = new MaterialPlanHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; vm.DocNo = _MaterialPlanHeaderService.GetMaxDocNo(); vm.CreatedDate = DateTime.Now; //Getting Settings var settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(id, vm.DivisionId, vm.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "MaterialPlanSettings", new { id = id }).Warning("Please create job order settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } vm.MaterialPlanSettings = Mapper.Map <MaterialPlanSettings, MaterialPlanSettingsViewModel>(settings); if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, id, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Create") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } if (string.IsNullOrEmpty(vm.MaterialPlanSettings.PlanType)) { TempData["CSEXC"] += "Please configure PlanType"; } vm.DocDate = DateTime.Now; vm.DueDate = DateTime.Now; vm.DocTypeId = id; vm.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".MaterialPlanHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId); ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; ViewBag.id = id; ViewBag.Mode = "Add"; return(View("Create", 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 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 (ModelState.IsValid && (TimePlanValidation || Continue)) { #region CreateRecord if (vm.MaterialPlanHeaderId <= 0) { using (var context = new ApplicationDbContext()) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; context.MaterialPlanHeader.Add(pt); int Serial = 0; MaterialPlanLineListViewModel svm = new MaterialPlanLineListViewModel(); svm.MaterialPlanLineViewModel = (List <MaterialPlanForSaleOrderViewModel>)System.Web.HttpContext.Current.Session["SODyeingPlan"]; var Summary = (IEnumerable <MaterialPlanLineViewModel>)System.Web.HttpContext.Current.Session["SODyeingPlanSummary"]; MaterialPlanSettings Settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId); bool isPr = false; bool isPP = false; int j = 0; foreach (var item in Summary) { { MaterialPlanLine planLine = new MaterialPlanLine(); planLine.RequiredQty = item.RequiredQty; planLine.ExcessStockQty = item.ExcessStockQty; planLine.MaterialPlanHeaderId = item.MaterialPlanHeaderId; planLine.ProductId = item.ProductId; planLine.Dimension1Id = item.Dimension1Id; planLine.Dimension2Id = item.Dimension2Id; planLine.ProdPlanQty = item.ProdPlanQty; planLine.CreatedBy = User.Identity.Name; planLine.CreatedDate = DateTime.Now; planLine.Sr = Serial++; planLine.Specification = item.Specification; planLine.ModifiedBy = User.Identity.Name; planLine.MaterialPlanLineId = j; planLine.ModifiedDate = DateTime.Now; planLine.ProcessId = item.ProcessId; planLine.Remark = item.Remark; planLine.PurchPlanQty = item.PurchPlanQty; planLine.StockPlanQty = item.StockPlanQty; planLine.GeneratedFor = MaterialPlanConstants.SaleOrder; planLine.ObjectState = Model.ObjectState.Added; context.MaterialPlanLine.Add(planLine); if (!isPr) { if (item.ProdPlanQty > 0) { isPr = true; } } if (!isPP) { if (item.PurchPlanQty > 0) { isPP = true; } } } j++; } if (isPr) { ProdOrderHeader ExistingProdOrder = new ProdOrderHeaderService(_unitOfWork).GetProdOrderForMaterialPlan(pt.MaterialPlanHeaderId); int ProdORderSerial = 1; if (ExistingProdOrder == null) { ProdOrderHeader prodOrderHeader = new ProdOrderHeader(); prodOrderHeader.CreatedBy = User.Identity.Name; prodOrderHeader.CreatedDate = DateTime.Now; prodOrderHeader.DivisionId = pt.DivisionId; prodOrderHeader.DocDate = pt.DocDate; prodOrderHeader.DocNo = pt.DocNo; prodOrderHeader.DocTypeId = Settings.DocTypeProductionOrderId.Value; prodOrderHeader.DueDate = pt.DueDate; prodOrderHeader.MaterialPlanHeaderId = pt.MaterialPlanHeaderId; prodOrderHeader.ModifiedBy = User.Identity.Name; prodOrderHeader.ModifiedDate = DateTime.Now; prodOrderHeader.Remark = pt.Remark; prodOrderHeader.BuyerId = pt.BuyerId; prodOrderHeader.SiteId = pt.SiteId; //prodOrderHeader.Status = header.Status; prodOrderHeader.Status = (int)StatusConstants.System; prodOrderHeader.ObjectState = Model.ObjectState.Added; context.ProdOrderHeader.Add(prodOrderHeader); //ForCreating ProdOrderStatus ProdOrderHeaderStatus pts = new ProdOrderHeaderStatus(); pts.ProdOrderHeaderId = prodOrderHeader.ProdOrderHeaderId; pts.ObjectState = Model.ObjectState.Added; context.ProdOrderHeaderStatus.Add(pts); int ProdOrderLineKey = 0; foreach (var item in context.MaterialPlanLine.Local.Where(m => m.ProdPlanQty > 0)) { ProdOrderLine prodOrderLine = new ProdOrderLine(); prodOrderLine.CreatedBy = User.Identity.Name; prodOrderLine.CreatedDate = DateTime.Now; prodOrderLine.MaterialPlanLineId = item.MaterialPlanLineId; prodOrderLine.ModifiedBy = User.Identity.Name; prodOrderLine.ModifiedDate = DateTime.Now; prodOrderLine.ProdOrderHeaderId = prodOrderHeader.ProdOrderHeaderId; prodOrderLine.Specification = item.Specification; prodOrderLine.ProductId = item.ProductId; prodOrderLine.Dimension1Id = item.Dimension1Id; prodOrderLine.Dimension2Id = item.Dimension2Id; prodOrderLine.Sr = ProdORderSerial++; prodOrderLine.Qty = item.ProdPlanQty; prodOrderLine.Remark = item.Remark; prodOrderLine.ProdOrderLineId = ProdOrderLineKey++; prodOrderLine.ObjectState = Model.ObjectState.Added; context.ProdOrderLine.Add(prodOrderLine); //ForAdding ProdrderLinestatus ProdOrderLineStatus ptl = new ProdOrderLineStatus(); ptl.ProdOrderLineId = prodOrderLine.ProdOrderLineId; ptl.ObjectState = Model.ObjectState.Added; context.ProdOrderLineStatus.Add(ptl); } } else { ProdORderSerial = new ProdOrderLineService(_unitOfWork).GetMaxSr(ExistingProdOrder.ProdOrderHeaderId); int ProdOrderLineKey = 0; foreach (var item in context.MaterialPlanLine.Local.Where(m => m.ProdPlanQty > 0)) { ProdOrderLine prodOrderLine = new ProdOrderLine(); prodOrderLine.CreatedBy = User.Identity.Name; prodOrderLine.CreatedDate = DateTime.Now; prodOrderLine.MaterialPlanLineId = item.MaterialPlanLineId; prodOrderLine.ModifiedBy = User.Identity.Name; prodOrderLine.ModifiedDate = DateTime.Now; prodOrderLine.ProdOrderHeaderId = ExistingProdOrder.ProdOrderHeaderId; prodOrderLine.ProductId = item.ProductId; prodOrderLine.Dimension1Id = item.Dimension1Id; prodOrderLine.Dimension2Id = item.Dimension2Id; prodOrderLine.Specification = item.Specification; prodOrderLine.Qty = item.ProdPlanQty; prodOrderLine.Sr = ProdORderSerial++; prodOrderLine.Remark = item.Remark; prodOrderLine.ProdOrderLineId = ProdOrderLineKey++; prodOrderLine.ObjectState = Model.ObjectState.Added; context.ProdOrderLine.Add(prodOrderLine); //ForAdding ProdrderLinestatus ProdOrderLineStatus ptl = new ProdOrderLineStatus(); ptl.ProdOrderLineId = prodOrderLine.ProdOrderLineId; ptl.ObjectState = Model.ObjectState.Added; context.ProdOrderLineStatus.Add(ptl); } } } if (isPP) { PurchaseIndentHeader ExistingIndent = new PurchaseIndentHeaderService(_unitOfWork).GetPurchaseIndentForMaterialPlan(pt.MaterialPlanHeaderId); int PurchaseIndentSr = 1; if (ExistingIndent == null) { PurchaseIndentHeader indentHeader = new PurchaseIndentHeader(); indentHeader.CreatedBy = User.Identity.Name; indentHeader.CreatedDate = DateTime.Now; indentHeader.DivisionId = pt.DivisionId; indentHeader.DocDate = pt.DocDate; indentHeader.DocNo = pt.DocNo; indentHeader.DocTypeId = Settings.DocTypePurchaseIndentId.Value; indentHeader.ModifiedBy = User.Identity.Name; indentHeader.MaterialPlanHeaderId = pt.MaterialPlanHeaderId; indentHeader.ModifiedDate = DateTime.Now; indentHeader.Remark = pt.Remark; indentHeader.SiteId = pt.SiteId; //indentHeader.Status = header.Status; indentHeader.Status = (int)StatusConstants.System; indentHeader.DepartmentId = (int)DepartmentConstants.Production; indentHeader.ObjectState = Model.ObjectState.Added; context.PurchaseIndentHeader.Add(indentHeader); foreach (var item in context.MaterialPlanLine.Local.Where(m => m.PurchPlanQty > 0)) { PurchaseIndentLine indentLine = new PurchaseIndentLine(); indentLine.CreatedBy = User.Identity.Name; indentLine.CreatedDate = DateTime.Now; indentLine.MaterialPlanLineId = item.MaterialPlanLineId; indentLine.ModifiedBy = User.Identity.Name; indentLine.ModifiedDate = DateTime.Now; indentLine.ProductId = item.ProductId; indentLine.Dimension1Id = item.Dimension1Id; indentLine.Dimension2Id = item.Dimension2Id; indentLine.Specification = item.Specification; indentLine.PurchaseIndentHeaderId = indentHeader.PurchaseIndentHeaderId; indentLine.Qty = item.PurchPlanQty; indentLine.Sr = PurchaseIndentSr++; indentLine.Remark = item.Remark; indentLine.ObjectState = Model.ObjectState.Added; context.PurchaseIndentLine.Add(indentLine); } } else { PurchaseIndentSr = new PurchaseIndentLineService(_unitOfWork).GetMaxSr(ExistingIndent.PurchaseIndentHeaderId); foreach (var item in context.MaterialPlanLine.Local.Where(m => m.PurchPlanQty > 0)) { PurchaseIndentLine indentLine = new PurchaseIndentLine(); indentLine.CreatedBy = User.Identity.Name; indentLine.CreatedDate = DateTime.Now; indentLine.MaterialPlanLineId = item.MaterialPlanLineId; indentLine.ModifiedBy = User.Identity.Name; indentLine.Specification = item.Specification; indentLine.ModifiedDate = DateTime.Now; indentLine.ProductId = item.ProductId; indentLine.Dimension1Id = item.Dimension1Id; indentLine.Dimension2Id = item.Dimension2Id; indentLine.Sr = PurchaseIndentSr++; indentLine.PurchaseIndentHeaderId = ExistingIndent.PurchaseIndentHeaderId; indentLine.Qty = item.PurchPlanQty; indentLine.Remark = item.Remark; indentLine.ObjectState = Model.ObjectState.Added; context.PurchaseIndentLine.Add(indentLine); } } } int i = 0; int MaterialPlanForSaleOrderSr = new MaterialPlanForSaleOrderService(_unitOfWork).GetMaxSr(svm.MaterialPlanLineViewModel.FirstOrDefault().MaterialPlanHeaderId); foreach (var item in svm.MaterialPlanLineViewModel) { if (item.Qty > 0) { MaterialPlanForSaleOrder order = new MaterialPlanForSaleOrder(); order.MaterialPlanHeaderId = item.MaterialPlanHeaderId; order.Qty = item.Qty; order.SaleOrderLineId = item.SaleOrderLineId; order.MaterialPlanForSaleOrderId = i; order.Sr = MaterialPlanForSaleOrderSr++; order.CreatedBy = User.Identity.Name; order.CreatedDate = DateTime.Now; order.ModifiedBy = User.Identity.Name; order.ModifiedDate = DateTime.Now; //if (item.Dimension1Id != null) //{ // var MaterialPlan = context.MaterialPlanLine.Local.Where(m => m.ProductId == item.ProductId && m.Dimension1Id == item.Dimension1Id).FirstOrDefault(); // if (order != null) // { // order.MaterialPlanLineId = MaterialPlan.MaterialPlanLineId; // } //} //else //{ // var MaterialPlan = context.MaterialPlanLine.Local.Where(m => m.ProductId == item.ProductId).FirstOrDefault(); // if (order != null) // { // order.MaterialPlanLineId = MaterialPlan.MaterialPlanLineId; // } //} order.ObjectState = Model.ObjectState.Added; context.MaterialPlanForSaleOrder.Add(order); i++; } } try { context.SaveChanges(); } 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("Index", "MaterialPlanHeader", new { id = pt.DocTypeId })); } } #endregion } ViewBag.Name = new DocumentTypeService(_unitOfWork).Find(vm.DocTypeId).DocumentTypeName; ViewBag.id = vm.DocTypeId; ViewBag.Mode = "Add"; return(View("Create", vm)); }