Пример #1
0
        public ActionResult AddGig(GigViewModel gigViewModel)
        {
            if (ModelState.IsValid)
            {
                //We Can compare User.Identity.GetUserId() Function in LinQ Method !!
                // Because this Method is Purely a C Sharp Code !!!
                //    var artist = _context.Users.Where(u => u.Id == User.Identity.GetUserId());

                var artistId = User.Identity.GetUserId();

                //In the following code, we use the Single method which takes one predicate as a parameter.
                //Using that predicate we specify our condition which is going to return only one element from the sequence.

                var artist = _context.Users.Single(u => u.Id == artistId);
                var genre  = _context.Genres.Single(g => g.Id == gigViewModel.SelectedGenreId);

                _gig.Venue    = gigViewModel.Venue;
                _gig.Artist   = artist;
                _gig.Genre    = genre;
                _gig.DateTime = DateTime.Parse(string.Format("{0} {1}", gigViewModel.Date, gigViewModel.Time));
                _context.Gigs.Add(_gig);
                _context.SaveChanges();
                return(RedirectToAction("Mine", "Gigs"));
            }
            return(View());
        }
Пример #2
0
        public ActionResult ApplyForGig(int id)
        {
            //Gig gig = db.Gigs.Find(id);
            //Artist artist = db.Artists.Find(User.Identity.GetUserId());
            //gig.Artists.Add(artist);


            //db.SaveChanges();

            var gigs = db.Gigs.Include(g => g.Host);
            List <GigViewModel> gigvms = new List <GigViewModel>();

            foreach (Gig g in gigs)
            {
                GigViewModel gigvm            = CloudConcerts3.Models.ModelMapper.ConvertToGigViewModel(g);
                var          foundApplication = db.ArtistGigs.Where(a => a.ArtistID.Equals(User.Identity.GetUserId())).Where(gi => gi.GigID.Equals(gigvm.GigID)).First();
                if (foundApplication != null)
                {
                    gigvm.hasUserApplied = true;
                }

                gigvms.Add(gigvm);
            }

            return(View("Apply", gigvms));
        }
Пример #3
0
        public ActionResult Edit(int gigId)
        {
            var gig = _unitofWork.Gigs.Get(gigId);

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

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

            var viewModel = new GigViewModel
            {
                Id      = gigId,
                Date    = gig.Datetime.ToString("dd MMM yyyy"),
                Time    = gig.Datetime.ToString("HH:mm"),
                Genre   = gig.GenreId,
                Venue   = gig.Venue,
                Genres  = _unitofWork.Genres.GetAll(),
                Heading = "Update Gig"
            };

            return(View("GigForm", viewModel));
        }
Пример #4
0
        public GigsController()
        {
            _context      = new ApplicationDbContext();
            _gigViewModel = new GigViewModel();

            _gig = new Gig();
        }
Пример #5
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"));
        }
Пример #6
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"));
        }
Пример #7
0
        public ActionResult Edit(int id)
        {
            var gig = _unitOfWork.Gigs.GetGigForEdit(id);

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

            var genres = _unitOfWork.Genre.GetAllGenres();

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

            return(View("GigForm", viewModel));
        }
Пример #8
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());
            }
        }
Пример #9
0
        public ActionResult Index(string query = null)
        {
            var upcomingGigs = _context.Gigs
                               .Include(g => g.Artist)
                               .Include(g => g.Genre)
                               .Where(g => g.DateTime > DateTime.Now && !g.IsCanceled);


            if (!String.IsNullOrWhiteSpace(query))
            {
                upcomingGigs = upcomingGigs.Where(g =>
                                                  g.Artist.Name.Contains(query) ||
                                                  g.Genre.Name.Contains(query) ||
                                                  g.Venue.Contains(query));
            }

            var userId      = User.Identity.GetUserId();
            var attendances = _context.Attendances
                              .Where(a => a.AttendeeId == userId && a.Gig.DateTime > DateTime.Now)
                              .ToList()
                              .ToLookup(a => a.GigId);

            var viewModel = new GigViewModel
            {
                UpcomingGigs = upcomingGigs,
                ShowActions  = User.Identity.IsAuthenticated,
                Heading      = "Upcoming Gigs",
                SearchTerm   = query,
                Attendances  = attendances
            };

            return(View("Gigs", viewModel));
        }
Пример #10
0
        public ActionResult Details(int id)
        {
            var gig = _context.Gigs
                      .Include(g => g.Artist)
                      .Include(g => g.Genre)
                      .SingleOrDefault(g => g.Id == id);

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

            var viewModel = new GigViewModel {
                Gig = gig
            };

            if (User.Identity.IsAuthenticated)
            {
                var userId = User.Identity.GetUserId();

                viewModel.IsAttending = _context.Attendances
                                        .Any(a => a.GigId == gig.Id && a.AttendeeId == userId);

                viewModel.IsFollowing = _context.Followings
                                        .Any(f => f.FolloweeId == gig.ArtistId && f.FollowerId == userId);
            }
            return(View("Details", viewModel));
        }
