TVSorter.Model.FileResult.GetEpisodeName C# (CSharp) Method

GetEpisodeName() private method

Gets the name of the episode. Used if there is more than one episode.
private GetEpisodeName ( ) : string
return string
        private string GetEpisodeName()
        {
            // If there is only one episode on the match then return it.
            if (this.Episodes.Count == 1)
            {
                return this.Episode.Name;
            }

            // If the episode names are the same except for a part number at the end then
            // use the same name and just list the part numbers at the end.
            var regex = new Regex(@"\(([0-9]+)\)");
            var episodeNames = (from episode in this.Episodes
                                let match = regex.Match(episode.Name)
                                where match.Success
                                select
                                    new
                                        {
                                            Name = episode.Name.Substring(0, match.Index).Trim(),
                                            Part = match.Groups[1],
                                        }).ToList();

            // If all the episode had a number in brackets at the end of them.
            if (episodeNames.Count == this.Episodes.Count)
            {
                // Ensure that the all the episode names before the number were the same.
                string firstName = episodeNames.First().Name;
                if (episodeNames.All(x => x.Name == firstName))
                {
                    // Return the episode name with the number list in brackets.
                    // e.g Episode Name (1-2)
                    return firstName + " ("
                           + episodeNames.Select(x => x.Part.ToString()).Aggregate((x, y) => x + "-" + y) + ")";
                }
            }

            // The names didn't have numbers or didn't match.
            // Just concatenate all the names together separated with -.
            return this.Episodes.Select(x => x.Name).Aggregate((x, y) => x + "-" + y);
        }