public ActionResult Create(ConsoleCreate model) { if (!ModelState.IsValid) { return(View(model)); } //var service = new ConsoleService(); if (_consoleService.CreateConsole(model)) { TempData["SaveResult"] = "Your console was added."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Console could not be added."); return(View(model)); }
public bool CreateConsole(ConsoleCreate model) { var entity = new Console() { Name = model.Name, Description = model.Description, Brand = model.Brand, Price = model.Price, ReleaseDate = model.ReleaseDate, Rating = -1 }; using (var ctx = new ApplicationDbContext()) { ctx.Consoles.Add(entity); return(ctx.SaveChanges() == 1); } }