public ActionResult RateListWizard(int id) { RateListHeader Header = _RateListHeaderService.Find(id); if (Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Modified) { db = new ApplicationDbContext(); var RateListForWizard = (from p in db.RateListHeader where p.RateListHeaderId == id select new RateListHeaderViewModel { EffectiveDate = p.EffectiveDate, RateListName = p.RateListName, CalculateWeightageOn = p.CalculateWeightageOn, DealUnitName = p.DealUnit.UnitName, RateListHeaderId = p.RateListHeaderId, }).FirstOrDefault(); return(View(RateListForWizard)); } else { return(RedirectToAction("Index").Danger("Please Submit the record")); } }
public ActionResult Approved(int Id, string returl) { if (ModelState.IsValid) { RateListHeader pd = _RateListHeaderService.Find(Id); pd.Status = (int)StatusConstants.Approved; pd.ObjectState = Model.ObjectState.Modified; db.RateListHeader.Add(pd); db.SaveChanges(); LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.RateListHeader).DocumentTypeId, DocId = pd.RateListHeaderId, ActivityType = (int)ActivityTypeContants.Approved, DocNo = pd.RateListName, })); return(RedirectToAction("Index")); } return(View()); }
// GET: /ProductMaster/Delete/5 public ActionResult Delete(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RateListHeader RateListHeader = _RateListHeaderService.Find(id); if (RateListHeader == null) { return(HttpNotFound()); } ReasonViewModel vm = new ReasonViewModel() { id = id, }; return(PartialView("_Reason", vm)); }
public ActionResult Post(RateListHeaderViewModel vm) { RateListHeader pt = Mapper.Map <RateListHeaderViewModel, RateListHeader>(vm); if (vm.RateListHeaderId <= 0) { ViewBag.Mode = "Add"; } else { ViewBag.Mode = "Edit"; } if (vm.ProcessId <= 0) { ModelState.AddModelError("ProcessId", "The Process field is required."); } if (ModelState.IsValid) { if (vm.RateListHeaderId <= 0) { int SiteId = (int)System.Web.HttpContext.Current.Session["SiteId"]; int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"]; pt.SiteId = SiteId; pt.DivisionId = DivisionId; pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _RateListHeaderService.Create(pt); if (!string.IsNullOrEmpty(vm.PersonRateGroup)) { foreach (string item in vm.PersonRateGroup.Split(',').ToList()) { RateListPersonRateGroup PRG = new RateListPersonRateGroup(); PRG.RateListHeaderId = pt.RateListHeaderId; PRG.PersonRateGroupId = Int32.Parse(item); PRG.CreatedDate = DateTime.Now; PRG.ModifiedDate = DateTime.Now; PRG.CreatedBy = User.Identity.Name; PRG.ModifiedBy = User.Identity.Name; _RateListPersonRateGroupService.Create(PRG); } } if (!string.IsNullOrEmpty(vm.ProductRateGroup)) { foreach (string item in vm.ProductRateGroup.Split(',').ToList()) { RateListProductRateGroup PRRG = new RateListProductRateGroup(); PRRG.RateListHeaderId = pt.RateListHeaderId; PRRG.ProductRateGroupId = Int32.Parse(item); PRRG.CreatedDate = DateTime.Now; PRRG.ModifiedDate = DateTime.Now; PRRG.CreatedBy = User.Identity.Name; PRRG.ModifiedBy = User.Identity.Name; _RateListProductRateGroupService.Create(PRRG); } } try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); PrepareViewBag(); return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.RateListHeader).DocumentTypeId, DocId = pt.RateListHeaderId, ActivityType = (int)ActivityTypeContants.Added, DocNo = pt.RateListName, })); return(RedirectToAction("Create").Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); RateListHeader temp = _RateListHeaderService.Find(pt.RateListHeaderId); RateListHeader ExRec = Mapper.Map <RateListHeader>(temp); temp.RateListName = pt.RateListName; temp.CalculateWeightageOn = pt.CalculateWeightageOn; temp.DealUnitId = pt.DealUnitId; temp.Description = pt.Description; temp.EffectiveDate = pt.EffectiveDate; temp.MaxRate = pt.MaxRate; temp.MinRate = pt.MinRate; temp.ProcessId = pt.ProcessId; temp.WeightageGreaterOrEqual = pt.WeightageGreaterOrEqual; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; if (temp.Status != (int)StatusConstants.Drafted) { temp.Status = (int)StatusConstants.Modified; } _RateListHeaderService.Update(temp); var RateListPersoRateGroup = _RateListPersonRateGroupService.GetRateListPersonRateGroupList(temp.RateListHeaderId); foreach (var item in RateListPersoRateGroup) { _RateListPersonRateGroupService.Delete(item); } var RateListProduRateGroup = _RateListProductRateGroupService.GetRateListProductRateGroupList(temp.RateListHeaderId); foreach (var item in RateListProduRateGroup) { _RateListProductRateGroupService.Delete(item); } if (!string.IsNullOrEmpty(vm.PersonRateGroup)) { foreach (string item in vm.PersonRateGroup.Split(',').ToList()) { RateListPersonRateGroup PRG = new RateListPersonRateGroup(); PRG.RateListHeaderId = pt.RateListHeaderId; PRG.PersonRateGroupId = Int32.Parse(item); PRG.CreatedDate = DateTime.Now; PRG.ModifiedDate = DateTime.Now; PRG.CreatedBy = User.Identity.Name; PRG.ModifiedBy = User.Identity.Name; _RateListPersonRateGroupService.Create(PRG); } } if (!string.IsNullOrEmpty(vm.ProductRateGroup)) { foreach (string item in vm.ProductRateGroup.Split(',').ToList()) { RateListProductRateGroup PRRG = new RateListProductRateGroup(); PRRG.RateListHeaderId = pt.RateListHeaderId; PRRG.ProductRateGroupId = Int32.Parse(item); PRRG.CreatedDate = DateTime.Now; PRRG.ModifiedDate = DateTime.Now; PRRG.CreatedBy = User.Identity.Name; PRRG.ModifiedBy = User.Identity.Name; _RateListProductRateGroupService.Create(PRRG); } } LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); PrepareViewBag(); return(View("Create", vm)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.RateListHeader).DocumentTypeId, DocId = temp.RateListHeaderId, ActivityType = (int)ActivityTypeContants.Modified, xEModifications = Modifications, DocNo = temp.RateListName, })); return(RedirectToAction("Index").Success("Data saved successfully")); } } PrepareViewBag(); return(View("Create", vm)); }
public ActionResult Submitted(int Id, string returl, string UserRemark) { if (ModelState.IsValid) { RateListHeader Header = _RateListHeaderService.Find(Id); int ActivityType; var Cartesian = (from p in db.RateListHeader join t in db.RateListPersonRateGroup on p.RateListHeaderId equals t.RateListHeaderId into table from tab in table.DefaultIfEmpty() join t1 in db.RateListProductRateGroup on p.RateListHeaderId equals t1.RateListHeaderId into table2 from tab2 in table2.DefaultIfEmpty() where p.RateListHeaderId == Id select new { RateListHId = p.RateListHeaderId, ProdRateGroupId = (int?)tab2.ProductRateGroupId, PerRateGroupId = (int?)tab.PersonRateGroupId, }).ToList(); var ExistingRateList = (from p in db.RateListLine where p.RateListHeaderId == Id select p).ToList(); var PedingToUpdate = (from p in Cartesian join t in ExistingRateList on new { x = p.RateListHId, y = p.ProdRateGroupId, z = p.PerRateGroupId } equals new { x = t.RateListHeaderId, y = t.ProductRateGroupId, z = t.PersonRateGroupId } into g from tab in g.DefaultIfEmpty() where tab == null select p).ToList(); var PendingToDelete = (from p in ExistingRateList join t in Cartesian on new { x = p.RateListHeaderId, y = p.ProductRateGroupId, z = p.PersonRateGroupId } equals new { x = t.RateListHId, y = t.ProdRateGroupId, z = t.PerRateGroupId } into g from tab in g.DefaultIfEmpty() where tab == null && p.ProductId == null select p ).ToList(); foreach (var item in PedingToUpdate) { RateListLine Line = new RateListLine(); Line.RateListHeaderId = item.RateListHId; Line.PersonRateGroupId = item.PerRateGroupId; Line.ProductRateGroupId = item.ProdRateGroupId; Line.CreatedBy = User.Identity.Name; Line.CreatedDate = DateTime.Now; Line.ModifiedBy = User.Identity.Name; Line.ModifiedDate = DateTime.Now; Line.ObjectState = Model.ObjectState.Added; db.RateListLine.Add(Line); } foreach (var item in PendingToDelete) { item.ObjectState = Model.ObjectState.Deleted; db.RateListLine.Remove(item); } Header.Status = (int)StatusConstants.Submitted; ActivityType = (int)ActivityTypeContants.Submitted; //_StockHeaderService.Update(StokHeader); Header.ObjectState = Model.ObjectState.Modified; db.RateListHeader.Add(Header); try { db.SaveChanges(); db.Dispose(); } catch (Exception Ex) { string message = _exception.HandleException(Ex); ModelState.AddModelError("", message); return(RedirectToAction("Index").Danger("Error in creating RateList.")); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.RateListHeader).DocumentTypeId, DocId = Header.RateListHeaderId, ActivityType = (int)ActivityTypeContants.Submitted, DocNo = Header.RateListName, UserRemark = UserRemark, })); return(RedirectToAction("RateListWizard", new { id = Id })); } return(View()); }
public void Update(RateListHeader pt) { pt.ObjectState = ObjectState.Modified; _unitOfWork.Repository <RateListHeader>().Update(pt); }
public void Delete(RateListHeader pt) { _unitOfWork.Repository <RateListHeader>().Delete(pt); }
public RateListHeader Create(RateListHeader pt) { pt.ObjectState = ObjectState.Added; _unitOfWork.Repository <RateListHeader>().Insert(pt); return(pt); }
public RateListHeader Add(RateListHeader pt) { _unitOfWork.Repository <RateListHeader>().Insert(pt); return(pt); }