public ActionResult DeletePost(PurchaseIndentLineViewModel vm) { bool BeforeSave = true; try { BeforeSave = PurchaseIndentDocEvents.beforeLineDeleteEvent(this, new PurchaseEventArgs(vm.PurchaseIndentHeaderId, vm.PurchaseIndentLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Validation failed before delete."; } if (BeforeSave && !EventException) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseIndentLine PurchaseIndentLine = db.PurchaseIndentLine.Find(vm.PurchaseIndentLineId); try { PurchaseIndentDocEvents.onLineDeleteEvent(this, new PurchaseEventArgs(PurchaseIndentLine.PurchaseIndentHeaderId, PurchaseIndentLine.PurchaseIndentLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } LogList.Add(new LogTypeViewModel { ExObj = Mapper.Map <PurchaseIndentLine>(PurchaseIndentLine), }); //_PurchaseIndentLineService.Delete(PurchaseIndentLine); PurchaseIndentHeader header = new PurchaseIndentHeaderService(_unitOfWork).Find(PurchaseIndentLine.PurchaseIndentHeaderId); if (header.Status != (int)StatusConstants.Drafted) { header.Status = (int)StatusConstants.Modified; //new PurchaseIndentHeaderService(_unitOfWork).Update(header); header.ModifiedBy = User.Identity.Name; header.ModifiedDate = DateTime.Now; header.ObjectState = Model.ObjectState.Modified; db.PurchaseIndentHeader.Add(header); } PurchaseIndentLine.ObjectState = Model.ObjectState.Deleted; db.PurchaseIndentLine.Remove(PurchaseIndentLine); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Create", vm)); } try { PurchaseIndentDocEvents.afterLineDeleteEvent(this, new PurchaseEventArgs(PurchaseIndentLine.PurchaseIndentHeaderId, PurchaseIndentLine.PurchaseIndentLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.PurchaseIndentHeaderId, DocLineId = PurchaseIndentLine.PurchaseIndentLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
public ActionResult _ResultsPost(PurchaseIndentMasterDetailModel vm) { int Serial = _PurchaseIndentLineService.GetMaxSr(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId); bool BeforeSave = true; try { BeforeSave = PurchaseIndentDocEvents.beforeLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save"); } if (ModelState.IsValid && BeforeSave && !EventException) { PurchaseIndentHeader header = new PurchaseIndentHeaderService(_unitOfWork).Find(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId); if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import) { header.Status = (int)StatusConstants.Modified; header.ModifiedBy = User.Identity.Name; header.ModifiedDate = DateTime.Now; header.ObjectState = Model.ObjectState.Modified; db.PurchaseIndentHeader.Add(header); } foreach (var item in vm.PurchaseIndentLineViewModel) { if (item.Qty > 0) { PurchaseIndentLine line = new PurchaseIndentLine(); line.PurchaseIndentHeaderId = item.PurchaseIndentHeaderId; line.MaterialPlanLineId = item.MaterialPlanLineId; line.ProductId = item.ProductId; line.Dimension1Id = item.Dimension1Id; line.Dimension2Id = item.Dimension2Id; line.Specification = item.Specification; line.Remark = item.Remark; line.Qty = item.Qty; line.Sr = Serial++; line.CreatedDate = DateTime.Now; line.ModifiedDate = DateTime.Now; line.CreatedBy = User.Identity.Name; line.ModifiedBy = User.Identity.Name; line.ObjectState = Model.ObjectState.Added; //_PurchaseIndentLineService.Create(line); db.PurchaseIndentLine.Add(line); } } try { PurchaseIndentDocEvents.onLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Results", vm)); } try { PurchaseIndentDocEvents.afterLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentLineViewModel.FirstOrDefault().PurchaseIndentHeaderId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.PurchaseIndentHeaderId, ActivityType = (int)ActivityTypeContants.MultipleCreate, DocNo = header.DocNo, DocDate = header.DocDate, DocStatus = header.Status, })); return(Json(new { success = true })); } return(PartialView("_Results", vm)); }
public ActionResult _CreatePost(PurchaseIndentLineViewModel svm) { PurchaseIndentLine s = Mapper.Map <PurchaseIndentLineViewModel, PurchaseIndentLine>(svm); PurchaseIndentHeader temp = new PurchaseIndentHeaderService(_unitOfWork).Find(s.PurchaseIndentHeaderId); ViewBag.Status = temp.Status; if (svm.PurchaseIndentLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (temp.DocDate > s.DueDate && s.DueDate != null) { ModelState.AddModelError("DueDate", "Duedate should be greater than Docdate"); } if (s.Qty <= 0) { ModelState.AddModelError("Qty", "Qty field is required"); } bool BeforeSave = true; try { if (svm.PurchaseIndentLineId <= 0) { BeforeSave = PurchaseIndentDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = PurchaseIndentDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentHeaderId, EventModeConstants.Edit), ref db); } } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } if (!BeforeSave) { ModelState.AddModelError("", "Validation failed before save."); } if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.PurchaseIndentLineId <= 0) { s.Sr = _PurchaseIndentLineService.GetMaxSr(s.PurchaseIndentHeaderId); s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; //_PurchaseIndentLineService.Create(s); db.PurchaseIndentLine.Add(s); PurchaseIndentHeader header = new PurchaseIndentHeaderService(_unitOfWork).Find(s.PurchaseIndentHeaderId); if (header.Status != (int)StatusConstants.Drafted) { header.Status = (int)StatusConstants.Modified; //new PurchaseIndentHeaderService(_unitOfWork).Update(header); header.ModifiedBy = User.Identity.Name; header.ModifiedDate = DateTime.Now; header.ObjectState = Model.ObjectState.Modified; db.PurchaseIndentHeader.Add(header); } try { PurchaseIndentDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, s.PurchaseIndentLineId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Create", svm)); } try { PurchaseIndentDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, s.PurchaseIndentLineId, EventModeConstants.Add), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.PurchaseIndentHeaderId, DocLineId = s.PurchaseIndentLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = svm.PurchaseIndentHeaderId, date = ((svm.DueDate == null) ? null : svm.DueDate) })); //return _Create(svm.PurchaseIndentHeaderId, ((svm.DueDate == null) ? null : svm.DueDate)); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseIndentLine templine = _PurchaseIndentLineService.Find(s.PurchaseIndentLineId); int Status = temp.Status; PurchaseIndentLine ExRec = new PurchaseIndentLine(); ExRec = Mapper.Map <PurchaseIndentLine>(templine); templine.DueDate = s.DueDate; templine.ProductId = s.ProductId; templine.Qty = s.Qty; templine.Remark = s.Remark; templine.Dimension1Id = s.Dimension1Id; templine.Dimension2Id = s.Dimension2Id; templine.Specification = s.Specification; templine.ModifiedDate = DateTime.Now; templine.ModifiedBy = User.Identity.Name; //_PurchaseIndentLineService.Update(templine); templine.ObjectState = Model.ObjectState.Modified; db.PurchaseIndentLine.Add(templine); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = templine, }); if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; //new PurchaseIndentHeaderService(_unitOfWork).Update(temp); temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; db.PurchaseIndentHeader.Add(temp); } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { PurchaseIndentDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, templine.PurchaseIndentLineId, EventModeConstants.Edit), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; EventException = true; } try { if (EventException) { throw new Exception(); } db.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Create", svm)); } try { PurchaseIndentDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, templine.PurchaseIndentLineId, 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 = templine.PurchaseIndentHeaderId, DocLineId = templine.PurchaseIndentLineId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(Json(new { success = true })); } } return(PartialView("_Create", svm)); }
public ActionResult Reviewed(int Id, string IndexType, string UserRemark, string IsContinue) { bool BeforeSave = true; try { BeforeSave = PurchaseIndentDocEvents.beforeHeaderReviewEvent(this, new PurchaseEventArgs(Id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Falied validation before submit."; } PurchaseIndentHeader pd = new PurchaseIndentHeaderService(_unitOfWork).Find(Id); if (ModelState.IsValid && BeforeSave && !EventException) { pd.ReviewCount = (pd.ReviewCount ?? 0) + 1; pd.ReviewBy += User.Identity.Name + ", "; pd.ObjectState = Model.ObjectState.Modified; context.PurchaseIndentHeader.Add(pd); try { PurchaseIndentDocEvents.onHeaderReviewEvent(this, new PurchaseEventArgs(Id), 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; return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType })); } try { PurchaseIndentDocEvents.afterHeaderReviewEvent(this, new PurchaseEventArgs(Id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.PurchaseIndentHeaderId, ActivityType = (int)ActivityTypeContants.Reviewed, UserRemark = UserRemark, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); NotifyUser(Id, ActivityTypeContants.Reviewed); if (!string.IsNullOrEmpty(IsContinue) && IsContinue == "True") { PurchaseIndentHeader HEader = _PurchaseIndentHeaderService.Find(Id); int nextId = new NextPrevIdService(_unitOfWork).GetNextPrevId(Id, HEader.DocTypeId, User.Identity.Name, ForActionConstants.PendingToReview, "Web.PurchaseIndentHeaders", "PurchaseIndentHeaderId", PrevNextConstants.Next); if (nextId == 0) { var PendingtoSubmitCount = _PurchaseIndentHeaderService.GetPurchaseIndentPendingToReview(HEader.DocTypeId, User.Identity.Name).Count(); if (PendingtoSubmitCount > 0) { return(RedirectToAction("Index_PendingToReview", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully")); } else { return(RedirectToAction("Index", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully")); } } ViewBag.PendingToReview = PendingToReviewCount(Id); return(RedirectToAction("Detail", new { id = nextId, transactionType = "ReviewContinue", IndexType = IndexType })); } else { return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully")); } } return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType })); }
public ActionResult Submitted(int Id, string IndexType, string UserRemark, string IsContinue) { bool BeforeSave = true; try { BeforeSave = PurchaseIndentDocEvents.beforeHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Falied validation before submit."; } PurchaseIndentHeader pd = new PurchaseIndentHeaderService(_unitOfWork).Find(Id); if (ModelState.IsValid && BeforeSave && !EventException) { int ActivityType; if (User.Identity.Name == pd.ModifiedBy || UserRoles.Contains("Admin")) { pd.ReviewBy = null; pd.Status = (int)StatusConstants.Submitted; ActivityType = (int)ActivityTypeContants.Submitted; //_PurchaseIndentHeaderService.Update(pd); pd.ObjectState = Model.ObjectState.Modified; context.PurchaseIndentHeader.Add(pd); try { PurchaseIndentDocEvents.onHeaderSubmitEvent(this, new PurchaseEventArgs(Id), 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; return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType })); } try { PurchaseIndentDocEvents.afterHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = pd.DocTypeId, DocId = pd.PurchaseIndentHeaderId, ActivityType = ActivityType, UserRemark = UserRemark, DocNo = pd.DocNo, DocDate = pd.DocDate, DocStatus = pd.Status, })); NotifyUser(Id, ActivityTypeContants.Submitted); if (!string.IsNullOrEmpty(IsContinue) && IsContinue == "True") { int nextId = new NextPrevIdService(_unitOfWork).GetNextPrevId(Id, pd.DocTypeId, User.Identity.Name, ForActionConstants.PendingToSubmit, "Web.PurchaseIndentHeaders", "PurchaseIndentHeaderId", PrevNextConstants.Next); if (nextId == 0) { var PendingtoSubmitCount = _PurchaseIndentHeaderService.GetPurchaseIndentPendingToSubmit(pd.DocTypeId, User.Identity.Name).Count(); if (PendingtoSubmitCount > 0) { return(RedirectToAction("Index_PendingToSubmit", new { id = pd.DocTypeId }).Success("Record Submitted Successfully")); } else { return(RedirectToAction("Index", new { id = pd.DocTypeId }).Success("Record Submitted Successfully")); } } return(RedirectToAction("Detail", new { id = nextId, TransactionType = "submitContinue" }).Success("Purchase Indent " + pd.DocNo + " submitted successfully.")); } else { return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Record Submitted Successfully")); } } else { return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Warning("Record can be submitted by user " + pd.ModifiedBy + " only.")); } } return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType })); }
public ActionResult Delete(ReasonViewModel vm) { bool BeforeSave = true; try { BeforeSave = PurchaseIndentDocEvents.beforeHeaderDeleteEvent(this, new PurchaseEventArgs(vm.id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } if (!BeforeSave) { TempData["CSEXC"] += "Failed validation before delete"; } if (ModelState.IsValid && BeforeSave && !EventException) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); //first find the Purchase Order Object based on the ID. (sience this object need to marked to be deleted IE. ObjectState.Deleted) var PurchaseIndentHeader = context.PurchaseIndentHeader.Find(vm.id); try { PurchaseIndentDocEvents.onHeaderDeleteEvent(this, new PurchaseEventArgs(vm.id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; EventException = true; } LogList.Add(new LogTypeViewModel { ExObj = Mapper.Map <PurchaseIndentHeader>(PurchaseIndentHeader), }); //Then find all the Purchase Order Header Line associated with the above ProductType. var PurchaseIndentLine = (from p in context.PurchaseIndentLine where p.PurchaseIndentHeaderId == vm.id select p).ToList(); //Mark ObjectState.Delete to all the Purchase Order Lines. foreach (var item in PurchaseIndentLine) { LogList.Add(new LogTypeViewModel { ExObj = Mapper.Map <PurchaseIndentLine>(item), }); item.ObjectState = Model.ObjectState.Deleted; context.PurchaseIndentLine.Remove(item); //new PurchaseIndentLineService(_unitOfWork).Delete(item.PurchaseIndentLineId); } // Now delete the Purhcase Order Header //new PurchaseIndentHeaderService(_unitOfWork).Delete(PurchaseIndentHeader); PurchaseIndentHeader.ObjectState = Model.ObjectState.Deleted; context.PurchaseIndentHeader.Remove(PurchaseIndentHeader); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); //Commit the DB try { if (EventException) { throw new Exception(); } context.SaveChanges(); //_unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; return(PartialView("_Reason", vm)); } try { PurchaseIndentDocEvents.afterHeaderDeleteEvent(this, new PurchaseEventArgs(vm.id), ref context); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = PurchaseIndentHeader.DocTypeId, DocId = PurchaseIndentHeader.PurchaseIndentHeaderId, ActivityType = (int)ActivityTypeContants.Deleted, UserRemark = vm.Reason, DocNo = PurchaseIndentHeader.DocNo, xEModifications = Modifications, DocDate = PurchaseIndentHeader.DocDate, DocStatus = PurchaseIndentHeader.Status, })); return(Json(new { success = true })); } return(PartialView("_Reason", vm)); }
public ActionResult Post(PurchaseIndentHeaderViewModel svm) { PurchaseIndentHeader s = Mapper.Map <PurchaseIndentHeaderViewModel, PurchaseIndentHeader>(svm); #region BeforeSave bool BeforeSave = true; try { if (svm.PurchaseIndentHeaderId <= 0) { BeforeSave = PurchaseIndentDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentHeaderId, EventModeConstants.Add), ref context); } else { BeforeSave = PurchaseIndentDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentHeaderId, 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.PurchaseIndentHeaderId <= 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.PurchaseIndentHeaderId <= 0) { s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.Status = (int)StatusConstants.Drafted; //_PurchaseIndentHeaderService.Create(s); s.ObjectState = Model.ObjectState.Added; context.PurchaseIndentHeader.Add(s); try { PurchaseIndentDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, 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 { PurchaseIndentDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentHeaderId, 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.PurchaseIndentHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = s.DocNo, DocDate = s.DocDate, DocStatus = s.Status, })); //return Edit(s.PurchaseIndentHeaderId).Success("Saved Sucessfully"); return(RedirectToAction("Modify", new { id = s.PurchaseIndentHeaderId }).Success("Data saved Successfully")); } #endregion #region EditRecord else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); PurchaseIndentHeader temp = _PurchaseIndentHeaderService.Find(s.PurchaseIndentHeaderId); PurchaseIndentHeader ExRec = new PurchaseIndentHeader(); ExRec = Mapper.Map <PurchaseIndentHeader>(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.Remark = s.Remark; temp.ModifiedDate = DateTime.Now; temp.ReasonId = s.ReasonId; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; context.PurchaseIndentHeader.Add(temp); //_PurchaseIndentHeaderService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { PurchaseIndentDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseIndentHeaderId, 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.Mode = "Edit"; return(View("Create", svm)); } try { PurchaseIndentDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseIndentHeaderId, 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.PurchaseIndentHeaderId, 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)); }