public ActionResult Create(PlatingCreate model) { if ((!ModelState.IsValid) || (SaveCreate(model) == false)) { return(View(model)); } return(RedirectToAction("Index")); }
private bool SaveCreate(PlatingCreate model) { var service = CreatePlatingService(); if (service.CreatePlating(model)) { TempData["SaveResult"] = "Your Plating was created."; return(true); } else { ModelState.AddModelError("", "Plating could not be created."); return(false); } }
public bool CreatePlating(PlatingCreate model) { var entity = new Plating() { AuthorID = userId, Name = model.Name, Description = model.Description, DateCreated = DateTimeOffset.UtcNow, }; using (var context = new CookbookContext()) { context.Platings.Add(entity); return(context.SaveChanges() == 1); } }