public ActionResult Create(EditPlateModelView modelView) { if (!ModelState.IsValid) { var restaurant = _restaurantRepository.Get(); modelView.RestaurantOptions = new SelectList(restaurant, "Id", "Name"); return(View(modelView)); } var plate = new Plate { Id = modelView.Id, Name = modelView.NamePlate, Ingredients = modelView.Ingredients, RestaurantId = modelView.RestaurantId }; try { _plateRepository.Create(plate); } catch (Exception ex) { //ModelState.AddModelError("message", ex.Message); var restaurant = _restaurantRepository.Get(); modelView.RestaurantOptions = new SelectList(restaurant, "Id", "Name"); return(View(modelView)); } return(RedirectToAction("Index")); }
public Plate Create(CreatePlateCommand command) { var plate = new Plate(command.PlateName, command.Price, command.RestaurantId); plate.Create(); _repository.Create(plate); if (Commit()) { return(plate); } return(null); }