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)); }