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 ViewResult Create() { var model = new CommisionViewModel(); ViewBag.branchList = BranchRepository.GetAllBranch().Where(x => x.Id == Helpers.Common.CurrentUser.BranchId || Helpers.Common.CurrentUser.UserTypeId == 1).AsEnumerable().Select(x => new SelectListItem { Text = x.Name, Value = x.Id + "" }).ToList(); return(View(model)); }
public ViewResult Detail(int BranchId, int StaffId, string txtProductCode, string txtCode, string txtSearch) { CommisionDetailViewModel model = new CommisionDetailViewModel(); var listCommision = commisionRepository.GetAllCommision().Where(item => item.BranchId == BranchId && item.StaffId == StaffId).ToList(); model.StaffName = staffsRepository.GetAllStaffs().Where(item => item.Id == StaffId).Select(item => item.Name).FirstOrDefault(); model.StaffId = StaffId; model.DetailList = new List <CommisionViewModel>(); var productList = productRepository.GetAllvwProductAndService().Select(item => new { item.Id, item.Code, item.Name, item.PriceOutbound }).ToList(); if (!string.IsNullOrEmpty(txtCode)) { productList = productList.Where(x => x.Code.Contains(txtCode)).ToList(); } if (!string.IsNullOrEmpty(txtSearch)) { productList = productList.Where(x => x.Name.Contains(txtSearch)).ToList(); } foreach (var item in productList) { var commisionViewModel = new CommisionViewModel(); commisionViewModel.ProductId = item.Id; commisionViewModel.Name = item.Code + " - " + item.Name; commisionViewModel.Price = item.PriceOutbound.Value; commisionViewModel.IsMoney = false; var commision = listCommision.Where(i => i.ProductId == item.Id).FirstOrDefault(); if (commision != null) { commisionViewModel.Id = commision.Id; commisionViewModel.CommissionValue = commision.CommissionValue; commisionViewModel.IsMoney = commision.IsMoney == null ? false : commision.IsMoney; } model.DetailList.Add(commisionViewModel); } ViewBag.SuccessMessage = TempData["SuccessMessage"]; ViewBag.FailedMessage = TempData["FailedMessage"]; ViewBag.AlertMessage = TempData["AlertMessage"]; return(View(model)); }
public ActionResult Edit(CommisionViewModel model) { if (ModelState.IsValid) { if (Request["Submit"] == "Save") { var Commision = CommisionRepository.GetCommisionById(model.Id); AutoMapper.Mapper.Map(model, Commision); Commision.ModifiedUserId = WebSecurity.CurrentUserId; Commision.ModifiedDate = DateTime.Now; CommisionRepository.UpdateCommision(Commision); var listCommisionBranch = CommisionRepository.GetListCommisionBranch(Commision.Id).ToList(); for (int i = 0; i < listCommisionBranch.Count; i++) { CommisionRepository.DeleteCommisionBranch(listCommisionBranch[i].Id); } 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.UpdateSuccess; return(RedirectToAction("Index")); } return(View(model)); } return(View(model)); //if (Request.UrlReferrer != null) // return Redirect(Request.UrlReferrer.AbsoluteUri); //return RedirectToAction("Index"); }
public ActionResult Edit(int?Id) { var Commision = CommisionRepository.GetCommisionById(Id.Value); if (Commision != null && Commision.IsDeleted != true) { var model = new CommisionViewModel(); AutoMapper.Mapper.Map(Commision, model); if (model.CreatedUserId != Erp.BackOffice.Helpers.Common.CurrentUser.Id && Erp.BackOffice.Helpers.Common.CurrentUser.UserTypeId != 1) { TempData["FailedMessage"] = Wording.NotOwner; return(RedirectToAction("Index")); } var listCommisionSale = CommisionSaleRepository.GetAllCommisionSale().Where(x => x.CommisionId == Commision.Id).FirstOrDefault(); if (listCommisionSale != null) { TempData["FailedMessage"] = Wording.CommisionApplied; return(RedirectToAction("Index")); } ViewBag.branchList = BranchRepository.GetAllBranch().Where(x => x.Id == Helpers.Common.CurrentUser.BranchId || Helpers.Common.CurrentUser.UserTypeId == 1).AsEnumerable().Select(x => new SelectListItem { Text = x.Name, Value = x.Id + "" }).ToList(); var listCommisionBranch = CommisionRepository.GetListCommisionBranch(Commision.Id).ToList(); model.BranchIdList = listCommisionBranch.Select(x => x.BranchId.ToString()).ToArray(); return(View(model)); } if (Request.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.AbsoluteUri)); } return(RedirectToAction("Index")); }
public ActionResult Detail(int?Id) { var Commision = CommisionRepository.GetCommisionById(Id.Value); if (Commision != null && Commision.IsDeleted != true) { var model = new CommisionViewModel(); AutoMapper.Mapper.Map(Commision, model); if (model.CreatedUserId != Erp.BackOffice.Helpers.Common.CurrentUser.Id && Erp.BackOffice.Helpers.Common.CurrentUser.UserTypeId != 1) { TempData["FailedMessage"] = "NotOwner"; return(RedirectToAction("Index")); } return(View(model)); } if (Request.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.AbsoluteUri)); } return(RedirectToAction("Index")); }