public ActionResult AchievementCreate(AchievementAdd model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateAchievementService(); if (service.AchievementAdd(model)) { TempData["SaveResult"] = "Your Achievement was created successfully."; return(RedirectToAction("Index", "VideoGames")); } ModelState.AddModelError("", "Achievement could not be created."); return(View(model)); }
public bool AchievementAdd(AchievementAdd model) { var entity = new Achievement() { VideoGameID = model.VideoGameID, VideoGame = model.VideoGame, AchievementName = model.AchievementName, AchievementNotes = model.AchievementNotes, AchievementCompleted = model.AchievementCompleted }; using (var ctx = new ApplicationDbContext()) { ctx.Achievements.Add(entity); return(ctx.SaveChanges() == 1); } }