public ActionResult Edit(int?Id) { var Promotion = PromotionRepository.GetPromotionById(Id.Value); if (Promotion != null && Promotion.IsDeleted != true) { var model = new PromotionViewModel(); AutoMapper.Mapper.Map(Promotion, model); //if (model.CreatedUserId != Helpers.Common.CurrentUser.Id && Helpers.Common.CurrentUser.UserTypeId != 1) //{ // TempData["FailedMessage"] = "NotOwner"; // return RedirectToAction("Index"); //} var detailList = PromotionRepository.GetAllPromotionDetailBy(model.Id).Select(x => new PromotionDetailViewModel { Id = x.Id, IsAll = x.IsAll, IsDeleted = false, PercentValue = x.PercentValue, ProductId = x.ProductId, CategoryCode = x.CategoryCode, QuantityFor = x.QuantityFor, Type = x.Type }).ToList(); if (detailList.Count == 0) { detailList.Add(new PromotionDetailViewModel() { QuantityFor = 1, PercentValue = 0 }); } model.DetailList = detailList; var productList = ProductRepository.GetAllProduct() .Select(item => new ProductViewModel { Code = item.Code, Barcode = item.Barcode, Name = item.Name, Id = item.Id, CategoryCode = item.CategoryCode, PriceOutbound = item.PriceOutbound, Unit = item.Unit, }); ViewBag.productList = productList; return(View(model)); } if (Request.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.AbsoluteUri)); } return(RedirectToAction("Index")); }