public ActionResult Create(CommisionViewModel model) { if (ModelState.IsValid) { var Commision = new Domain.Sale.Entities.Commision(); AutoMapper.Mapper.Map(model, Commision); Commision.IsDeleted = false; Commision.CreatedUserId = WebSecurity.CurrentUserId; Commision.ModifiedUserId = WebSecurity.CurrentUserId; Commision.CreatedDate = DateTime.Now; Commision.ModifiedDate = DateTime.Now; CommisionRepository.InsertCommision(Commision); if (model.BranchIdList != null) { foreach (var id in model.BranchIdList) { CommisionRepository.InsertCommisionBranch(new CommisionBranch { BranchId = Convert.ToInt32(id), CommisionId = Commision.Id }); } } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Detail(CommisionDetailViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { foreach (var item in model.DetailList) { if (item.CommissionValue < 0) { item.CommissionValue = 0; } else if ((item.IsMoney == null || item.IsMoney == false) && item.CommissionValue > 100) { item.CommissionValue = 100; } else if (item.CommissionValue > item.Price) { item.CommissionValue = item.Price; } if (item.Id > 0) { var commision = commisionRepository.GetCommisionById(item.Id); commision.ModifiedUserId = WebSecurity.CurrentUserId; commision.ModifiedDate = DateTime.Now; commision.CommissionValue = item.CommissionValue; commision.IsMoney = item.IsMoney; commisionRepository.UpdateCommision(commision); } else { if (item.CommissionValue > 0) { var commision = new Commision(); commision.IsDeleted = false; commision.CreatedUserId = WebSecurity.CurrentUserId; commision.ModifiedUserId = WebSecurity.CurrentUserId; commision.CreatedDate = DateTime.Now; commision.ModifiedDate = DateTime.Now; commision.BranchId = model.BranchId; commision.StaffId = model.StaffId; commision.ProductId = item.ProductId; commision.CommissionValue = item.CommissionValue; commision.IsMoney = item.IsMoney; commisionRepository.InsertCommision(commision); } } } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess; return(RedirectToAction("Detail", new { BranchId = model.BranchId, StaffId = model.StaffId })); } return(View(model)); } return(View(model)); }