public bool CreateVersion(VersionCreate model) { var entity = new GameVersion() { Name = model.Name, Description = model.Description, ReleaseYear = model.ReleaseYear }; using (var ctx = new ApplicationDbContext()) { ctx.Versions.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(VersionCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new VersionService(); if (service.CreateVersion(model)) { TempData["SaveResult"] = "Your version was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Version could not be created."); return(View(model)); }