public ActionResult Create(ProductConsumptionHeaderViewModel svm) { Product SProd = new ProductService(_unitOfWork).Find(svm.ProductId); if (ModelState.IsValid) { if (svm.BaseProductId == 0) { Product product = new Product(); if (SProd.ProductName.Length > 16) { product.ProductCode = SProd.ProductName.ToString().Substring(0, 16) + "-Bom"; } else { product.ProductCode = SProd.ProductName.ToString().Substring(0, SProd.ProductName.Length) + "-Bom"; } product.ProductName = SProd.ProductName + "-Bom"; product.ProductGroupId = new ProductGroupService(_unitOfWork).Find(ProductGroupConstants.Bom).ProductGroupId; product.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; product.IsActive = true; product.ReferenceDocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Product).DocumentTypeId; product.ReferenceDocId = svm.ProductId; product.CreatedDate = DateTime.Now; product.ModifiedDate = DateTime.Now; product.CreatedBy = User.Identity.Name; product.ModifiedBy = User.Identity.Name; product.ObjectState = Model.ObjectState.Added; _ProductService.Create(product); var ExistingRec = _BomDetailService.GetExistingBaseProduct(SProd.ProductId); if (ExistingRec != null) { ExistingRec.ProductId = product.ProductId; ExistingRec.CreatedDate = DateTime.Now; ExistingRec.ModifiedBy = User.Identity.Name; _BomDetailService.Update(ExistingRec); } else { BomDetail bomdetail = new BomDetail(); bomdetail.BaseProductId = SProd.ProductId; bomdetail.BatchQty = 1; bomdetail.ConsumptionPer = 100; bomdetail.ProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.Weaving).ProcessId; bomdetail.ProductId = product.ProductId; bomdetail.Qty = 1; bomdetail.CreatedDate = DateTime.Now; bomdetail.ModifiedDate = DateTime.Now; bomdetail.CreatedBy = User.Identity.Name; bomdetail.ModifiedBy = User.Identity.Name; bomdetail.ObjectState = Model.ObjectState.Added; _BomDetailService.Create(bomdetail); } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View(svm)); } //return RedirectToAction("Create").Success("Data saved successfully"); return(RedirectToAction("Edit", new { id = product.ProductId }).Success("Data saved Successfully")); } else { Product product = _ProductService.Find(svm.BaseProductId); if (SProd.ProductName.Length > 16) { product.ProductCode = SProd.ProductName.ToString().Substring(0, 16) + "-Bom"; } else { product.ProductCode = SProd.ProductName.ToString().Substring(0, SProd.ProductName.Length) + "-Bom"; } product.ProductName = SProd.ProductName + "-Bom"; product.ReferenceDocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Product).DocumentTypeId; product.ReferenceDocId = svm.ProductId; product.ModifiedBy = User.Identity.Name; product.ModifiedDate = DateTime.Now; StringBuilder logstring = new StringBuilder(); _ProductService.Update(product); ////Saving Activity Log:: ActivityLog al = new ActivityLog() { ActivityType = (int)ActivityTypeContants.Modified, DocId = svm.BaseProductId, Narration = logstring.ToString(), CreatedDate = DateTime.Now, CreatedBy = User.Identity.Name, //DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.ProcessSequence).DocumentTypeId, }; new ActivityLogService(_unitOfWork).Create(al); //End of Saving ActivityLog try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", svm)); } return(RedirectToAction("Index").Success("Data saved successfully")); } } PrepareViewBag(); return(View(svm)); }