//Create public bool Create(MealViewCreateModel model) { var dishes = new List <Dish>(); model.Dishes.ForEach(x => { dishes.Add(dishRepo.GetById(x)); }); var tags = new List <Tag>(); model.Tags.ForEach(x => { tags.Add(tagRepo.GetById(x)); }); var meal = new Meal { UserId = model.UserId, Name = model.Name, Dishes = dishes, Tags = tags }; meal = mealRepo.Create(meal);; return(meal.Id != 0); }
//GET public ActionResult Create() { var userId = Guid.Parse(User.Identity.GetUserId()); var dishes = DishService.GetUserDishSelectList(userId); var tags = TagService.GetUserTagSelectList(userId); MealViewCreateModel model = new MealViewCreateModel(); model.DishData = dishes.ToList(); model.TagData = tags.ToList(); return(View(model)); }
public ActionResult Create(MealViewCreateModel model) { if (!ModelState.IsValid) { return(View(model)); } model.UserId = Guid.Parse(User.Identity.GetUserId()); if (MealService.Create(model)) { TempData["SaveResult"] = "Your meal was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Meal could not be created."); return(View(model)); }