public ActionResult DeletePost(GatePassLineViewModel vm) { bool BeforeSave = true; try { BeforeSave = GatePassDocEvents.beforeLineDeleteEvent(this, new JobEventArgs(vm.GatePassHeaderId, vm.GatePassLineId), 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) { int?StockId = 0; int?StockProcessId = 0; List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); GatePassLine GatePassLine = (from p in db.GatePassLine where p.GatePassLineId == vm.GatePassLineId select p).FirstOrDefault(); GatePassHeader header = (from p in db.GatePassHeader where p.GatePassHeaderId == GatePassLine.GatePassHeaderId select p).FirstOrDefault(); LogList.Add(new LogTypeViewModel { Obj = Mapper.Map <GatePassLine>(GatePassLine), }); //_GatePassLineService.Delete(GatePassLine); GatePassLine.ObjectState = Model.ObjectState.Deleted; db.GatePassLine.Remove(GatePassLine); if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import) { header.Status = (int)StatusConstants.Modified; header.ModifiedDate = DateTime.Now; header.ModifiedBy = User.Identity.Name; db.GatePassHeader.Add(header); } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); //try //{ // GatePassDocEvents.onLineDeleteEvent(this, new JobEventArgs(GatePassLine.GatePassHeaderId, GatePassLine.GatePassLineId), ref db); //} //catch (Exception ex) //{ // string message = _exception.HandleException(ex); // TempData["CSEXCL"] += message; // EventException = true; //} try { if (EventException) { throw new Exception(); } db.SaveChanges(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; PrepareViewBag(vm); ViewBag.LineMode = "Delete"; return(PartialView("_Create", vm)); } try { GatePassDocEvents.afterLineDeleteEvent(this, new JobEventArgs(GatePassLine.GatePassHeaderId, GatePassLine.GatePassLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } //Saving the Activity Log LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.GatePassHeaderId, DocLineId = GatePassLine.GatePassLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
public ActionResult _CreatePost(GatePassLineViewModel svm) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); bool BeforeSave = true; GatePassHeader temp = new GatePassHeaderService(_unitOfWork).Find(svm.GatePassHeaderId); var PD = _GatePassLineService.GetGatePassLineListForIndex(svm.GatePassHeaderId).Where(x => x.Product == svm.Product && x.Specification == svm.Specification).ToList(); #region BeforeSave //try //{ // if (svm.GatePassLineId <= 0) // BeforeSave = GatePassDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.GatePassHeaderId, EventModeConstants.Add), ref db); // else // BeforeSave = GatePassDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.GatePassHeaderId, 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."); #endregion if (svm.Product == "" || svm.Product == null) { ModelState.AddModelError("Product", "The Product is required"); } if (svm.Qty <= 0) { ModelState.AddModelError("UnitId", "The Qty is required"); } if (svm.UnitId == "" || svm.UnitId == null) { ModelState.AddModelError("UnitId", "The Unit Name is required"); } if (PD.ToList().Count() != 0) { ModelState.AddModelError("Product", svm.Product + " " + svm.Specification + " already exist"); } GatePassLine s = Mapper.Map <GatePassLineViewModel, GatePassLine>(svm); ViewBag.Status = temp.Status; if (svm.GatePassLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.GatePassLineId <= 0) { //Posting in Stock s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; db.GatePassLine.Add(s); if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; } temp.ObjectState = Model.ObjectState.Modified; db.GatePassHeader.Add(temp); //try //{ // GatePassDocEvents.onLineSaveEvent(this, new JobEventArgs(s.GatePassHeaderId, s.GatePassLineId, 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(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; PrepareViewBag(svm); return(PartialView("_Create", svm)); } //try //{ // GatePassDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.GatePassHeaderId, s.GatePassHeaderId, 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.GatePassHeaderId, DocLineId = s.GatePassLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = svm.GatePassHeaderId, IsProdBased = false })); //return RedirectToAction("_Create", new { id = svm.GatePassHeaderId, IsProdBased = (s.ProdOrderLineId == null ? false : true) }); } else { GatePassLine templine = (from p in db.GatePassLine where p.GatePassLineId == s.GatePassLineId select p).FirstOrDefault(); GatePassLine ExTempLine = new GatePassLine(); ExTempLine = Mapper.Map <GatePassLine>(templine); templine.GatePassHeaderId = s.GatePassHeaderId; templine.Product = s.Product; templine.Specification = s.Specification; templine.Qty = s.Qty; templine.UnitId = s.UnitId; templine.ModifiedDate = DateTime.Now; templine.ModifiedBy = User.Identity.Name; templine.ObjectState = Model.ObjectState.Modified; db.GatePassLine.Add(templine); int Status = 0; if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { Status = temp.Status; temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; } temp.ObjectState = Model.ObjectState.Modified; db.GatePassHeader.Add(temp); LogList.Add(new LogTypeViewModel { ExObj = ExTempLine, Obj = templine }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); //try //{ // GatePassDocEvents.onLineSaveEvent(this, new JobEventArgs(s.GatePassHeaderId, templine.GatePassLineId, 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(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; PrepareViewBag(svm); return(PartialView("_Create", svm)); } try { GatePassDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.GatePassHeaderId, templine.GatePassLineId, EventModeConstants.Edit), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } //Saving the Activity Log LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = templine.GatePassHeaderId, DocLineId = templine.GatePassLineId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); //End of Saving the Activity Log return(Json(new { success = true })); } } PrepareViewBag(svm); return(PartialView("_Create", svm)); }
public GatePassLine Add(GatePassLine pt) { _unitOfWork.Repository <GatePassLine>().Insert(pt); return(pt); }
public void Update(GatePassLine pt) { pt.ObjectState = ObjectState.Modified; _unitOfWork.Repository <GatePassLine>().Update(pt); }
public void Delete(GatePassLine pt) { _unitOfWork.Repository <GatePassLine>().Delete(pt); }
public GatePassLine Create(GatePassLine pt) { pt.ObjectState = ObjectState.Added; _unitOfWork.Repository <GatePassLine>().Insert(pt); return(pt); }