public ActionResult Create(ToyCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreatedToysService(); if (service.CreateToy(model)) { TempData["SaveResult"] = "Your BLINYL was added."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "BLINYL could not be added."); return(View(model)); }
public bool CreateToy(ToyCreate model) { var entity = new Toy() { OwnerId = _userId, Name = model.Name, Brand = model.Brand, Series = model.Series, Artist = model.Artist, Description = model.Description, ReleaseYear = model.ReleaseYear, RetailPrice = model.RetailPrice, }; using (var ctx = new ApplicationDbContext()) { ctx.Toys.Add(entity); return(ctx.SaveChanges() == 1); } }