Ejemplo n.º 1
0
        public ActionResult Create(ViewModels.GigFormViewModel viewModel)
        {
            //var artistId = ;                       //This is OK as it is possible becasue the compiler can convert it to the sql query
            ////var artist = _context.Users.Single(u => u.Id == User.Identity.GetUserId();    //This will throw the error now so above line must be used

            //var artist = _context.Users.Single(u => u.Id == artistId);
            ///* picks the indentity of the user currently loggedin */
            //var genre = _context.Genres.Single(g => g.Id == viewModel.Genre);

            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("GigForm", viewModel));
            }

            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewModel.GetDateTime(),    //Time of teh gig must be in 20:00.
                GenreId  = viewModel.Genre,
                Venue    = viewModel.Venue
            };

            //so now that the gig object is created it can be added to the _context.
            _context.Gigs.Add(gig);
            _context.SaveChanges();

            //now we are redirecting to the home page which temporarly gonna show all gigs
            return(RedirectToAction("Mine", "Gigs"));
        }
Ejemplo n.º 2
0
        public ActionResult Update(ViewModels.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.Id == viewModel.Id && g.ArtistId == userId);

            gig.Venue    = viewModel.Venue;
            gig.DateTime = viewModel.GetDateTime();
            gig.GenreId  = viewModel.Genre;

            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Ejemplo n.º 3
0
        public ActionResult Create(ViewModels.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"));
        }