Exemplo n.º 1
0
        public ActionResult Index(string query = null)
        {
            var upcomingGigs = _contex.Gigs
                               .Include(g => g.Artist)
                               .Include(g => g.Genre)
                               .Include(g => g.Attendances.Select(a => a.Attendee))
                               .Where(g => g.DateTime > DateTime.Now && !g.IsCanceled);

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

            string userId     = User.Identity.GetUserId();
            var    attendance = _attendanceRepository.GetFutureAttendance(userId)
                                .ToLookup(a => a.GigId);


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

            return(View("Gigs", viewModel));
        }
Exemplo n.º 2
0
        public void GetFutureAttendance_ThereIsNotFutureAttandanceForGivenUser_ShouldNotBeReturned()
        {
            string userId = "1";
            var    gig    = new Gig()
            {
                DateTime = DateTime.Now.AddDays(-1), ArtistId = userId
            };
            var attandance = new Attendance()
            {
                AttendeeId = userId, Gigs = gig
            };

            mockAttandance.SetSource(new[] { attandance });

            var attendances = _attendanceRepository.GetFutureAttendance(userId);

            attendances.Should().BeEmpty();
        }