public void AddScreenedFilm(int filmid, string title, string description, ScreenedFilmType screenedFilmType) { var screenedFilm = new ScreenedFilm(filmid, title, description, screenedFilmType); ScreenedFilms.Add(screenedFilm); }
public override string ToString() { var newLine = Environment.NewLine; var twoLines = newLine + newLine; var builder = new StringBuilder(Url + newLine); // If present, add the short description. // Use the version with raw html tags as to allow it to be coverted // to an attributed string. if (RawFilmDescription != string.Empty) { builder.AppendLine(newLine + "Description"); builder.AppendLine(RawFilmDescription); } // Add the more elaborated article. if (FilmArticle != string.Empty) { builder.AppendLine(newLine + "Article"); builder.AppendLine(FilmArticle); } // Add combination programs in which this film is screened. if (CombinationProgramIds.Count > 0) { // Per combination program, find its screened film that matches // the current film and create a list of combination program - // screened film pairs. var combinationScreenedPairs = CombinationProgramIds .Select(i => ViewController.GetFilmById(i)) .SelectMany(cf => cf.FilmInfo.ScreenedFilms .Select(sf => new { cf, sf }) .Where(pair => pair.sf.ScreenedFilmId == FilmId)); // Store each screened film type together with the combination // programs it is paired with. var combinationsByType = new Dictionary <ScreenedFilmType, List <Film> > { }; foreach (var pair in combinationScreenedPairs) { if (!combinationsByType.Keys.Contains(pair.sf.ScreenedFilmType)) { combinationsByType.Add(pair.sf.ScreenedFilmType, new List <Film> { }); } combinationsByType[pair.sf.ScreenedFilmType].Add(pair.cf); } // Per type, add the applicable header and the combination // programs in which this film has that type to the string // builder. var space = newLine; foreach (var screenedFilmType in combinationsByType.Keys) { builder.AppendLine($"{space}{_partByScreenedFilmType[screenedFilmType]}:"); builder.AppendJoin( newLine, combinationsByType[screenedFilmType]); space = twoLines; } } // Add screened films if present. if (ScreenedFilms.Count > 0) { // Create a list of the distinct screened film types in the // screened films. var screenedFilmTypes = ScreenedFilms .Select(sf => sf.ScreenedFilmType) .Distinct(); // Per type, add the applicible header and the screened films // with that type to the string builder. var space = newLine; foreach (var screenedFilmType in screenedFilmTypes) { builder.AppendLine($"{space}{_headerByScreenedFilmType[screenedFilmType]}:"); var screenedFilmsOfType = ScreenedFilms .Where(sf => sf.ScreenedFilmType == screenedFilmType); builder.AppendJoin( twoLines, screenedFilmsOfType.Select(f => f.ToString())); space = twoLines; } // Calculate the average rating of all screened films if // applicable. decimal meanRating = TimeWeightedMeanRating(); if (meanRating != decimal.Zero) { builder.AppendLine($"{twoLines}Time weighted mean rating: {meanRating:0.##}"); } } return(builder.ToString()); }