Esempio n. 1
0
 public ActionResult Create()
 {
     var viewModel = new GigFormViewModel()
     {
         Genres = _context.Genres.ToList()
     };
     return View(viewModel);
 }
Esempio n. 2
0
 public ActionResult Create()
 {
     var viewModel = new GigFormViewModel()
     {
         Genres = _context.Genres.ToList(),
         Heading = "Add a Gig"
     };
     return View("GigForm",viewModel);
 }
Esempio n. 3
0
 public ActionResult Create(GigFormViewModel viewModel)
 {
     var gig = new Gig()
     {
         ArtistId = User.Identity.GetUserId(),
         DateTime = viewModel.DateTime,
         GenreId = viewModel.Genre,
         Venue = viewModel.Venue
     };
     _context.Gig.Add(gig);
     _context.SaveChanges();
     return RedirectToAction("Index", "Home");
 }
Esempio n. 4
0
        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");
        }
Esempio n. 5
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 GigFormViewModel()
            {
                Genres = _context.Genres.ToList(),
                Date = gig.DateTime.ToString("d MMM yyyy"),
                Time = gig.DateTime.ToString("HH:mm"),
                Genre = gig.Genre.Id,
                Venue = gig.Venue,
                Heading = "Edit a Gig",
                Id = gig.Id
            };
            return View("GigForm", viewModel);
        }
Esempio n. 6
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.Id == viewModel.Id && g.ArtistId == userId);
            gig.Venue = viewModel.Venue;
            gig.DateTime = viewModel.GetDateTime();
            gig.GenreId = viewModel.Genre;

            _context.SaveChanges();

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