public ActionResult DeletePost(QAGroupLineViewModel vm) { bool BeforeSave = true; //try //{ // BeforeSave = JobOrderDocEvents.beforeLineDeleteEvent(this, new JobEventArgs(vm.QAGroupId, vm.QAGroupLineId), 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>(); QAGroupLine QAGroupLine = (from p in db.QAGroupLine where p.QAGroupLineId == vm.QAGroupLineId select p).FirstOrDefault(); QAGroup header = (from p in db.QAGroup where p.QAGroupId == QAGroupLine.QAGroupId select p).FirstOrDefault(); LogList.Add(new LogTypeViewModel { Obj = Mapper.Map <QAGroupLine>(QAGroupLine), }); //_JobOrderLineService.Delete(JobOrderLine); QAGroupLine.ObjectState = Model.ObjectState.Deleted; db.QAGroupLine.Remove(QAGroupLine); 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.QAGroup.Add(header); } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); 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 { JobOrderDocEvents.afterLineDeleteEvent(this, new JobEventArgs(QAGroupLine.QAGroupId, QAGroupLine.QAGroupLineId), 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.QAGroupId, DocLineId = QAGroupLine.QAGroupLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.QaGroupName, xEModifications = Modifications, DocDate = header.CreatedDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
public ActionResult _CreatePost(QAGroupLineViewModel svm) { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); bool BeforeSave = true; QAGroup temp = new QAGroupService(_unitOfWork).Find(svm.QAGroupId); int i = 0; if (temp.QAGroupId <= 0) { i = _QAGroupLineService.GetQAGroupLineListForIndex(svm.QAGroupId).Where(x => x.Name == svm.Name).ToList().Count(); } else { i = _QAGroupLineService.GetQAGroupLineListForIndex(svm.QAGroupId).Where(x => x.Name == svm.Name && x.QAGroupLineId != svm.QAGroupLineId).ToList().Count(); } #region BeforeSave //try //{ // if (svm.GatePassLineId <= 0) // BeforeSave = JobOrderDocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.GatePassHeaderId, EventModeConstants.Add), ref db); // else // BeforeSave = JobOrderDocEvents.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.Name == "" || svm.Name == null) { ModelState.AddModelError("Name", "The Name is required"); } if (i != 0) { ModelState.AddModelError("Name", svm.Name + " already exist"); } QAGroupLine s = Mapper.Map <QAGroupLineViewModel, QAGroupLine>(svm); ViewBag.Status = temp.Status; if (svm.QAGroupLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (ModelState.IsValid && BeforeSave && !EventException) { if (svm.QAGroupLineId <= 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.QAGroupLine.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.QAGroup.Add(temp); //try //{ // JobOrderDocEvents.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)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = temp.DocTypeId, DocId = temp.QAGroupId, DocLineId = s.QAGroupLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.QaGroupName, DocDate = temp.CreatedDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = svm.QAGroupId, IsProdBased = false })); //return RedirectToAction("_Create", new { id = svm.GatePassHeaderId, IsProdBased = (s.ProdOrderLineId == null ? false : true) }); } else { QAGroupLine templine = (from p in db.QAGroupLine where p.QAGroupLineId == s.QAGroupLineId select p).FirstOrDefault(); QAGroupLine ExTempLine = new QAGroupLine(); ExTempLine = Mapper.Map <QAGroupLine>(templine); templine.QAGroupId = s.QAGroupId; /*templine.Name = s.Name; * templine.IsMandatory = s.IsMandatory; * templine.DataType = s.DataType; * templine.ListItem = s.ListItem; * templine.DefaultValue = s.DefaultValue; * templine.IsActive = s.IsActive;*/ templine.ModifiedDate = DateTime.Now; templine.ModifiedBy = User.Identity.Name; templine.ObjectState = Model.ObjectState.Modified; db.QAGroupLine.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.QAGroup.Add(temp); LogList.Add(new LogTypeViewModel { ExObj = ExTempLine, Obj = templine }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); 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 { JobOrderDocEvents.afterLineSaveEvent(this, new JobEventArgs(s.QAGroupId, templine.QAGroupLineId, 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.QAGroupId, DocLineId = templine.QAGroupLineId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.QaGroupName, xEModifications = Modifications, DocDate = temp.CreatedDate, DocStatus = temp.Status, })); //End of Saving the Activity Log return(Json(new { success = true })); } } PrepareViewBag(svm); return(PartialView("_Create", svm)); }
public QAGroupLine Add(QAGroupLine pt) { _unitOfWork.Repository <QAGroupLine>().Insert(pt); return(pt); }
public void Update(QAGroupLine pt) { pt.ObjectState = ObjectState.Modified; _unitOfWork.Repository <QAGroupLine>().Update(pt); }
public void Delete(QAGroupLine pt) { _unitOfWork.Repository <QAGroupLine>().Delete(pt); }
public QAGroupLine Create(QAGroupLine pt) { pt.ObjectState = ObjectState.Added; _unitOfWork.Repository <QAGroupLine>().Insert(pt); return(pt); }