// GET: /PurchaseIndentCancelHeader/Create public ActionResult Create(int id)//DocumentTypeIndex { PrepareViewBag(id); PurchaseIndentCancelHeaderViewModel s = new PurchaseIndentCancelHeaderViewModel(); s.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; s.SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; s.CreatedDate = DateTime.Now; //Getting Settings var settings = new PurchaseIndentSettingService(_unitOfWork).GetPurchaseIndentSettingForDocument(id, s.DivisionId, s.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreatePurchaseIndentCancel", "PurchaseIndentSetting", new { id = id }).Warning("Please create Purchase Indent cancel settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } s.PurchaseIndentSettings = Mapper.Map <PurchaseIndentSetting, PurchaseIndentSettingsViewModel>(settings); s.DocTypeId = id; s.DocDate = DateTime.Now; s.DocNo = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseIndentCancelHeaders", s.DocTypeId, s.DocDate, s.DivisionId, s.SiteId); ViewBag.Mode = "Add"; return(View("Create", s)); }
public ActionResult Detail(int id, string IndexType, string transactionType) { ViewBag.transactionType = transactionType; ViewBag.IndexStatus = IndexType; PurchaseIndentCancelHeader s = _PurchaseIndentCancelHeaderService.Find(id); PurchaseIndentCancelHeaderViewModel svm = Mapper.Map <PurchaseIndentCancelHeader, PurchaseIndentCancelHeaderViewModel>(s); PrepareViewBag(s.DocTypeId); //Job Order Settings var settings = new PurchaseIndentSettingService(_unitOfWork).GetPurchaseIndentSettingForDocument(s.DocTypeId, s.DivisionId, s.SiteId); if (settings == null) { return(RedirectToAction("Create", "PurchaseIndentSetting", new { id = s.DocTypeId }).Warning("Please create Purchase Indent cancel settings")); } svm.PurchaseIndentSettings = Mapper.Map <PurchaseIndentSetting, PurchaseIndentSettingsViewModel>(settings); if (s == null) { return(HttpNotFound()); } if (String.IsNullOrEmpty(transactionType) || transactionType == "detail") { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.PurchaseIndentCancelHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); } return(View("Create", svm)); }
// GET: /PurchaseIndentCancelHeader/Edit/5 private ActionResult Edit(int id, string IndexType) { ViewBag.IndexStatus = IndexType; PurchaseIndentCancelHeader s = _PurchaseIndentCancelHeaderService.Find(id); PurchaseIndentCancelHeaderViewModel svm = Mapper.Map <PurchaseIndentCancelHeader, PurchaseIndentCancelHeaderViewModel>(s); if (svm == 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 })); } PrepareViewBag(s.DocTypeId); //Job Order Settings var settings = new PurchaseIndentSettingService(_unitOfWork).GetPurchaseIndentSettingForDocument(s.DocTypeId, svm.DivisionId, svm.SiteId); if (settings == null && UserRoles.Contains("SysAdmin")) { return(RedirectToAction("CreatePurchaseIndentCancel", "PurchaseIndentSetting", new { id = s.DocTypeId }).Warning("Please create Purchase Indent cancel settings")); } else if (settings == null && !UserRoles.Contains("SysAdmin")) { return(View("~/Views/Shared/InValidSettings.cshtml")); } svm.PurchaseIndentSettings = Mapper.Map <PurchaseIndentSetting, PurchaseIndentSettingsViewModel>(settings); ViewBag.Mode = "Edit"; if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create")) { LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = s.DocTypeId, DocId = s.PurchaseIndentCancelHeaderId, ActivityType = (int)ActivityTypeContants.Detail, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); } return(View("Create", svm)); }
public ActionResult HeaderPost(PurchaseIndentCancelHeaderViewModel svm) { #region BeforeSave bool BeforeSave = true; try { if (svm.PurchaseIndentCancelHeaderId <= 0) { BeforeSave = PurchaseIndentCancelDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = PurchaseIndentCancelDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, 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.PurchaseIndentCancelHeaderId <= 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.PurchaseIndentCancelHeaderId <= 0) { PurchaseIndentCancelHeader s = new PurchaseIndentCancelHeader(); s.DocTypeId = svm.DocTypeId; s.DocDate = svm.DocDate; s.DocNo = svm.DocNo; s.Remark = svm.Remark; s.CreatedDate = DateTime.Now; s.SiteId = svm.SiteId; s.ReasonId = svm.ReasonId; s.DivisionId = svm.DivisionId; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; //_PurchaseIndentCancelHeaderService.Create(s); s.ObjectState = Model.ObjectState.Added; db.PurchaseIndentCancelHeader.Add(s); try { PurchaseIndentCancelDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, 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) { PrepareViewBag(svm.DocTypeId); string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Add"; return(View("Create", svm)); } try { PurchaseIndentCancelDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, 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.PurchaseIndentCancelHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); //return Edit(s.PurchaseIndentCancelHeaderId).Success("Data saved Successfully"); return(RedirectToAction("Modify", new { id = s.PurchaseIndentCancelHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); StringBuilder logstring = new StringBuilder(); PurchaseIndentCancelHeader temp = _PurchaseIndentCancelHeaderService.Find(svm.PurchaseIndentCancelHeaderId); PurchaseIndentCancelHeader ExRec = new PurchaseIndentCancelHeader(); ExRec = Mapper.Map <PurchaseIndentCancelHeader>(temp); int status = temp.Status; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; } temp.DocTypeId = svm.DocTypeId; temp.DocDate = svm.DocDate; temp.DocNo = svm.DocNo; temp.Remark = svm.Remark; temp.ReasonId = svm.ReasonId; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; db.PurchaseIndentCancelHeader.Add(temp); //_PurchaseIndentCancelHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { PurchaseIndentCancelDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseIndentCancelHeaderId, 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) { PrepareViewBag(svm.DocTypeId); string message = _exception.HandleException(ex); TempData["CSEXC"] += message; ViewBag.Mode = "Edit"; return(View("Create", svm)); } try { PurchaseIndentCancelDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseIndentCancelHeaderId, 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.PurchaseIndentCancelHeaderId, 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)); }