Exemplo n.º 1
0
        private void CreateOrModifyAGig(GigsFormViewModel model)
        {
            if (model.UserAction == New)
            {
                // Create a new gig object.
                var gig = new Gig
                {
                    ArtistId = _userManager.GetUserId(User), DateTime = model.GetDateTime(), GenreId = model.Genre,
                    Venue    = model.Venue, ImageUrl = _uniqueImageName
                };

                // Add gig object into gig collections.
                _unitOfWork.Gigs.AddAGig(gig);
            }
            else
            {
                // Modify a gig object.
                var gigInDb = _unitOfWork.Gigs.FindGigById(model.GigId);
                gigInDb.DateTime = model.GetDateTime();
                gigInDb.Venue    = model.Venue;
                gigInDb.GenreId  = model.Genre;
                if (model.Photo != null)
                {
                    if (gigInDb.ImageUrl != null)
                    {
                        var oldImage = Path.Combine(_hostEnvironment.ContentRootPath, @"wwwroot\images\", gigInDb.ImageUrl);
                        if (System.IO.File.Exists(oldImage))
                        {
                            System.IO.File.Delete(oldImage);
                        }
                    }
                    gigInDb.ImageUrl = _uniqueImageName;
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult Update(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitOfWork.Genres.GetGenres();

                return(View("GigForm", viewModel));
            }


            var gig = _unitOfWork.Gigs.GetGigWithAttendees(viewModel.Id);

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

            if (gig.ArtistId != User.Identity.GetUserId())
            {
                return(new HttpUnauthorizedResult());
            }


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


            _unitOfWork.Complete();


            return(RedirectToAction("Mine", "Gigs"));
        }
Exemplo n.º 3
0
        public ActionResult Create(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _unitOfWork.Genres.GetGenres();

                return(View("GigForm", viewModel));
            }


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


            _unitOfWork.Gigs.Add(gig);


            _unitOfWork.Complete();


            return(RedirectToAction("Mine", "Gigs"));
        }
Exemplo n.º 4
0
        public ActionResult Update(GigsFormViewModel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                viewmodel.Genres = db.Genres.ToList();
                return(View("GigForm", viewmodel));
            }
            var userId = User.Identity.GetUserId();
            var gig    = db.Gigs.Include(g => g.Attendances.Select(a => a.Attendee))
                         .Single(g => g.Id == viewmodel.Id && g.ArtistId == userId);

            gig.Modify(viewmodel.GetDateTime(), viewmodel.Venue, viewmodel.Genre);
            db.SaveChanges();
            return(RedirectToAction("Mine", "Gigs"));
        }
Exemplo n.º 5
0
        public ActionResult Create(GigsFormViewModel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                viewmodel.Genres = db.Genres.ToList();
                return(View("GigForm", viewmodel));
            }
            var gig = new Gig
            {
                ArtistId = User.Identity.GetUserId(),
                DateTime = viewmodel.GetDateTime(),
                GenreId  = viewmodel.Genre,
                Venue    = viewmodel.Venue,
            };

            db.Gigs.Add(gig);
            db.SaveChanges();
            return(RedirectToAction("Mine", "Gigs"));
        }
Exemplo n.º 6
0
        public ActionResult Edit(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _applicationDbContext.Genres.ToList();
                return(View("GigForm", viewModel));
            }

            var currentUserId = User.Identity.GetUserId();

            var gig = _applicationDbContext.Gigs
                      .Include(g => g.Attendences.Select(a => a.Attendee))
                      .Single(g => g.Id == viewModel.Id && g.ArtistId == currentUserId);

            gig.Notify(viewModel.GetDateTime(), viewModel.Vanue, viewModel.Genre);
            _applicationDbContext.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Exemplo n.º 7
0
        public ActionResult Update(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();//viewmodel coming from Create view has it's Genres=null
                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"));
        }
Exemplo n.º 8
0
        public ActionResult Create(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();//viewmodel coming from Create view has it's Genres=null
                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"));
        }
Exemplo n.º 9
0
        public ActionResult Update(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                //Genres need to populate first
                viewModel.Genres = _context.Genre.ToList();
                return(View("GigForm", viewModel));
            }

            var userId = User.Identity.GetUserId();
            var gigs   = _context.Gigs.Single(g => g.Id == viewModel.Id && g.ArtistId == userId);

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

            _context.SaveChanges();


            return(RedirectToAction("Mine", "Gigs"));
        }
Exemplo n.º 10
0
        public ActionResult Create(GigsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                //Genres need to populate first
                viewModel.Genres = _context.Genre.ToList();
                return(View("GigForm", "Gigs"));
            }


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

            _context.Gigs.Add(gigs);
            _context.SaveChanges();
            return(RedirectToAction("Mine", "Home"));
        }