public ActionResult Update(GigFormViewModels viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); } var userId = User.Identity.GetUserId(); var gig = _context.Gigs.Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Venue = viewModel.Venue; gig.DateTime = viewModel.GetDateTime(); gig.GenreId = viewModel.Genre; _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModels viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue, }; _context.Gigs.Add(gig); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }