public ActionResult Edit(int id, FormCollection collection) { var model = new DiscountVM { Discount = uow.Discounts.Obtener(id), DiscountCategories = uow.DiscountCategories.Lista().OrderBy(c => c.Name).ToList(), SelectedCategoryId = int.Parse(collection["SelectedCategoryId"]) }; try { var usuario = uow.Advertisers.Consulta(a => a.Name == User.Identity.Name).SingleOrDefault(); var categoria = uow.DiscountCategories.Obtener(model.SelectedCategoryId); model.Discount.Advertiser = usuario; model.Discount.DiscountCategory = categoria; if (model.Discount.IsValid) { UpdateModel(model.Discount, "Discount"); uow.Discounts.Modificar(model.Discount); uow.SaveChanges(); return RedirectToAction("Index", "AdvertisersManagement"); } model.DiscountCategories = uow.DiscountCategories.Lista().OrderBy(c => c.Name).ToList(); return View(model); } catch (Exception ex) { model.DiscountCategories = uow.DiscountCategories.Lista().OrderBy(c => c.Name).ToList(); return View(model); } }
// // GET: /AdvertisersManagement/Create public ActionResult Create() { var discount = new DiscountVM { Discount = uow.Discounts.Crear(), DiscountCategories = uow.DiscountCategories.Lista().OrderBy(p => p.Name).ToList() }; return View(discount); }
public async Task <IActionResult> Create(DiscountVM vm) { if (ModelState.IsValid) { Discount model = _mapper.Map <Discount>(vm); await _discountService.CreateAsync(model); } return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(long Id) { DiscountDTO discountDto = _discountService.GetDiscount(Id, CurrentLanguage, CurrentCurrency); Mapper.Initialize(c => c.CreateMap <DiscountDTO, DiscountVM>()); DiscountVM discountVM = Mapper.Map <DiscountDTO, DiscountVM>(discountDto); return(View(discountVM)); }
// // GET: /AdvertisersManagement/Edit/1 public ActionResult Edit(int id) { var oferta = uow.Discounts.Obtener(id); var model = new DiscountVM { Discount = oferta, DiscountCategories = uow.DiscountCategories.Lista().OrderBy(c => c.Name).ToList(), SelectedCategoryId = oferta.DiscountCategory.Id }; return View(model); }
// GET: Pharmacist/Discount public async Task <ActionResult> Index() { var model = new DiscountVM { AllProductList = await db.Products.ToListAsync(), DiscountedProducts = await db.Products.Where(p => p.IsOnSale == true) .ToListAsync(), Categories = new SelectList(await db.Categories.ToListAsync(), "Id", "Name") }; return(View(model)); }
public ActionResult Add(DiscountVM discount) { if (ModelState.IsValid) { Mapper.Initialize(c => c.CreateMap <DiscountVM, DiscountDTO>()); DiscountDTO dto = Mapper.Map <DiscountVM, DiscountDTO>(discount); OperationDetails op = _discountService.AddDiscount(dto); return(Json(new { Succedeed = op.Succedeed, message = op.Message, prop = op.Property })); } else { return(View(discount)); } }
public async Task <int> SaveDataAsync(DiscountVM viewModel) { var entity = _mapper.Map <Discount>(viewModel); if (!string.IsNullOrEmpty(entity.DiscountCode)) { entity.DiscountCode = entity.DiscountCode.ToUpper(); } if (viewModel.DiscountId == 0) { await _discountRepository.AddAsync(entity); } else { await _discountRepository.UpdateAsync(entity); } return(await _unitOfWork.SaveAsync()); }
public ActionResult Create(DiscountVM oferta) { try { var usuario = uow.Advertisers.Consulta(a => a.Name == User.Identity.Name).SingleOrDefault(); var categoria = uow.DiscountCategories.Obtener(oferta.SelectedCategoryId); oferta.Discount.Advertiser = usuario; oferta.Discount.DiscountCategory = categoria; if (oferta.Discount.IsValid) { uow.Discounts.Agregar(oferta.Discount); uow.SaveChanges(); return RedirectToAction("Index", "AdvertisersManagement"); } oferta.DiscountCategories = uow.DiscountCategories.Lista().OrderBy(p => p.Name).ToList(); return View(oferta); } catch (Exception ex) { oferta.DiscountCategories = uow.DiscountCategories.Lista().OrderBy(p => p.Name).ToList(); return View(oferta); } }
public async Task <ActionResult> Detail(DiscountVM viewModel, HttpPostedFileBase file) { if (ModelState.IsValid) { viewModel.DiscountNameAlias = EntityExtensions.ConvertToUnSign(viewModel.DiscountName); if (file != null && file.ContentLength > 0) { string pic = "discount_" + (int)viewModel.DiscountType + "_" + viewModel.DiscountNameAlias + Path.GetExtension(file.FileName); string path = Path.Combine(Server.MapPath("/img/"), pic); viewModel.DiscountCover = EntityExtensions.SaveImage(file, pic, path); } if (await _adminDiscountService.SaveDataAsync(viewModel) > 0) { return(RedirectToAction("Index", new { status = StatusMessageId.UpdateSuccess })); } } ModelState.AddModelError("Error", "Cannot save your product"); return(View()); }
public IActionResult Index() { var discount = new DiscountVM(); return(View(discount)); }
public IActionResult Create(int ID) { var vm = new DiscountVM(); return(View(vm)); }
public ActionResult Add() { DiscountVM discount = new DiscountVM(); return(View(discount)); }