Пример #11
0
        public ActionResult Attending()
        {
            var userId = User.Identity.GetUserId();
            var gigs   = _context.Attendances
                         .Where(a => a.AttendeeId == userId)
                         .Select(a => a.Gig)
                         .Include(g => g.Artist)
                         .Include(g => g.Genre)
                         .ToList();

            var attendances = _context.Attendances
                              .Where(a => a.AttendeeId == userId && a.Gig.DateTime > DateTime.Now)
                              .ToList()
                              .ToLookup(a => a.GigId);

            var viewModel = new GigViewModel
            {
                UpcomingGigs = gigs,
                ShowActions  = User.Identity.IsAuthenticated,
                Heading      = "Gigs I'm Attending",
                Attendances  = attendances
            };

            return(View("Gigs", viewModel));
        }
Пример #12
0
        public ActionResult Edit(int gigId)
        {
            var gig = _unitOfWork.Gigs.GetGigById(gigId);

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

            if (gig.ArtistId != User.Identity.GetUserId())
            {
                return(new HttpUnauthorizedResult());
            }
            var gigViewModel = new GigViewModel()
            {
                Date    = gig.DateTime.ToString("d MMM yyyy"),
                Time    = gig.DateTime.ToString("HH:mm"),
                Venue   = gig.Venue,
                Id      = gig.Id,
                Genre   = gig.GenreId,
                Genres  = _unitOfWork.Genres.GetGenres(),
                Heading = "Edit Gig"
            };

            return(View("GigForm", gigViewModel));
        }
Пример #13
0
        public ActionResult Index(string SearchTerm = null)
        {
            var upcomingGigs = _context.Gigs
                               .Include(g => g.Artist)
                               .Include(g => g.Genre)
                               .Where(g => g.DateTime > DateTime.Now && !g.IsCanceled);

            if (!string.IsNullOrWhiteSpace(SearchTerm))
            {
                upcomingGigs = upcomingGigs
                               .Where(g => g.Artist.Name.Contains(SearchTerm) ||
                                      g.Genre.Name.Contains(SearchTerm) ||
                                      g.Venue.Contains(SearchTerm));
            }

            var userid      = User.Identity.GetUserId();
            var attendances = _attendanceRepository.GetFutureAttendances(userid)
                              .ToLookup(a => a.GigId);

            var viewmodel = new GigViewModel
            {
                Gigs        = upcomingGigs,
                Attendances = attendances
            };


            return(View(viewmodel));
        }
Пример #14
0
        public ActionResult index(string query = null)
        {
            var upComingGig = _unitOfWork.Gigs.GetFutureGig();

            if (!string.IsNullOrWhiteSpace(query))
            {
                upComingGig = upComingGig.Where(g => g.Genre.Name.Contains(query) ||
                                                g.Artist.Name.Contains(query) ||
                                                g.Venue.Contains(query)).ToList();
            }

            string userId = User.Identity.GetUserId();



            GigViewModel model = new GigViewModel()
            {
                UpComingGigs = upComingGig,
                ShowActions  = User.Identity.IsAuthenticated,
                Heading      = "Upcoming Gig ",
                SearchTerm   = query,
                Attendances  = _unitOfWork.Attendaces.GetFutureAttandance(userId).
                               ToLookup(g => g.GigId)

                               /*_attendaceRepository.GetFutureAttandance(userId).
                                *        ToLookup(g => g.GigId)*/
            };



            return(View("Gigs", model));
        }
Пример #15
0
        public ActionResult Update(GigViewModel 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.Attendances
                               .Select(a => a.Attendee))
                      .Single(g => g.Id == viewModel.Id && g.ArtistId == userId);

            //update
            gig.Update(viewModel.DateTime, viewModel.Genre, viewModel.Venue);
            gig.Venue    = viewModel.Venue;
            gig.GenreId  = viewModel.Genre;
            gig.DateTime = viewModel.DateTime;

            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gigs"));
        }
Пример #16
0
        public async Task <bool> CreateGigAsync(GigViewModel model, bool isArtist)
        {
            var entity =
                new Gig()
            {
                OwnerId    = _userId,
                Date       = model.Date,
                PostalCode = model.PostalCode
            };

            if (isArtist)
            {
                entity.IsRequest = false;
            }
            else
            {
                entity.IsRequest = true;
            }

            using (var context = new ApplicationDbContext())
            {
                context.Gigs.Add(entity);
                return(await context.SaveChangesAsync() == 1);
            }
        }
