public ActionResult Import(int id)//Document Type Id { //ControllerAction ca = new ControllerActionService(_unitOfWork).Find(id); ExcessMaterialHeaderViewModel vm = new ExcessMaterialHeaderViewModel(); vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; vm.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; var settings = new ExcessMaterialSettingsService(_unitOfWork, context).GetExcessMaterialSettingsForDocument(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 Create(int id)//DocumentTypeId { ExcessMaterialHeaderViewModel p = new ExcessMaterialHeaderViewModel(); if (System.Web.HttpContext.Current.Session["ExcessMaterialDocDate"] == null) { p.DocDate = DateTime.Now; } else { p.DocDate = (DateTime)System.Web.HttpContext.Current.Session["ExcessMaterialDocDate"]; } 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 ExcessMaterialSettingsService(_unitOfWork, context).GetExcessMaterialSettingsForDocument(id, p.DivisionId, p.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "ExcessMaterialSettings", new { id = id }).Warning("Please create Material Issue settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } p.ExcessMaterialSettings = Mapper.Map <ExcessMaterialSettings, ExcessMaterialSettingsViewModel>(settings); p.ProcessId = settings.ProcessId; if (System.Web.HttpContext.Current.Session["DefaultGodownId"] != null) { p.GodownId = (int)System.Web.HttpContext.Current.Session["DefaultGodownId"]; } PrepareViewBag(id); p.DocTypeId = id; p.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".ExcessMaterialHeaders", p.DocTypeId, p.DocDate, p.DivisionId, p.SiteId); ViewBag.Mode = "Add"; return(View(p)); }
public ActionResult Detail(int id, string IndexType, string transactionType) { //Saving ViewBag Data:: ViewBag.transactionType = transactionType; ViewBag.IndexStatus = IndexType; ExcessMaterialHeaderViewModel s = _ExcessMaterialHeaderService.GetExcessMaterialHeader(id); //Job Order Settings var settings = new ExcessMaterialSettingsService(_unitOfWork, context).GetExcessMaterialSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId); if (settings == null) { return(RedirectToAction("Create", "ExcessMaterialSettings", new { id = s.DocTypeId }).Warning("Please create Material Issue settings")); } s.ExcessMaterialSettings = Mapper.Map <ExcessMaterialSettings, ExcessMaterialSettingsViewModel>(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.ExcessMaterialHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); } return(View("Create", s)); }
public void UpdateExcessMaterialHeader(ExcessMaterialHeaderViewModel S) { ExcessMaterialHeader ExcessMaterialHeader = Find(S.ExcessMaterialHeaderId); ExcessMaterialHeader.DocTypeId = S.DocTypeId; ExcessMaterialHeader.DocDate = S.DocDate; ExcessMaterialHeader.DocNo = S.DocNo; ExcessMaterialHeader.DivisionId = S.DivisionId; ExcessMaterialHeader.SiteId = S.SiteId; ExcessMaterialHeader.CurrencyId = S.CurrencyId; ExcessMaterialHeader.PersonId = S.PersonId; ExcessMaterialHeader.ProcessId = S.ProcessId; ExcessMaterialHeader.GodownId = S.GodownId; ExcessMaterialHeader.Remark = S.Remark; ExcessMaterialHeader.Status = S.Status; ExcessMaterialHeader.ModifiedBy = S.ModifiedBy; ExcessMaterialHeader.ModifiedDate = S.ModifiedDate; Update(ExcessMaterialHeader); }
private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; ExcessMaterialHeaderViewModel s = _ExcessMaterialHeaderService.GetExcessMaterialHeader(id); if (s == null) { return(HttpNotFound()); } #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 ExcessMaterialSettingsService(_unitOfWork, context).GetExcessMaterialSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("Create", "ExcessMaterialSettings", new { id = s.DocTypeId }).Warning("Please create Material Issue settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } s.ExcessMaterialSettings = Mapper.Map <ExcessMaterialSettings, ExcessMaterialSettingsViewModel>(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.ExcessMaterialHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); } return(View("Create", s)); }
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)); }