public async Task <IActionResult> Create(MerchantVoucherViewModel merchantVoucher, [FromForm(Name = "ImageFile")] IFormFile file) { var user = await _userManager.GetUserAsync(User); // TODO: clean this mess up. I couldnt get the category to bind to the voucher model. // So i added the id to the viewmodel and added it by hand here. merchantVoucher.Voucher.Category = _context.VoucherCategories.FirstOrDefault(x => x.Id == merchantVoucher.CategoryId); if (ModelState.IsValid) { if (merchantVoucher.Voucher.DefaultImages == DefaultImages.Default) { await _voucherService.CreateMerchantVoucher(merchantVoucher.Voucher, file, user); } else { await _voucherService.CreateMerchantVoucher(merchantVoucher.Voucher, merchantVoucher.Voucher.DefaultImages, user); } return(RedirectToAction(nameof(Index))); } merchantVoucher.Categories = _voucherService.GetCategories(user); return(View(merchantVoucher)); }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var user = await _userManager.GetUserAsync(User); var merchantVoucher = _context.MerchantVouchers.Include(x => x.Category) .FirstOrDefault(x => x.Id == id); if (merchantVoucher == null) { return(NotFound()); } var model = new MerchantVoucherViewModel { Voucher = merchantVoucher, Categories = _voucherService.GetCategories(user), CategoryId = merchantVoucher.Category.Id }; return(View(model)); }
public async Task <IActionResult> Create() { var user = await _userManager.GetUserAsync(User); var model = new MerchantVoucherViewModel { Voucher = new MerchantVoucher(), Categories = _voucherService.GetCategories(user) }; return(View(model)); }