public ActionResult <FilmsFullReport> GetFullReport(FilmsFilter filter) { if (!Request.IsAuthorized()) { return(Unauthorized()); } if (filter.FromYear.HasValue && filter.ToYear.HasValue && filter.FromYear > filter.ToYear) { return(BadRequest("FromYear is greater than ToYear")); } var films = Films.Items .Where(film => film.Title.ContainsIgnoreCase(filter.Title)) .Where(film => film.Year > (filter.FromYear ?? 0)) .Where(film => film.Year < (filter.ToYear ?? 3000)) .Select(film => new FilmFullData { ID = film.ID, Title = film.Title, Year = film.Year, Budget = Assignments.ByFilm(film.ID) .Select(x => Employees.Get(x.EmployeeId)) .Sum(x => x.Salary), Stuff = Assignments.ByFilm(film.ID) .Select(x => Employees.Get(x.EmployeeId)) .Select(x => new Stuff { Role = x.Role.ToString(), Name = x.Name, Costs = x.Salary }).ToArray() }).ToArray(); var result = new FilmsFullReport { Count = films.Length, Budget = films.Sum(film => film.Budget), Data = films }; return(Ok(result)); }