// GET: /StockHeader/Create public ActionResult Create(int id)//DocumentTypeId { StockHeaderViewModel p = new StockHeaderViewModel(); p.DocDate = DateTime.Now.Date; p.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; p.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; p.CreatedDate = DateTime.Now; //Getting Settings var settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(id, p.DivisionId, p.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreateForJobConsumption", "StockHeaderSettings", new { id = id }).Warning("Please create Job Consumption settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } p.StockHeaderSettings = Mapper.Map <StockHeaderSettings, StockHeaderSettingsViewModel>(settings); p.ProcessId = settings.ProcessId; if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, id, settings.ProcessId, this.ControllerContext.RouteData.Values["controller"].ToString(), "Create") == false) { return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task.")); } PrepareViewBag(id); p.DocTypeId = id; p.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".StockHeaders", p.DocTypeId, p.DocDate, p.DivisionId, p.SiteId); ViewBag.Mode = "Add"; return(View(p)); }
public ActionResult Import(int id)//Document Type Id { //ControllerAction ca = new ControllerActionService(_unitOfWork).Find(id); StockHeaderViewModel vm = new StockHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; var settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(id, vm.DivisionId, vm.SiteId); if (settings != null) { if (settings.ImportMenuId != null) { MenuViewModel menuviewmodel = new MenuService(_unitOfWork).GetMenu((int)settings.ImportMenuId); 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 + "/" + id + "?MenuId=" + menuviewmodel.MenuId)); } else { return(RedirectToAction(menuviewmodel.ActionName, menuviewmodel.ControllerName, new { MenuId = menuviewmodel.MenuId, id = id })); } } } return(RedirectToAction("Index", new { id = id })); }
public ActionResult Detail(int id, string IndexType, string transactionType) { //Saving ViewBag Data:: ViewBag.transactionType = transactionType; ViewBag.IndexStatus = IndexType; StockHeaderViewModel s = _StockHeaderService.GetStockHeader(id); //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); PrepareViewBag(s.DocTypeId); if (s == null) { return(HttpNotFound()); } if (String.IsNullOrEmpty(transactionType) || transactionType == "detail") { 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 void UpdateStockHeader(StockHeaderViewModel S) { StockHeader StockHeader = Find(S.StockHeaderId); StockHeader.DocTypeId = S.DocTypeId; StockHeader.DocDate = S.DocDate; StockHeader.DocNo = S.DocNo; StockHeader.DivisionId = S.DivisionId; StockHeader.SiteId = S.SiteId; StockHeader.CurrencyId = S.CurrencyId; StockHeader.PersonId = S.PersonId; StockHeader.ProcessId = S.ProcessId; StockHeader.FromGodownId = S.FromGodownId; StockHeader.GodownId = S.GodownId; StockHeader.Remark = S.Remark; StockHeader.Status = S.Status; StockHeader.ModifiedBy = S.ModifiedBy; StockHeader.ModifiedDate = S.ModifiedDate; StockHeader.CostCenterId = S.CostCenterId; StockHeader.MachineId = S.MachineId; Update(StockHeader); }
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)); }
// 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(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)); }