public async Task <ActionResult> Create(CatalogCouponViewModel catalogCouponViewModel) { try { if (ModelState.IsValid) { var catalogCoupon = Mapper.Map <CatalogCoupon>(catalogCouponViewModel); catalogCoupon.Status = CommonStatus.Active; await _catalogCouponService.CreateAsync(catalogCoupon, true); return(RedirectToAction("Index")); } } catch { } var categories = await _categoryService.GetAll(); var products = await _productService.GetAll(); ViewBag.ApplyForCategory = new SelectList(categories, "Id", "Name", catalogCouponViewModel.ApplyForCategory); ViewBag.ApplyForProduct = new SelectList(products, "Id", "Title", catalogCouponViewModel.ApplyForProduct); return(View(catalogCouponViewModel)); }
public async Task <ActionResult> Edit(CatalogCouponViewModel catalogCouponViewModel) { if (ModelState.IsValid) { CatalogCoupon catalogCoupon = await _catalogCouponService.Find(catalogCouponViewModel.Id); if (catalogCoupon == null) { return(HttpNotFound()); } Mapper.Map(catalogCouponViewModel, catalogCoupon); catalogCoupon.UpdatedDate = DateTime.Now; await _catalogCouponService.UpdateAsync(catalogCoupon, catalogCouponViewModel.Id, true); return(RedirectToAction("Index")); } var categories = await _categoryService.GetAll(); var products = await _productService.GetAll(); ViewBag.ApplyForCategory = new SelectList(categories, "Id", "Name", catalogCouponViewModel.ApplyForCategory); ViewBag.ApplyForProduct = new SelectList(products, "Id", "Title", catalogCouponViewModel.ApplyForProduct); return(View(catalogCouponViewModel)); }