public ActionResult Itinerary(DateTime eventDate, int bandId) { Band band = db.Bands .Include(b => b.Events) .Include(b => b.Tours) .Include("Tours.TourDates") .Include("Tours.TourDates.Venue") .Where(b => b.BandId == bandId) .FirstOrDefault(); string eventsJson = "["; foreach (Event bandEvent in band.Events) { eventsJson += "{"; eventsJson += "\"id\": " + bandEvent.EventId + ","; eventsJson += "\"title\": \"" + bandEvent.Name + "\","; eventsJson += "\"start\": \"" + bandEvent.EventDate.ToString("r") + "\","; eventsJson += "\"description\": \"" + bandEvent.Description + "\""; eventsJson += "},"; } //add all of the tour dates to the list of events too var tours = band.Tours; List <TourDate> tourDates = new List <TourDate>(); foreach (Tour tour in tours) { foreach (TourDate tourDate in tour.TourDates) { tourDates.Add(tourDate); } } foreach (TourDate tourDate in tourDates) { eventsJson += "{"; eventsJson += "\"id\": \"0\","; eventsJson += "\"title\": \"Tour Date: " + tourDate.Venue.Name + "\","; eventsJson += "\"color\": \"#f89406\","; eventsJson += "\"start\": \"" + tourDate.EventDate.ToString("r") + "\","; eventsJson += "\"description\": \"Tour Date at " + tourDate.Venue.Name + "\""; eventsJson += "},"; } eventsJson += "]"; EventItineraryViewModel viewModel = new EventItineraryViewModel(); viewModel.EventsJson = eventsJson; viewModel.BandName = band.Name; viewModel.EventDate = eventDate.ToString("r"); return(View(viewModel)); }
public async Task <IActionResult> EventItinerary(int eventId, int?userId = null) { var evt = await _dbContext.Events.FindAsync(eventId); if (evt == null) { return(NotFound()); } var currentUser = await _userManager.GetUserAsync(User); if (!userId.HasValue) { userId = currentUser.Id; } else if (userId.HasValue && userId != currentUser.Id && evt.OwnerUserId != currentUser.Id) { return(NotFound()); } var user = await _dbContext.Users.FindAsync(userId); var model = new EventItineraryViewModel(); model.Event = evt.ToModel(); model.User = user.ToModel(); model.Sections = await _dbContext.Sections .Where(x => x.EventId == evt.Id) .OrderBy(x => x.StartOn) .ProjectTo <SectionModel>() .ToListAsync(); var userSessionIds = await _dbContext.Registrations .Where(x => x.EventId == eventId && x.UserId == userId) .Select(x => x.SessionId) .ToListAsync(); model.RegisteredSessions = await _dbContext.Sessions .Where(x => userSessionIds.Contains(x.Id)) .ProjectTo <SessionModel>() .ToListAsync(); model.SerializedSessions = JsonConvert.SerializeObject(model.RegisteredSessions); return(View(model)); }