Ejemplo n.º 1
0
        public async Task <IActionResult> Create(GigsViewModel newGig)
        {
            if (!ModelState.IsValid)
            {
                newGig.Genres = await _context.Genres.ToListAsync();

                return(View("Create", newGig));
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);

            var gig = new Gig
            {
                ArtistId = user.Id,
                GenreId  = newGig.GenreId,
                Date     = newGig.GetDateTime(),
                Venue    = newGig.Venue
            };

            _context.Gigs.Add(gig);

            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                newGig.Id = gig.Id;
                return(RedirectToAction("index", "Home"));
            }
            return(BadRequest());
        }
Ejemplo n.º 2
0
        public ActionResult Create(GigsViewModel ViewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewModel.Genres = _unitOfWork.Gigs.GetGenres();
                return(View("GigForm", ViewModel));
            }

            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = ViewModel.GetDateTime(),
                Venue    = ViewModel.Venue,
                GenreId  = ViewModel.Genre
            };


            _unitOfWork.Gigs.Add(gig);

            _unitOfWork.Complete();

            //_context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Ejemplo n.º 3
0
        public ActionResult Update(GigsViewModel 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.Attendences.Select(a => a.Attendee))
                         .Single(g => g.Id == viewModel.Id && g.ArtistId == userId);

            gig.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre);

            _context.SaveChanges();
            return(RedirectToAction("MyUpcomingGigs", "Gigs"));
        }
Ejemplo n.º 4
0
        public ActionResult Edit(GigsViewModel GigView)
        {
            if (!ModelState.IsValid)
            {
                GigView.Genres = db.Genres.ToList();
                return(View("Edit", GigView));
            }
            var userId = User.Identity.GetUserId();
            var gigs   = db.Gigs
                         .Include(a => a.Attendances.Select(g => g.Attendee))
                         .Single(g => g.Id == GigView.Id && g.ArtistId == userId);

            gigs.Mofify(GigView.GetDateTime(), GigView.Venue, GigView.Genre);

            db.SaveChanges();

            return(RedirectToAction("MineGigs", "Gigs"));
        }
Ejemplo n.º 5
0
        public ActionResult Create(GigsViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("Create", 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"));
        }
Ejemplo n.º 6
0
        public ActionResult Create(GigsViewModel GigView)
        {
            if (!ModelState.IsValid)
            {
                GigView.Genres = db.Genres.ToList();
                return(View(GigView));
            }

            var gigs = new Gig()
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = GigView.GetDateTime(),
                Venue    = GigView.Venue,
                GenreId  = GigView.Genre
            };

            db.Gigs.Add(gigs);
            db.SaveChanges();

            return(RedirectToAction("Create", "Gigs"));
        }
Ejemplo n.º 7
0
        public ActionResult Update(GigsViewModel ViewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewModel.Genres = _unitOfWork.Gigs.GetGenres().ToList();
                return(View("GigForm", ViewModel));
            }

            var userId = User.Identity.GetUserId();

            //this is the part resposible for get the users will attend some events
            //.Include(g=>g.Attendances.Select(l=>l.Attendee))

            //var gig = _context.Gigs.Include(g=>g.Attendances.Select(l=>l.Attendee))
            //    .Single(c => c.Id == ViewModel.Id && c.ArtistId == userId);

            var gig = _unitOfWork.Gigs.GetGigWithAttende(ViewModel.Id);

            if (gig == null)
            {
                return(HttpNotFound());
            }

            if (gig.ArtistId != userId)
            {
                return(new HttpUnauthorizedResult());
            }



            gig.Update(ViewModel.GetDateTime(), ViewModel.Genre, ViewModel.Venue);



            _unitOfWork.Complete();
            //_context.SaveChanges();

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