//Create Cricketer public bool CreateCricketer(CricketerCreate model) { var entity = new Cricketer() { UserId = _userId, Name = model.Name, Country = model.Country, TotalRuns = model.TotalRuns }; using (var ctx = new ApplicationDbContext()) { ctx.Cricketerss.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(CricketerCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateCricketService(); if (service.CreateCricketer(model)) { TempData["SaveResult"] = "Your Cricketer was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Cricketer could not be created."); return(View(model)); }