public ActionResult GetPhotoDetail(int id) { var photos = DatabaseSession .Query <Photo>() .Select(x => new PhotoItemDto { PhotoId = x.PhotoId, InsertedDateTime = x.InsertedDateTime, }) .ToList().OrderBy(x => x.PhotoId).ToList(); var index = photos.IndexOf(photos.Single(x => x.PhotoId == id)); var previousId = index > 0 ? photos[index - 1].PhotoId : (int?)null; var nextId = index < photos.Count - 1 ? photos[index + 1].PhotoId : (int?)null; var viewModel = new PhotoDetailViewModel(); viewModel.PhotoUploadLinkURL = ""; viewModel.PreviousPhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(id)); viewModel.NextPhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(id)); if (previousId.HasValue) { viewModel.HasPreviousPhotoLinkURL = true; viewModel.PreviousPhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(previousId.Value)); } if (nextId.HasValue) { viewModel.HasNextPhotoLinkURL = true; viewModel.NextPhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(nextId.Value)); } viewModel.PhotoViewModel = new PhotoViewModel(DatabaseSession.Get <Photo>(id), "", this); return(View(viewModel)); }
public ActionResult EditPerson(int personId) { if (!Request.IsAjaxRequest()) { return(this.RedirectToAction(x => x.PersonDetails(personId))); } var person = DatabaseSession.Get <Person>(personId); var photos = DatabaseSession.Query <PersonPhoto>().Where(x => x.Person == person).Fetch(x => x.Photo).ToList(); var viewModel = new EditPersonViewModel(); viewModel.POSTUrl = Url.Action("SaveEdit"); viewModel.PersonId = personId; viewModel.FirstName = person.FirstName; viewModel.LastName = person.LastName; viewModel.MiddleName = person.MiddleName; viewModel.Honorific = person.Honorific; viewModel.Suffix = person.Suffix; viewModel.Nickname = person.Nickname; viewModel.Biography = person.Biography; viewModel.DefaultPhotoId = person.Photo.PhotoId; viewModel.Photos = photos.OrderBy(x => x.Photo.InsertedDateTime).ThenBy(x => x.Photo.PhotoId).Select(x => new EditPersonViewModel.Photo { PhotoItemId = x.Photo.PhotoId, PhotoTinyURL = x.Photo.GetTinyFileURL(), PhotoThumbnailURL = x.Photo.GetThumbnailFileURL(), }).ToList(); return(PartialView(viewModel)); }
public ActionResult Admin() { var awardTypes = DatabaseSession.Query <AwardType>().ToList(); return(new ViewModelResult(new AwardTypesViewModel(awardTypes, this.Url))); }
public ActionResult DeletePhoto(int personId, int photoId) { var person = DatabaseSession.Get <Person>(personId); var result = PhotosController.Delete(this, photoId); if (DatabaseSession.Transaction.IsActive) { // reassign photo if we just deleted it if (person.Photo == null || person.Photo.PhotoId == photoId || person.Photo.IsDefaultNoPic()) { person.Photo = DatabaseSession.Query <PersonPhoto>() .Where(x => x.Person == person && x.Photo.PhotoId != photoId) .Take(1) .ToList() .Select(x => x.Photo) .FirstOrDefault() ?? DatabaseSession.Load <Photo>(Photo.NoPic); } } if (result != null) { return(result); } return(new ViewModelResult(new HttpApiResult { HttpStatusCode = HttpStatusCode.OK, Message = "Photo Deleted", RedirectToURL = this.GetURL(c => c.ListPersonPhotos(personId, null)), })); }
public ActionResult ByYear(short?year) { if (!year.HasValue || year > DateTime.Now.Year) { return(this.RedirectToAction(c => c.ByYear(GetMostRecentYear()))); } var awards = DatabaseSession.Query <Award>().Where(x => x.Year == year).Fetch(x => x.Show).Fetch(x => x.Person).Fetch(x => x.AwardType).ToList(); var viewModel = new ByYearViewModel(); viewModel.Year = year.Value; var nextYear = (short)(year.Value + 1); var prevYear = (short)(year.Value - 1); viewModel.NextYearURL = this.GetURL(c => c.ByYear(nextYear)); viewModel.PreviousYearURL = this.GetURL(c => c.ByYear(prevYear)); viewModel.AwardsTable = new AwardsTableViewModel( this.Url , id => "" , awards) { CanEdit = false, //AddItemURL = this.GetURL(c => c.AddAward(personId)), }; return(View(viewModel)); }
public ActionResult List() { var photos = DatabaseSession .Query <Photo>() .ToList(); var recentlyUploaded = photos.OrderByDescending(x => x.InsertedDateTime).ThenByDescending(x => x.PhotoId).Take(10).ToList(); var ran = new Random(); var randomSet = new HashSet <Photo>(); var randomList = new List <Photo>(photos); while (randomSet.Count < 10) { var nextIndex = ran.Next(randomList.Count); var item = randomList[nextIndex]; randomList.Remove(item); randomSet.Add(item); } var viewModel = new ListPhotosViewModel(); viewModel.RecentlyUploaded = recentlyUploaded.Select(x => new ListPhotosViewModel.Photo { PhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(x.PhotoId)), PhotoThumbnailURL = x.GetThumbnailFileURL(), }).ToList(); viewModel.RandomPic = randomSet.Select(x => new ListPhotosViewModel.Photo { PhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(x.PhotoId)), PhotoThumbnailURL = x.GetThumbnailFileURL() }).ToList(); return(new ViewModelResult(viewModel)); }
public void DeletePosition(string symbol) { using (var db = new DatabaseSession()) { var position = db.Query <Position>().FirstOrDefault(p => p.Symbol == symbol); db.Remove(position); } }
public IEnumerable <Position> GetPositions() { using (var db = new DatabaseSession()) { var positions = db.Query <Position>().OrderBy(p => p.Symbol).ToList(); var portfolio = new Portfolio(positions); //This calculates the asset allocation return(portfolio.Positions); } }
public ActionResult List() { var users = DatabaseSession.Query <UserAccount>().ToList(); var listViewModel = new ListViewModel(); listViewModel.IsUserAdmin = this.User.IsInRole(RoleNames.Admin); listViewModel.Users = users.Select(x => new UserAccountViewModel(x, this.Url)).ToList(); return(View(listViewModel)); }
public ActionResult AddAward(int showId) { var show = DatabaseSession.Get <Show>(showId); var awardTypes = DatabaseSession.Query <AwardType>().ToList(); var people = DatabaseSession.Query <Person>().ToList(); var viewModel = new AddAwardViewModel(awardTypes, people, show.Year) { POSTUrl = this.GetURL(c => c.AddAward(showId)), }; return(new ViewModelResult(viewModel)); }
public ActionResult AddAward(int personId) { var person = DatabaseSession.Get <Person>(personId); var awardTypes = DatabaseSession.Query <AwardType>().ToList(); var shows = DatabaseSession.Query <Show>().ToList(); var viewModel = new AddAwardViewModel(awardTypes, shows) { POSTUrl = this.GetURL(x => x.AddAward(personId)), }; return(new ViewModelResult(viewModel)); }
public ActionResult Upload(int showId) { var show = DatabaseSession.Get <Show>(showId); var viewModel = new UploadViewModel(); viewModel.ParentName = show.DisplayTitleWithYear; viewModel.ParentLinkURL = this.GetURL <ShowController>(c => c.ShowDetails(showId)); viewModel.PhotoCount = DatabaseSession.Query <ShowPhoto>().Where(x => x.Show == show).Count(); viewModel.PhotoListLinkURL = Url.GetUrl(ListShowPhotos, showId, (int?)null); viewModel.UploadFormURL = Url.GetUrl(Upload, showId, (PhotosController.UploadPOSTParameters)null); return(new ViewModelResult(viewModel)); }
public ActionResult Upload(int personId) { var person = DatabaseSession.Get <Person>(personId); var viewModel = new UploadViewModel(); viewModel.ParentName = person.Fullname; viewModel.ParentLinkURL = this.GetURL <PersonController>(c => c.PersonDetails(personId)); viewModel.PhotoCount = DatabaseSession.Query <PersonPhoto>().Where(x => x.Person == person).Count(); viewModel.PhotoListLinkURL = Url.GetUrl(ListPersonPhotos, personId, (int?)null); viewModel.UploadFormURL = Url.GetUrl(Upload, personId, (PhotosController.UploadPOSTParameters)null); return(new ViewModelResult(viewModel)); }
public ActionResult ArchiveWelcome() { var stats = DatabaseSession.Query <dynamic>(@" SELECT 'ShowCount' AS [Key], COUNT(*) AS [Value] FROM Show UNION SELECT 'PersonCount' AS [Key], COUNT(*) AS [Value] FROM Person UNION SELECT 'CastCount' AS [Key], COUNT(*) AS [Value] FROM ShowCast UNION SELECT 'CrewCount' AS [Key], COUNT(*) AS [Value] FROM ShowCrew UNION SELECT 'PhotoCount' AS [Key], COUNT(*) AS [Value] FROM Photo "); var aMonthAgo = DateTime.UtcNow.AddMonths(-1).Date; var newShows = DatabaseSession.Query <Show>().Fetch(x => x.Photo).Where(x => x.InsertedDateTime >= aMonthAgo).ToList(); var newPersons = DatabaseSession.Query <Person>().Fetch(x => x.Photo).Where(x => x.InsertedDateTime >= aMonthAgo).ToList(); var newPhotos = DatabaseSession.Query <Photo>().Where(x => x.InsertedDateTime >= aMonthAgo).ToList(); var viewModel = new ArchiveWelcomeViewModel(); viewModel.ShowCount = (int)stats.Single(x => x.Key == "ShowCount").Value; viewModel.PersonCount = (int)stats.Single(x => x.Key == "PersonCount").Value; viewModel.CastCount = (int)stats.Single(x => x.Key == "CastCount").Value; viewModel.CrewCount = (int)stats.Single(x => x.Key == "CrewCount").Value; viewModel.PhotoCount = (int)stats.Single(x => x.Key == "PhotoCount").Value; viewModel.NewShows = newShows.OrderBy(x => x, ShowComparer.ReverseChronologicalShowComparer) .Select(x => new ArchiveWelcomeViewModel.NewShowViewModel { Name = x.DisplayTitle, Year = x.Year.ToString(), LinkUrl = Url.For <ShowController>(c => Url.GetUrl(c.ShowDetails, x.ShowId)), ImageUrl = x.Photo.GetTinyFileURL(), }).ToList(); viewModel.NewPeople = newPersons.OrderBy(x => x.SortableName) .Select(x => new ArchiveWelcomeViewModel.NewPersonViewModel { Name = x.Fullname, LinkUrl = Url.For <PersonController>(c => Url.GetUrl(c.PersonDetails, x.PersonId)), ImageUrl = x.Photo.GetTinyFileURL(), }).ToList(); viewModel.NewPhotos = newPhotos.OrderByDescending(x => x.InsertedDateTime) .Select(x => new ArchiveWelcomeViewModel.NewPhotoViewModel { LinkUrl = Url.GetURL <PhotosController>(c => c.GetPhotoDetail(x.PhotoId)), ImageUrl = x.GetTinyFileURL(), }).ToList(); return(View(viewModel)); }
public void CreatePosition(Position model) { using (var db = new DatabaseSession()) { var existingPosition = db.Query <Position>().FirstOrDefault(p => p.Symbol == model.Symbol); if (existingPosition != null) { existingPosition.Quantity += model.Quantity; } else { db.Add(model); } } }
public ActionResult AddCast(int showId) { if (!Request.IsAjaxRequest()) { return(this.RedirectToAction(x => x.ShowDetails(showId))); } var people = DatabaseSession.Query <Person>().ToList(); var viewModel = new AddCastViewModel(people) { POSTUrl = this.GetURL(x => x.AddCast(showId)), }; return(new ViewModelResult(viewModel)); }
public ActionResult Hunt() { var shows = DatabaseSession.Query <Show>().Where(x => x.Toaster != string.Empty).ToList(); var viewModel = new HuntViewModel(); viewModel.Shows.AddRange(shows.Select(x => new HuntViewModel.Show { ShowId = x.ShowId, ShowName = x.Title, ShowQuarter = x.Quarter, ShowYear = x.Year, Toaster = x.Toaster, })); return(View(viewModel)); }
public ActionResult SortByTitle() { var shows = DatabaseSession.Query <Show>().ToList(); var viewModel = new SortedShowsViewModel(); viewModel.Shows = shows.OrderBy(x => x.Title).Select(x => new SortedShowsViewModel.Show { ShowLinkURL = this.GetURL <ShowController>(c => c.ShowDetails(x.ShowId)), ShowId = x.ShowId, ShowTitle = x.DisplayTitle, ShowQuarter = x.Quarter, ShowYear = x.Year, }).ToList(); return(View(viewModel)); }
public ActionResult AddClubPosition(int personId) { if (!Request.IsAjaxRequest()) { return(this.RedirectToAction(x => x.PersonDetails(personId))); } var person = DatabaseSession.Get <Person>(personId); var positions = DatabaseSession.Query <PersonClubPosition>().Select(x => x.Position).Distinct().ToList(); var viewModel = new AddClubPositionViewModel(positions) { POSTUrl = this.GetURL(x => x.AddClubPosition(personId)), }; return(new ViewModelResult(viewModel)); }
public ActionResult AddCast(int personId) { if (!Request.IsAjaxRequest()) { return(this.RedirectToAction(x => x.PersonDetails(personId))); } var person = DatabaseSession.Get <Person>(personId); var shows = DatabaseSession.Query <Show>().ToList(); var viewModel = new AddCastViewModel(shows) { POSTUrl = this.GetURL(x => x.AddCast(personId)), }; return(new ViewModelResult(viewModel)); }
public ActionResult AddCrew(int showId) { if (!Request.IsAjaxRequest()) { return(this.RedirectToAction(x => x.ShowDetails(showId))); } var people = DatabaseSession.Query <Person>().ToList(); var crewPositions = DatabaseSession.Query <ShowCrew>().Select(x => x.Position).Distinct().ToList(); var viewModel = new AddCrewViewModel(people, crewPositions) { POSTUrl = this.GetURL(x => x.AddCrew(showId)), }; return(new ViewModelResult(viewModel)); }
public ActionResult ListShowPhotos(int showId, int?photoId = null) { var show = DatabaseSession.Get <Show>(showId); if (photoId == null && show.Photo != null && !show.Photo.IsDefaultNoPic()) { return(Redirect(this.GetURL(c => c.ListShowPhotos(showId, show.Photo.PhotoId)))); } var photos = DatabaseSession.Query <ShowPhoto>() .Where(x => x.Show == show).Fetch(x => x.Photo) .ToList(); if (photoId == null && photos.Any()) { return(Redirect(this.GetURL(c => c.ListShowPhotos(showId, photos.First().Photo.PhotoId)))); } var viewModel = new PhotoListViewModel(); viewModel.ParentName = show.DisplayTitleWithYear; viewModel.ParentLinkURL = this.GetURL <ShowController>(c => c.ShowDetails(showId)); viewModel.ShowPhotoUploadControl = User.IsInRole(RoleNames.Contributor) || User.IsInRole(RoleNames.Archivist); viewModel.PhotoUploadLinkURL = Url.GetUrl(Upload, showId); viewModel.Photos = photos .OrderBy(x => x.Photo.InsertedDateTime).ThenBy(x => x.Photo.PhotoId) .Select(x => new PhotoListViewModel.Photo { PhotoLinkURL = this.GetURL(c => c.ListShowPhotos(showId, x.Photo.PhotoId)), PhotoThumbnailURL = x.Photo.GetThumbnailFileURL(), }).ToList(); if (photoId.HasValue) { var photo = photos.SingleOrDefault(x => x.Photo.PhotoId == photoId.Value); if (photo == null) { return(Redirect(this.GetURL(c => c.ListShowPhotos(showId, null)))); } viewModel.CurrentPhotoViewModel = new PhotoViewModel(photo.Photo, this.GetURL(c => c.ListShowPhotos(showId, photoId.Value)), this); } return(View(viewModel)); }
public ActionResult ListPersonPhotos(int personId, int?photoId = null) { var person = DatabaseSession.Get <Person>(personId); if (photoId == null && person.Photo != null && !person.Photo.IsDefaultNoPic()) { return(Redirect(this.GetURL(c => c.ListPersonPhotos(personId, person.Photo.PhotoId)))); } var photos = DatabaseSession.Query <PersonPhoto>() .Where(x => x.Person == person).Fetch(x => x.Photo) .ToList(); if (photoId == null && photos.Any()) { return(Redirect(this.GetURL(c => c.ListPersonPhotos(personId, photos.First().Photo.PhotoId)))); } var viewModel = new PhotoListViewModel(); viewModel.ParentName = person.Fullname; viewModel.ParentLinkURL = this.GetURL <PersonController>(c => c.PersonDetails(personId)); viewModel.ShowPhotoUploadControl = User.IsInRole(RoleNames.Contributor) || User.IsInRole(RoleNames.Archivist); viewModel.PhotoUploadLinkURL = Url.GetUrl(Upload, personId); viewModel.Photos = photos .OrderBy(x => x.Photo.InsertedDateTime).ThenBy(x => x.Photo.PhotoId) .Select(x => new PhotoListViewModel.Photo { PhotoLinkURL = this.GetURL(c => c.ListPersonPhotos(personId, x.Photo.PhotoId)), PhotoThumbnailURL = x.Photo.GetThumbnailFileURL(), }).ToList(); if (photoId.HasValue) { var photo = photos.SingleOrDefault(x => x.Photo.PhotoId == photoId.Value); if (photo == null) { return(Redirect(this.GetURL(c => c.ListPersonPhotos(personId, null)))); } viewModel.CurrentPhotoViewModel = new PhotoViewModel(photo.Photo, this.GetURL(c => c.ListPersonPhotos(personId, photoId.Value)), this); } return(new ViewModelResult(viewModel)); }
public ActionResult HandleFacebookOAuthCallback(string code, string state) { if (code.IsNullOrWhiteSpace()) { return(this.RedirectToAction(c => c.Login())); } // TODO, decrypt redirectURL var redirectURL = string.Empty; if (!string.IsNullOrWhiteSpace(state)) { redirectURL = HttpUtility.UrlDecode(state); } var facebookAccessToken = FacebookAuthentication.ExchangeCodeForAccessToken(Request, FacebookAuthenticationOptions.FromWebConfig(), code); var user = DatabaseSession.Query <UserAccount>().Where(x => x.FacebookId == facebookAccessToken.FacebookID).SingleOrDefault(); if (user == null) { user = new UserAccount(facebookAccessToken); // TODO: redirect to a welcome page to confirm info redirectURL = this.GetURL<> } user.UpdateSeen(); var tokenEntity = user.AddFacebookAccessToken(facebookAccessToken); DatabaseSession.Save(user); DatabaseSession.Flush(); var tokenID = tokenEntity.UserFacebookAccessTokenId; HttpContext.Get <IAuthenticationManager>().SignIn(tokenID.ToString(), FacebookAuthentication.AuthenticationType); if (redirectURL.IsNullOrWhiteSpace()) { redirectURL = "~"; } return(Redirect(redirectURL)); }
private short GetMostRecentYear() { return(DatabaseSession.Query <Award>().OrderByDescending(x => x.Year).Take(1).ToList().Select(x => x.Year).Single()); }
public ActionResult Search(string searchTerm, string searchType) { if (string.IsNullOrWhiteSpace(searchTerm)) { return(Redirect("~")); } searchType = (searchType ?? "all").ToLower(); var viewModel = new SearchResultsViewModel(); viewModel.SearchTerm = searchTerm; var searchTerms = searchTerm.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (searchType == "all" || searchType == "show") { var query = DatabaseSession.Query <Show>() .Fetch(x => x.Photo).AsQueryable(); foreach (var term in searchTerms) { query = query.Where(x => x.Title.Contains(term)); } var shows = query.ToList(); viewModel.Results.AddRange(shows.Select(x => new SearchResultsViewModel.SearchResult { Name = x.Title, Year = x.Year.ToString(), SortField = x.Title, ImageUrl = x.Photo.GetTinyFileURL(), LinkUrl = Url.Action <ShowController>(c => c.ShowDetails(x.ShowId)), })); } if (searchType == "all" || searchType == "peep") { var query = DatabaseSession.Query <Person>() .Fetch(x => x.Photo).AsQueryable(); foreach (var term in searchTerms) { query = query.Where(x => x.LastName.Contains(term) || x.FirstName.Contains(term) || x.Nickname.Contains(term)); } var people = query.ToList(); viewModel.Results.AddRange(people.Select(x => new SearchResultsViewModel.SearchResult { Name = x.Fullname, SortField = x.LastName, ImageUrl = x.Photo.GetTinyFileURL(), LinkUrl = Url.Action <PersonController>(c => c.PersonDetails(x.PersonId)), })); } if (viewModel.Results.Count == 1) { return(Redirect(viewModel.Results[0].LinkUrl)); } ViewBag.SearchTerm = searchTerm; return(View(viewModel)); }
public ActionResult PersonDetails(int personId) { var person = DatabaseSession.Get <Person>(personId); var clubPositions = DatabaseSession.Query <PersonClubPosition>().Where(x => x.Person == person).ToList(); var crew = DatabaseSession.Query <ShowCrew>().Where(x => x.Person == person).Fetch(x => x.Show).ToList(); var cast = DatabaseSession.Query <ShowCast>().Where(x => x.Person == person).Fetch(x => x.Show).ToList(); var awards = DatabaseSession.Query <Award>().Where(x => x.Person == person).Fetch(x => x.Show).Fetch(x => x.AwardType).ToList(); var photos = DatabaseSession.Query <PersonPhoto>().Where(x => x.Person == person).Fetch(x => x.Photo).ToList(); var viewModel = new PersonDetailsViewModel(); viewModel.EditLinkURL = this.GetURL(c => c.EditPerson(personId)); viewModel.ShowPhotoUploadControl = User.IsInRole(RoleNames.Contributor) || User.IsInRole(RoleNames.Archivist); viewModel.PhotoUploadLinkURL = this.GetURL <PersonPhotosController>(c => c.Upload(personId)); viewModel.PhotoLinkURL = this.GetURL <PersonPhotosController>(c => c.ListPersonPhotos(personId, person.Photo.PhotoId)); viewModel.PhotoThumbnailURL = person.Photo.GetThumbnailFileURL(); viewModel.PhotoListLinkURL = this.GetURL <PersonPhotosController>(c => c.ListPersonPhotos(personId, null)); viewModel.FullName = person.Fullname; viewModel.Biography = person.Biography; viewModel.AwardsTable = new AwardsTableViewModel( this.Url , id => this.GetURL(c => c.DeleteAward(personId, id)) , awards) { CanEdit = this.ControllerContext.CanEditPerson(person), AddItemURL = this.GetURL(c => c.AddAward(personId)), }; viewModel.ClubPositionsTable = new ClubPositionsTableViewModel( this.Url , id => this.GetURL(c => c.DeleteClubPosition(personId, id)) , clubPositions) { CanEdit = this.ControllerContext.CanEditPerson(person), AddItemURL = this.GetURL(c => c.AddClubPosition(personId)), }; viewModel.CastRolesTable = new Views.Show.CastRolesTableViewModel( this.Url , id => this.GetURL(c => c.DeleteCast(personId, id)) , cast) { CanEdit = this.ControllerContext.CanEditPerson(person), AddItemURL = this.GetURL(c => c.AddCast(personId)), }; viewModel.CrewPositionsTable = new Views.Show.CrewPositionsTableViewModel( this.Url , id => this.GetURL(c => c.DeleteCrew(personId, id)) , crew) { CanEdit = this.ControllerContext.CanEditPerson(person), AddItemURL = this.GetURL(c => c.AddCrew(personId)), }; viewModel.PhotoCount = photos.Count; viewModel.NewPhotos = photos .OrderByDescending(x => x.InsertedDateTime) .Where(x => x.Photo.PhotoId != person.Photo.PhotoId) .Select(x => new PersonDetailsViewModel.NewPhotosViewModel { PhotoLinkURL = this.GetURL <PersonPhotosController>(c => c.ListPersonPhotos(personId, x.Photo.PhotoId)), PhotoTinyURL = x.Photo.GetTinyFileURL(), }) .Take(4) .ToList(); return(View(viewModel)); }
public ActionResult ShowDetails(int showId) { var orderedShows = DatabaseSession.Query <Show>().ToList().OrderBy(x => x).ToList(); var index = orderedShows.IndexOf(orderedShows.Single(x => x.ShowId == showId)); var previousShowId = index > 0 ? orderedShows[index - 1].ShowId : (int?)null; var nextShowId = index < orderedShows.Count - 1 ? orderedShows[index + 1].ShowId : (int?)null; var show = DatabaseSession.Get <Show>(showId); var crew = DatabaseSession.Query <ShowCrew>().Where(x => x.Show == show).Fetch(x => x.Person).ToList(); var cast = DatabaseSession.Query <ShowCast>().Where(x => x.Show == show).Fetch(x => x.Person).ToList(); var awards = DatabaseSession.Query <Award>().Where(x => x.Show == show).Fetch(x => x.Person).Fetch(x => x.AwardType).ToList(); var relatedPhotos = DatabaseSession.Query <ShowPhoto>().Where(x => x.Show == show).Fetch(x => x.Photo).ToList(); var otherPerformances = DatabaseSession.Query <Show>() .Where(x => x.Title == show.Title && x.ShowId != show.ShowId) .ToList(); var viewModel = new ShowDetailsViewModel(); viewModel.ShowPhotoUploadControl = User.IsInRole(RoleNames.Contributor) || User.IsInRole(RoleNames.Archivist); viewModel.PhotoUploadLinkURL = this.GetURL <ShowPhotosController>(c => c.Upload(showId)); viewModel.PhotoLinkURL = this.GetURL <ShowPhotosController>(c => c.ListShowPhotos(showId, show.Photo.PhotoId)); viewModel.PhotoThumbnailURL = show.Photo.GetThumbnailFileURL(); viewModel.PhotoListLinkURL = this.GetURL <ShowPhotosController>(c => c.ListShowPhotos(showId, null)); viewModel.Title = show.DisplayTitle; viewModel.Author = show.Author; viewModel.Quarter = show.Quarter; viewModel.Year = show.Year; viewModel.FunFacts = show.FunFacts; viewModel.Pictures = show.Pictures; viewModel.Toaster = show.Toaster; viewModel.PreviousShowLinkURL = previousShowId.HasValue ? this.GetURL(c => c.ShowDetails(previousShowId.Value)) : ""; viewModel.NextShowLinkURL = nextShowId.HasValue ? this.GetURL(c => c.ShowDetails(nextShowId.Value)) : ""; viewModel.OtherPerformances = new OtherPerformancesTableViewModel(this.Url, otherPerformances); viewModel.AwardsTable = new AwardsTableViewModel( this.Url , id => this.GetURL(c => c.DeleteAward(showId, id)) , awards) { CanEdit = this.ControllerContext.CanEditShow(show), AddItemURL = this.GetURL(c => c.AddAward(showId)), }; viewModel.CastRolesTable = new CastRolesTableViewModel( this.Url , id => this.GetURL(c => c.DeleteCast(showId, id)) , cast) { CanEdit = this.ControllerContext.CanEditShow(show), AddItemURL = this.GetURL(c => c.AddCast(showId)), }; viewModel.CrewPositionsTable = new CrewPositionsTableViewModel( this.Url , id => this.GetURL(c => c.DeleteCrew(showId, id)) , crew) { CanEdit = this.ControllerContext.CanEditShow(show), AddItemURL = this.GetURL(c => c.AddCrew(showId)), }; viewModel.PhotoCount = relatedPhotos.Count; viewModel.NewPhotos = relatedPhotos .OrderByDescending(x => x.InsertedDateTime) .Where(x => x.Photo.PhotoId != show.Photo.PhotoId) .Select(x => new ShowDetailsViewModel.NewPhotoViewModel { PhotoLinkURL = this.GetURL <ShowPhotosController>(c => c.ListShowPhotos(showId, x.Photo.PhotoId)), PhotoTinyURL = x.Photo.GetTinyFileURL(), }) .Take(4) .ToList(); return(View(viewModel)); }