public ActionResult Add(MatchViewModels model) { if(ModelState.IsValid) { TempData["MatchAdded"] = "Added the match"; // Add match to the database dbm.AddMatch(model); RedirectToAction("Table", "Statistics"); } TempData["MatchAdded"] = "Error on adding the match."; ModelState.AddModelError("", "Niet alle gegevens zijn juist ingevuld."); return RedirectToAction("Table", "Statistics", model); }
public void AddMatch(MatchViewModels model) { Match match = new Match { MatchedPlayed = DateTime.Parse(model.MatchDate), HomeTeamID = model.HomeTeamID, HomeTeamScored = model.HomeTeamScored, AwayTeamID = model.AwayTeamID, AwayTeamScored = model.AwayTeamScored }; db.Matches.Add(match); db.SaveChanges(); return; }