예제 #1
0
        public ActionResult Update(GigViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitOfWork.Genre.GetAllGenres();
                return(View("GigForm", viewModel));
            }

            string userId = User.Identity.GetUserId();
            var    gig    = _unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id);

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

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

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

            _unitOfWork.Complete();

            return(RedirectToAction("Mine", "Gigs"));
        }
예제 #2
0
        public ActionResult Create(GigViewModel formModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    formModel.Genres = _context.Genre.ToList();
                    return(View("Create", formModel));
                }
                var gig = new Gig
                {
                    ArtistId = User.Identity.GetUserId(),
                    GenreId  = formModel.Genre,
                    Venue    = formModel.Venue,
                    DateTime = formModel.GetDateTime()
                };

                _context.Gig.Add(gig);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                var errorMessage = ex.Message;//OR ex.ToString(); OR Free text OR an custom object

                return(View());
            }
        }
예제 #3
0
        public ActionResult Create(GigViewModel viewModel)
        {
            //var userId = User.Identity.GetUserId();

            //solve this by create forignkey
            //var artist = _context.Users.Single(p => p.Id ==userId );
            //var genre = _context.Genres.Single(p => p.Id == viewModel.Genre);
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitofWork.Genres.GetAll();
                return(View("GigForm", viewModel));
            }

            Gig gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                Datetime = viewModel.GetDateTime(),
                GenreId  = viewModel.Genre,
                Venue    = viewModel.Venue
            };

            _unitofWork.Gigs.Add(gig);
            _unitofWork.Complete();
            return(RedirectToAction("Index", "Home"));
        }
예제 #4
0
        public async Task <IActionResult> Create(GigViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Genres = await GetGenres();

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

            var   userId = _userManager.GetUserId(User);
            Genre genre  = _appDbContext.Genres.Single(a => a.Id == model.GenreId);

            Gig newGig = new Gig(userId, genre, model.GetDateTime(), model.Venue);

            _appDbContext.Gigs.Add(newGig);
            await _appDbContext.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
예제 #5
0
        public ActionResult Create(GigViewModel 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("index", "Home"));
        }
예제 #6
0
        [ValidateAntiForgeryToken] // to prevent CSRF Attack
        public ActionResult AddGig(GigViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Genres = _context.Genre.ToList();
                return(View("Create", model));
            }

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

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

            return(RedirectToAction("Index", "Home"));
        }
예제 #7
0
        public ActionResult Create(GigViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitOfWork.Genre.GetAllGenres();
                return(View("GigForm", viewModel));
            }

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

            _unitOfWork.Gigs.Add(gig);
            _unitOfWork.Complete();

            return(RedirectToAction("Mine", "Gigs"));
        }
예제 #8
0
        public ActionResult Create(GigViewModel gigVM)
        {
            if (!ModelState.IsValid)

            {
                gigVM.Genres  = _unitOfWork.Genres.GetGenres();
                gigVM.Heading = "Add a Gig";
                return(View("GigForm", gigVM));
            }

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

            _unitOfWork.Gigs.Add(gig);
            _unitOfWork.Complete();
            return(RedirectToAction("Mine", "Gigs"));
        }
예제 #9
0
        public ActionResult Create(GigViewModel 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();

            /* o 'return' será o redirecionamento da página assim que o usuário clicar no botão 'Salvar' */
            return(RedirectToAction("Index", "Home"));
        }
예제 #10
0
        public ActionResult Update(GigViewModel gigVM)
        {
            if (!ModelState.IsValid)

            {
                gigVM.Genres = _unitOfWork.Genres.GetGenres();
                return(View("GigForm", gigVM));
            }

            var gig = _unitOfWork.Gigs.GetGigWithAttendances(gigVM.Id);

            if (gig == null)
            {
                return(HttpNotFound());
            }
            if (gig.ArtistId != User.Identity.GetUserId())
            {
                return(new HttpUnauthorizedResult());
            }
            gig.Modify(gigVM.GetDateTime(), gigVM.Venue, gigVM.Genre);

            _unitOfWork.Complete();
            return(RedirectToAction("Mine", "Gigs"));
        }