public async Task <IActionResult> Create(DrinkInsertViewModel viewModel) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <DrinkInsertViewModel, DrinkDTO>(); }); IMapper mapper = configuration.CreateMapper(); DrinkDTO dto = mapper.Map <DrinkDTO>(viewModel); try { await _drinkService.Create(dto); return(RedirectToAction("Home", "Index")); } catch (NecoException ex) { ViewBag.ValidationErrors = ex.Errors; } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; } return(View()); }
public ActionResult Create(DrinkViewModel drink)//need to have zero constructor for this binding to work { if (ModelState.IsValid) { _drinksService.Create(drink); return(RedirectToAction(nameof(Index))); } else { return(View(drink)); } }
public ActionResult Create(DrinkViewModel drink)//need to have zero constructor for this binding to work { if (ModelState.IsValid) { Drink createdDrink = _drinksService.Create(drink); return(PartialView("_drinkPartial", createdDrink)); } else { return(BadRequest()); } }