Пример #1
0
        public ActionResult Create()
        {
            var viewModel = new GigFormViewModels
            {
                Genres  = _context.Genres.ToList(),
                Heading = "Add a Gig"
            };

            return(View("GigForm", viewModel));
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            var userId = User.Identity.GetUserId();
            var gig    = _context.Gigs.Single(g => g.Id == id && g.ArtistId == userId);


            var viewModel = new GigFormViewModels
            {
                Genres  = _context.Genres.ToList(),
                Id      = gig.Id,
                Date    = gig.DateTime.ToString("d MMM yyyy"),
                Time    = gig.DateTime.ToString("HH:mm"),
                Genre   = gig.GenreId,
                Venue   = gig.Venue,
                Heading = "Edit a Gig"
            };

            return(View("GigForm", viewModel));
        }
Пример #3
0
        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"));
        }
Пример #4
0
        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"));
        }