public ActionResult _Detail(int id) { RequisitionCancelLineViewModel temp = _RequisitionCancelLineService.GetRequisitionCancelLine(id); RequisitionCancelHeader header = new RequisitionCancelHeaderService(_unitOfWork).Find(temp.RequisitionCancelHeaderId); //Getting Settings var settings = new RequisitionSettingService(_unitOfWork).GetRequisitionSettingForDocument(header.DocTypeId, header.DivisionId, header.SiteId); temp.RequisitionSettings = Mapper.Map <RequisitionSetting, RequisitionSettingsViewModel>(settings); if (temp == null) { return(HttpNotFound()); } return(PartialView("_Create", temp)); }
private ActionResult _Delete(int id) { RequisitionCancelLineViewModel temp = _RequisitionCancelLineService.GetRequisitionCancelLine(id); if (temp == null) { return(HttpNotFound()); } #region DocTypeTimeLineValidation try { TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId { LockReason = temp.LockReason }, User.Identity.Name, out ExceptionMsg, out Continue); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; TimePlanValidation = false; } if (!TimePlanValidation) { TempData["CSEXCL"] += ExceptionMsg; } #endregion if ((TimePlanValidation || Continue)) { ViewBag.LineMode = "Delete"; } RequisitionCancelHeader header = new RequisitionCancelHeaderService(_unitOfWork).Find(temp.RequisitionCancelHeaderId); //Getting Settings var settings = new RequisitionSettingService(_unitOfWork).GetRequisitionSettingForDocument(header.DocTypeId, header.DivisionId, header.SiteId); temp.RequisitionSettings = Mapper.Map <RequisitionSetting, RequisitionSettingsViewModel>(settings); return(PartialView("_Create", temp)); }
public ActionResult _Create(int Id, int sid) //Id ==>Sale Order Header Id { RequisitionCancelHeader header = new RequisitionCancelHeaderService(_unitOfWork).Find(Id); RequisitionCancelLineViewModel svm = new RequisitionCancelLineViewModel(); //Getting Settings var settings = new RequisitionSettingService(_unitOfWork).GetRequisitionSettingForDocument(header.DocTypeId, header.DivisionId, header.SiteId); svm.RequisitionSettings = Mapper.Map <RequisitionSetting, RequisitionSettingsViewModel>(settings); svm.RequisitionCancelHeaderId = Id; svm.PersonId = sid; if (!string.IsNullOrEmpty((string)TempData["CSEXCL"])) { ViewBag.CSEXCL = TempData["CSEXCL"]; TempData["CSEXCL"] = null; } ViewBag.LineMode = "Create"; return(PartialView("_Create", svm)); }
public ActionResult DeletePost(RequisitionCancelLineViewModel vm) { bool BeforeSave = true; try { BeforeSave = MaterialRequestCancelDocEvents.beforeLineDeleteEvent(this, new StockEventArgs(vm.RequisitionCancelHeaderId, vm.RequisitionCancelLineId), 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>(); RequisitionCancelLine RequisitionLine = (from p in db.RequisitionCancelLine where p.RequisitionCancelLineId == vm.RequisitionCancelLineId select p).FirstOrDefault(); //RequisitionCancelLine RequisitionLine = _RequisitionCancelLineService.Find(vm.RequisitionCancelLineId); RequisitionCancelHeader header = new RequisitionCancelHeaderService(_unitOfWork).Find(RequisitionLine.RequisitionCancelHeaderId); RequisitionCancelLine ExRec = new RequisitionCancelLine(); ExRec = Mapper.Map <RequisitionCancelLine>(RequisitionLine); LogList.Add(new LogTypeViewModel { ExObj = ExRec, }); new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnCancel(RequisitionLine.RequisitionLineId, RequisitionLine.RequisitionCancelLineId, header.DocDate, 0, ref db, true); RequisitionLine.ObjectState = Model.ObjectState.Deleted; db.RequisitionCancelLine.Remove(RequisitionLine); 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.RequisitionCancelHeader.Add(header); } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { MaterialRequestCancelDocEvents.onLineDeleteEvent(this, new StockEventArgs(RequisitionLine.RequisitionCancelHeaderId, RequisitionLine.RequisitionCancelLineId), 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; return(PartialView("_Create", vm)); } try { MaterialRequestCancelDocEvents.afterLineDeleteEvent(this, new StockEventArgs(RequisitionLine.RequisitionCancelHeaderId, RequisitionLine.RequisitionCancelLineId), ref db); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXC"] += message; } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = header.DocTypeId, DocId = header.RequisitionCancelHeaderId, DocLineId = RequisitionLine.RequisitionCancelLineId, ActivityType = (int)ActivityTypeContants.Deleted, DocNo = header.DocNo, xEModifications = Modifications, DocDate = header.DocDate, DocStatus = header.Status, })); } return(Json(new { success = true })); }
public ActionResult _CreatePost(RequisitionCancelLineViewModel svm) { bool BeforeSave = true; try { if (svm.RequisitionLineId <= 0) { BeforeSave = MaterialRequestCancelDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.RequisitionCancelHeaderId, EventModeConstants.Add), ref db); } else { BeforeSave = MaterialRequestCancelDocEvents.beforeLineSaveEvent(this, new StockEventArgs(svm.RequisitionCancelHeaderId, 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 (svm.RequisitionCancelLineId <= 0) { ViewBag.LineMode = "Create"; } else { ViewBag.LineMode = "Edit"; } if (svm.RequisitionCancelLineId <= 0) { RequisitionCancelHeader temp = new RequisitionCancelHeaderService(_unitOfWork).Find(svm.RequisitionCancelHeaderId); RequisitionCancelLine s = new RequisitionCancelLine(); decimal balqty = (from p in db.ViewRequisitionBalance where p.RequisitionLineId == svm.RequisitionLineId select p.BalanceQty).FirstOrDefault(); if (balqty < svm.Qty) { ModelState.AddModelError("Qty", "Qty Exceeding Balance Qty"); } if (svm.Qty == 0) { ModelState.AddModelError("Qty", "Please Check Qty"); } if (ModelState.IsValid && BeforeSave && !EventException) { s.Remark = svm.Remark; s.RequisitionCancelHeaderId = svm.RequisitionCancelHeaderId; s.RequisitionLineId = svm.RequisitionLineId; s.Qty = svm.Qty; s.CreatedDate = DateTime.Now; s.ModifiedDate = DateTime.Now; s.CreatedBy = User.Identity.Name; s.ModifiedBy = User.Identity.Name; s.ObjectState = Model.ObjectState.Added; db.RequisitionCancelLine.Add(s); //_RequisitionCancelLineService.Create(s); new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnCancel(s.RequisitionLineId, s.RequisitionCancelLineId, temp.DocDate, s.Qty, ref db, true); if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import) { temp.Status = (int)StatusConstants.Modified; temp.ModifiedBy = User.Identity.Name; temp.ModifiedDate = DateTime.Now; temp.ObjectState = Model.ObjectState.Modified; db.RequisitionCancelHeader.Add(temp); } try { MaterialRequestCancelDocEvents.onLineSaveEvent(this, new StockEventArgs(s.RequisitionCancelHeaderId, s.RequisitionLineId, 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; return(PartialView("_Create", svm)); } try { MaterialRequestCancelDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionCancelHeaderId, s.RequisitionLineId, 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.RequisitionCancelHeaderId, DocLineId = s.RequisitionCancelLineId, ActivityType = (int)ActivityTypeContants.Added, DocNo = temp.DocNo, DocDate = temp.DocDate, DocStatus = temp.Status, })); return(RedirectToAction("_Create", new { id = s.RequisitionCancelHeaderId, sid = svm.PersonId })); } return(PartialView("_Create", svm)); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); RequisitionCancelHeader temp = new RequisitionCancelHeaderService(_unitOfWork).Find(svm.RequisitionCancelHeaderId); int status = temp.Status; StringBuilder logstring = new StringBuilder(); RequisitionCancelLine s = _RequisitionCancelLineService.Find(svm.RequisitionCancelLineId); RequisitionCancelLine ExRec = new RequisitionCancelLine(); ExRec = Mapper.Map <RequisitionCancelLine>(s); decimal balqty = (from p in db.ViewRequisitionBalance where p.RequisitionLineId == svm.RequisitionLineId select p.BalanceQty).FirstOrDefault(); if (balqty + s.Qty < svm.Qty) { ModelState.AddModelError("Qty", "Qty Exceeding Balance Qty"); } if (ModelState.IsValid && BeforeSave) { if (svm.Qty > 0) { s.Remark = svm.Remark; s.Qty = svm.Qty; s.ModifiedBy = User.Identity.Name; s.ModifiedDate = DateTime.Now; new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnCancel(s.RequisitionLineId, s.RequisitionCancelLineId, temp.DocDate, s.Qty, ref db, true); } //_RequisitionCancelLineService.Update(s); s.ObjectState = Model.ObjectState.Modified; db.RequisitionCancelLine.Add(s); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = s, }); if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; temp.ObjectState = Model.ObjectState.Modified; db.RequisitionCancelHeader.Add(temp); //new RequisitionCancelHeaderService(_unitOfWork).Update(temp); } XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { MaterialRequestCancelDocEvents.onLineSaveEvent(this, new StockEventArgs(s.RequisitionCancelHeaderId, s.RequisitionCancelLineId, 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(); } catch (Exception ex) { string message = _exception.HandleException(ex); TempData["CSEXCL"] += message; return(PartialView("_Create", svm)); } try { MaterialRequestCancelDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionCancelHeaderId, s.RequisitionCancelLineId, 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 = temp.RequisitionCancelHeaderId, DocLineId = s.RequisitionCancelLineId, ActivityType = (int)ActivityTypeContants.Modified, DocNo = temp.DocNo, xEModifications = Modifications, DocDate = temp.DocDate, DocStatus = temp.Status, })); //End Of Saving Activity Log return(Json(new { success = true })); } return(PartialView("_Create", svm)); } }