Exemplo n.º 1
0
        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.Single(g => g.GigId == viewModel.Id && g.ArtistId == userId);

            gig.Venue   = viewModel.Venue;
            gig.GigDate = viewModel.GetGigDate();
            gig.GenreId = viewModel.Genre;

            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Exemplo n.º 2
0
        public ActionResult Create(GigFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("GigForm", viewModel));
            }

            var userId = User.Identity.GetUserId();

            var gig = new Gig
            {
                Venue    = viewModel.Venue,
                ArtistId = userId,
                GenreId  = viewModel.Genre,
                GigDate  = viewModel.GetGigDate()
            };

            _context.Gigs.Add(gig);
            _context.SaveChanges();

            return(RedirectToAction("Attending", "Gigs"));
        }