public async Task <IActionResult> Create([Bind("SportId,SportName,Description")] Sport sport) { if (ModelState.IsValid) { _context.Add(sport); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sport)); }
public async Task <IActionResult> Create([Bind("PlayerId,FullName,Age,Contry,SportId")] Players players) { if (ModelState.IsValid) { _context.Add(players); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(players)); }
public IActionResult CreateTest(TestsList testsList) { if (ModelState.IsValid) { Tests test = new Tests { Date = testsList.Date, TestTypeID = testsList.TestType.TestTypeId }; db.Add(test); db.SaveChanges(); if (test.TestId > 0) { return(RedirectToAction("Details", new { id = test.TestId })); } } ViewBag.ListOfTests = db.TestTypes.ToList(); ModelState.AddModelError("", "some thing went wrong"); return(View()); }
public async Task UpdateAddress(Person person, Address address) { if (person.AddressId != null) { address.AddressId = (int)person.AddressId; _context.Addresses.Update(address); } else { person.Address = address; _context.Add(address); _context.Update(person); } await _context.SaveChangesAsync(); }
// Validate the submission and add the Wedding to the DB public IActionResult CreatePlayDate(Sport wed) { // Check whether User is logged in, and if so get session variables (User Id/Name) int?userId = HttpContext.Session.GetInt32("CurrentUserId"); if (userId == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { // Set current User as Wedding creator and add to DB wed.UserId = (int)userId; _Context.Add(wed); _Context.SaveChanges(); System.Console.WriteLine("Congratulations !!"); return(RedirectToAction("Dashboard")); } // Show Add page with errors return(View("Add")); }