public bool CreateShopping(ShoppingCreate model) { var entity = new Shopping() { OwnerId = _userId, ShoppingLiquor = model.ShoppingLiquor, ShoppingFruit = model.ShoppingFruit, ShoppingJuice = model.ShoppingFruit, ShoppingOther = model.ShoppingOther }; using (var ctx = new ApplicationDbContext()) { ctx.ShoppingList.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ShoppingCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateShoppingService(); if (service.CreateShopping(model)) { TempData["SaveResult"] = "Your note was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Note could not be created."); return(View()); }