public bool CreateCompetition(CompetitionCreate model) { var entity = new Competition() { Name = model.Name, City = model.City, Ranked = model.Ranked }; using (var ctx = new ApplicationDbContext()) { ctx.Competitions.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(CompetitionCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateCompetitionService(); if (service.CreateCompetition(model)) { TempData["SaveResult"] = "The competition was created"; return(RedirectToAction("Index")); } ; { ModelState.AddModelError("", "Competition could not be created."); return(View(model)); } }