public ActionResult Create([Bind(Include = "ID,Name")] Artist artist) { if (ModelState.IsValid) { db.Artists.Add(artist); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(artist)); }
public ActionResult Create([Bind(Include = "ID,ArtistID,Name")] Track track) { if (ModelState.IsValid) { db.Tracks.Add(track); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ArtistID = new SelectList(db.Artists, "ID", "Name", track.ArtistID); return(View(track)); }
public IActionResult AddArtist([Bind("fName", "lName", "alias", "summary")] ArtistModel newArtist) { // return Content("Add Artist"); // check if data entered in body of request is valid if (ModelState.IsValid) { // add artist to database is data is valid _context.Add(newArtist); _context.SaveChanges(); return(View("ViewAll")); } else { // send errors as view data item if data is invalid List <string> errors = GetErrorListFromModelState(ModelState); string displayErrors = ""; // build errors into string to pass to view errors.ForEach(error => displayErrors += $"Error : {error}\n"); ViewData["errorMessage"] = displayErrors; return(View("Error")); } }
public void UpdateEvent(int idArtist, int idEvent, DateTime pd) { var deadline = _context.Events.Find(idEvent).EndDate; var ae = _context.ArtistEvent.Find(idArtist, idEvent); var check = DateTime.Compare(deadline, pd); if (check > 0) { ae.PerformanceDate = pd; _context.SaveChanges(); } }