Пример #17
0
        public ActionResult Create()
        {
            var viewModel = new GigViewModel();

            viewModel.Genres = _context.Genres.ToList();

            return(View(viewModel));
        }
Пример #18
0
        public IActionResult Create()
        {
            var gigsViewModel = new GigViewModel()
            {
                Genres = GetGenres().GetAwaiter().GetResult()
            };

            return(View(gigsViewModel));
        }
Пример #19
0
        public ActionResult Create()
        {
            GigViewModel model = new GigViewModel
            {
                Genres = _context.Genre.ToList()
            };

            return(View(model));
        }
Пример #20
0
        public IActionResult Create()
        {
            var gigViewModel = new GigViewModel()
            {
                Genres = _context.Genres.ToList()
            };

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

            return(View("GigForm", viewModel));
        }
Пример #22
0
        public ActionResult Create()
        {
            var gigVM = new GigViewModel()
            {
                Genres  = _unitOfWork.Genres.GetGenres(),
                Heading = "Add a Gig"
            };

            return(View("GigForm", gigVM));
        }
Пример #23
0
        public ActionResult Create()
        {
            var ViewModel = new GigViewModel
            {
                Genres  = _unitofWork.Genres.GetAll(),
                Heading = "Create Gig"
            };

            return(View("GigForm", ViewModel));
        }
Пример #24
0
        public ActionResult Create()
        {
            var viewModel = new GigViewModel
            {
                Genres  = _unitOfWork.Genre.GetAllGenres(),
                Heading = "Add a Gig"
            };

            return(View("GigForm", viewModel));
        }
Пример #25
0
        public ActionResult Index()
        {
            var viewModel = new GigViewModel
            {
                Gig   = _context.Gigs.ToList(),
                Genre = _context.Genres.ToList()
            };

            return(View(viewModel));
        }
Пример #26
0
        private List<GigViewModel> MakeViewModels(IEnumerable<Gig> gigs)
        {
            List<GigViewModel> models = new List<GigViewModel>();

            foreach (Gig gig in gigs)
            {
                GigViewModel model = new GigViewModel { Date = gig.Date, Id = gig.Id, Name = gig.Name };
                models.Add(model);
            }

            return models;
        }
Пример #27
0
        public ActionResult Attending()
        {
            var userid = User.Identity.GetUserId();


            var viewmodel = new GigViewModel
            {
                Gigs        = _unitOfWork.Gigs.GetGigsUserAttending(userid),
                Attendances = _unitOfWork.Attendances.GetFutureAttendances(userid)
                              .ToLookup(a => a.GigId)
            };

            return(View(viewmodel));
        }
Пример #28
0
        public ActionResult Index()
        {
            var upcomingGigs = _context.Gigs
                               .Include(g => g.Artist)
                               .Include(g => g.Genre)
                               .Where(g => g.DateTime > DateTime.Now);
            GigViewModel homeModel = new GigViewModel
            {
                UpComingGigs = upcomingGigs,
                ShowAction   = User.Identity.IsAuthenticated
            };

            return(View("Gigs", homeModel));
        }
Пример #29
0
        public ActionResult Attending()
        {
            string userId = User.Identity.GetUserId();

            var viewModel = new GigViewModel
            {
                UpcomingGigs = _unitOfWork.Gigs.GetGigUserAttending(userId),
                ShowActions  = User.Identity.IsAuthenticated,
                Heading      = "Gigs I'm attending",
                Attendaces   = _unitOfWork.Attendance.GetFutureAttendance(userId).ToLookup(a => a.GigId)
            };

            return(View("Gigs", viewModel));
        }
Пример #30
0
        public ActionResult Attending()
        {
            var userId = User.Identity.GetUserId();
            var gigs   = _context.Attendances.
                         Where(a => a.AttendeeId == userId).Select(a => a.Gig)
                         .Include(g => g.Artist)
                         .Include(g => g.Genre);
            var gigAttendingView = new GigViewModel
            {
                UpComingGigs = gigs,
                ShowAction   = User.Identity.IsAuthenticated
            };

            return(View("Gigs", gigAttendingView));
        }
Пример #31
0
        public IHttpActionResult Post(GigViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateGigService();

            if (!service.CreateGig(model))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #32
0
        private List<GigViewModel> makeViewModels(IEnumerable<Gig> gigs)
        {
            List<GigViewModel> gigViewModels = new List<GigViewModel>();

            foreach (Gig gig in gigs)
            {
                GigViewModel model = new GigViewModel {Id = gig.Id, Date = gig.Date};
                if (gig.Private)
                {
                    model.Name = "Private Booking";
                    model.ShowDetailsLink = false;
                }
                else
                {
                    model.Name = gig.Name;
                    model.ShowDetailsLink = true;
                }
                gigViewModels.Add(model);
            }

            return gigViewModels;
        }