public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genres.GetGenre(); return(View("GigForm", viewModel)); } var gig = _unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id); if (gig == null) { return(HttpNotFound()); } if (gig.ArtistId != User.Identity.GetUserId()) { return(new HttpUnauthorizedResult()); } gig.Update(viewModel.getDateTime(), viewModel.Venue, viewModel.Genre); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Update(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _context.Genres.ToList(); return(View("GigForm", viewModel)); } var userId = User.Identity.GetUserId(); var gig = _context.Gigs .Include(g => g.Attendances.Select(a => a.Attendee)) .Single(g => g.Id == viewModel.Id && g.ArtistId == userId); gig.Venue = viewModel.Venue; gig.DateTime = viewModel.getDateTime(); gig.GenreId = viewModel.Genre; gig.Modify(viewModel.getDateTime(), viewModel.Venue, viewModel.Genre); _context.SaveChanges(); return(RedirectToAction("Mine", "Gigs")); }
public ActionResult Create(GigFormViewModel 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")); }
public ActionResult Create(GigFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Genres = _unitOfWork.Genres.GetGenre(); return(View("GigForm", viewModel)); } var gig = new Gig { ArtistId = User.Identity.GetUserId(), DateTime = viewModel.getDateTime(), GenreId = viewModel.Genre, Venue = viewModel.Venue, }; _unitOfWork.Gigs.AddGig(gig); _unitOfWork.Complete(); return(RedirectToAction("Mine", "Gigs")); }