public RateListProductRateGroup Add(RateListProductRateGroup pt) { _unitOfWork.Repository <RateListProductRateGroup>().Insert(pt); return(pt); }
public void Update(RateListProductRateGroup pt) { pt.ObjectState = ObjectState.Modified; _unitOfWork.Repository <RateListProductRateGroup>().Update(pt); }
public RateListProductRateGroup Create(RateListProductRateGroup pt) { pt.ObjectState = ObjectState.Added; _unitOfWork.Repository <RateListProductRateGroup>().Insert(pt); return(pt); }
public void Delete(RateListProductRateGroup pt) { _unitOfWork.Repository <RateListProductRateGroup>().Delete(pt); }
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)); }