public ActionResult Create(AchievementCreate model) { Games games = _db.Games.Find(model.GameID); Character chars = _db.Character.Find(model.Char_Id); model.Char_Name = chars.Char_Name; if (games == null) { return(HttpNotFound("Game not found")); } if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors); return(View(model)); } var service = CreateAchieveService(); if (service.CreateAchieve(model)) { TempData["SaveResult"] = "Your Achievement has been Entered."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Achievement could not be entered."); return(View(model)); }
public bool CreateAchieve(AchievementCreate model) { var entity = new Achievements() { OwnerID = _userId, //GameTitle = (Data.Game)model.GameTitle, Char_Id = model.Char_Id, GameID = model.GameID, Char_Name = model.Char_Name, Achievement = model.Achievement, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Achievements.Add(entity); return(ctx.SaveChanges() == 1); } }