public bool CreateWeakness(WeaknessCreate model) { var newWeakness = new Weakness { WeaknessId = model.WeaknessId, Type = model.Type, Value = model.Value }; using (var ctx = new ApplicationDbContext()) { ctx.Weaknesses.Add(newWeakness); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(WeaknessCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateWeaknessService(); if (service.CreateWeakness(model)) { TempData["SaveResult"] = "Your Weakness was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Weakness could not be created."); return(View(model)); }