// GET: /JobReceiveSettingsMaster/Create public ActionResult Create(int id)//DocTypeId { if (!UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; var SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; PrepareViewBag(); var settings = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(id, DivisionId, SiteId); if (settings == null) { JobReceiveSettingsViewModel vm = new JobReceiveSettingsViewModel(); vm.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; vm.SiteId = SiteId; vm.DivisionId = DivisionId; vm.DocTypeId = id; return(View("Create", vm)); } else { JobReceiveSettingsViewModel temp = AutoMapper.Mapper.Map <JobReceiveSettings, JobReceiveSettingsViewModel>(settings); temp.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName; return(View("Create", temp)); } }
// GET: /JobReceiveHeader/Create public ActionResult Create()//DocumentTypeId { JobReceiveHeaderViewModel p = new JobReceiveHeaderViewModel(); p.DocDate = DateTime.Now; p.CreatedDate = DateTime.Now; p.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; p.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; int DocTypeId = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.WeavingBazar).DocumentTypeId; p.DocTypeId = DocTypeId; //Getting Settings var settings = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(DocTypeId, p.DivisionId, p.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "JobReceiveSettings", new { id = DocTypeId }).Warning("Please create job order settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } p.JobReceiveSettings = Mapper.Map <JobReceiveSettings, JobReceiveSettingsViewModel>(settings); if (System.Web.HttpContext.Current.Session["BarCodesWeavingWizardJobOrder"] == null) { return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + DocTypeId)); } var JobOrderLin = ((List <WeavingReceiveWizardViewModel>)System.Web.HttpContext.Current.Session["BarCodesWeavingWizardJobOrder"]).FirstOrDefault(); //p.JobReceiveById = new EmployeeService(_unitOfWork).GetEmloyeeForUser(User.Identity.GetUserId()); p.ProcessId = settings.ProcessId; if (System.Web.HttpContext.Current.Session["DefaultGodownId"] != null) { p.GodownId = (int)System.Web.HttpContext.Current.Session["DefaultGodownId"]; } PrepareViewBag(); p.DocTypeId = DocTypeId; p.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".JobReceiveHeaders", p.DocTypeId, p.DocDate, p.DivisionId, p.SiteId); List <WeavingReceiveWizardViewModel> JobOrdersAndQtys = (List <WeavingReceiveWizardViewModel>)System.Web.HttpContext.Current.Session["BarCodesWeavingWizardJobOrder"]; p.JobWorkerId = JobOrdersAndQtys.FirstOrDefault().JobWorkerId; return(View(p)); }
public ActionResult CreateWeavingReceive(int id)//DocTypeId { int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"]; ViewBag.id = id; int DocTypeId = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeId; //Getting Settings var settings = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(DocTypeId, DivisionId, SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "JobReceiveSettings", new { id = DocTypeId }).Warning("Please create settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } return(View("CreateWeavingReceive")); }
public ActionResult JobReceive_OnSubmit(int Id, string ReturnUrl) { int Cnt = 0; JobReceiveHeader Header = new JobReceiveHeaderService(_unitOfWork).Find(Id); //#region BomPost //IEnumerable<JobReceiveBom> JobReceiveBomList = new JobReceiveBomService(_unitOfWork).GetBomForHeader(Header.JobReceiveHeaderId); //foreach (JobReceiveBom item in JobReceiveBomList) //{ // if (item.StockProcessId != 0 && item.JobReceiveBomId != null) // { // new StockProcessService(_unitOfWork).Delete((int)item.StockProcessId); // } // new JobReceiveBomService(_unitOfWork).Delete(item.JobReceiveBomId); //} //SqlParameter SQLJobReceiveHeaderId = new SqlParameter("@JobReceiveHeaderId", Id); //List<ProcGetBomForWeavingViewModel> BomForWeaving = new List<ProcGetBomForWeavingViewModel>(); //BomForWeaving = db.Database.SqlQuery<ProcGetBomForWeavingViewModel>("Web.ProcGetBomForWeavingReceive @JobReceiveHeaderId", SQLJobReceiveHeaderId).ToList(); //foreach (var item in BomForWeaving) //{ // Cnt = Cnt + 1; // JobReceiveBom BomPost = new JobReceiveBom(); // BomPost.JobReceiveHeaderId = Id; // BomPost.CreatedBy = User.Identity.Name; // BomPost.CreatedDate = DateTime.Now; // BomPost.ModifiedBy = User.Identity.Name; // BomPost.ModifiedDate = DateTime.Now; // BomPost.ProductId = item.ProductId; // BomPost.Dimension1Id = item.Dimension1Id; // BomPost.Dimension2Id = item.Dimension2Id; // BomPost.CostCenterId = item.CostCenterId; // BomPost.Qty = Convert.ToDecimal(item.Qty); // StockProcessViewModel StockProcessBomViewModel = new StockProcessViewModel(); // if (Header.StockHeaderId != null && Header.StockHeaderId != 0) // { // StockProcessBomViewModel.StockHeaderId = (int)Header.StockHeaderId; // } // StockProcessBomViewModel.StockProcessId = -Cnt; // StockProcessBomViewModel.DocHeaderId = Header.JobReceiveHeaderId; // StockProcessBomViewModel.DocLineId = BomPost.JobReceiveBomId; // StockProcessBomViewModel.DocTypeId = Header.DocTypeId; // StockProcessBomViewModel.StockHeaderDocDate = Header.DocDate; // StockProcessBomViewModel.StockProcessDocDate = DateTime.Now.Date; // StockProcessBomViewModel.DocNo = Header.DocNo; // StockProcessBomViewModel.DivisionId = Header.DivisionId; // StockProcessBomViewModel.SiteId = Header.SiteId; // StockProcessBomViewModel.CurrencyId = null; // StockProcessBomViewModel.HeaderProcessId = null; // StockProcessBomViewModel.PersonId = Header.JobWorkerId; // StockProcessBomViewModel.ProductId = item.ProductId; // StockProcessBomViewModel.HeaderFromGodownId = null; // StockProcessBomViewModel.HeaderGodownId = null; // StockProcessBomViewModel.GodownId = Header.GodownId; // StockProcessBomViewModel.ProcessId = Header.ProcessId; // StockProcessBomViewModel.LotNo = null; // StockProcessBomViewModel.CostCenterId = item.CostCenterId; // StockProcessBomViewModel.Qty_Iss = item.Qty; // StockProcessBomViewModel.Qty_Rec = 0; // StockProcessBomViewModel.Rate = 0; // StockProcessBomViewModel.ExpiryDate = null; // StockProcessBomViewModel.Specification = null; // StockProcessBomViewModel.Dimension1Id = item.Dimension1Id; // StockProcessBomViewModel.Dimension2Id = item.Dimension2Id; // StockProcessBomViewModel.Remark = null; // StockProcessBomViewModel.Status = Header.Status; // StockProcessBomViewModel.CreatedBy = User.Identity.Name; // StockProcessBomViewModel.CreatedDate = DateTime.Now; // StockProcessBomViewModel.ModifiedBy = User.Identity.Name; // StockProcessBomViewModel.ModifiedDate = DateTime.Now; // string StockProcessPostingError = ""; // StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPost(ref StockProcessBomViewModel); // if (StockProcessPostingError != "") // { // ModelState.AddModelError("", StockProcessPostingError); // //return PartialView("_Create", svm); // } // BomPost.StockProcessId = StockProcessBomViewModel.StockProcessId; // BomPost.ObjectState = Model.ObjectState.Added; // new JobReceiveBomService(_unitOfWork).Create(BomPost); // if (Header.StockHeaderId == null) // { // Header.StockHeaderId = StockProcessBomViewModel.StockHeaderId; // } //} //#endregion string ConnectionString = (string)System.Web.HttpContext.Current.Session["DefaultConnectionString"]; JobReceiveSettings Setting = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId); //string ProcConsumption = Setting.SqlProcConsumption.ToString(); try { DataSet ds = new DataSet(); using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) { sqlConnection.Open(); using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".sp_PostBomForWeavingReceive")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = sqlConnection; cmd.Parameters.AddWithValue("@JobReceiveHeaderId", Id); cmd.CommandTimeout = 1000; //cmd.Connection.Open(); cmd.ExecuteNonQuery(); //cmd.Connection.Close(); } //using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".Mig_PostWeavingConsumption_OldData")) //{ // cmd.CommandType = CommandType.StoredProcedure; // cmd.Connection = sqlConnection; // cmd.Parameters.AddWithValue("@JobReceiveHeaderId", Id); // cmd.CommandTimeout = 1000; // cmd.ExecuteNonQuery(); //} using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".sp_PostBazarAtBranch")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = sqlConnection; cmd.Parameters.AddWithValue("@JobReceiveHeaderId", Id); cmd.CommandTimeout = 1000; //cmd.Connection.Open(); cmd.ExecuteNonQuery(); //cmd.Connection.Close(); } using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".Mig_WeavingReceiveLedgerPosting")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = sqlConnection; cmd.Parameters.AddWithValue("@JobReceiveHeaderId", Id); cmd.CommandTimeout = 1000; //cmd.Connection.Open(); cmd.ExecuteNonQuery(); //cmd.Connection.Close(); } //using (SqlCommand cmd = new SqlCommand("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".sp_WeavingSmallChunk_LedgerPost")) //{ // cmd.CommandType = CommandType.StoredProcedure; // cmd.Connection = sqlConnection; // cmd.Parameters.AddWithValue("@JobReceiveHeaderId", Id); // cmd.CommandTimeout = 1000; // //cmd.Connection.Open(); // cmd.ExecuteNonQuery(); // //cmd.Connection.Close(); //} } } catch (Exception ex) { if (Header == null) { throw new Exception("Header is null"); } Header.Status = (int)StatusConstants.Drafted; new JobReceiveHeaderService(_unitOfWork).Update(Header); _unitOfWork.Save(); return(Redirect(ReturnUrl).Warning(ex.Message.ToString())); //throw ex; } return(Redirect(ReturnUrl)); }
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)); }