public async Task <IEnumerable <FailedRequestViewModel> > GetFailedRequests() { var failed = await _requestQueueRepository.GetAll().Where(x => !x.Completed.HasValue).ToListAsync(); var vm = new List <FailedRequestViewModel>(); foreach (var f in failed) { var vmModel = new FailedRequestViewModel { RequestId = f.RequestId, RetryCount = f.RetryCount, Dts = f.Dts, Error = f.Error, FailedId = f.Id, Type = f.Type }; if (f.Type == RequestType.Movie) { var request = await _movieRequestRepository.Find(f.RequestId); vmModel.Title = request.Title; vmModel.ReleaseYear = request.ReleaseDate; } if (f.Type == RequestType.Album) { var request = await _musicRequestRepository.Find(f.RequestId); vmModel.Title = request.Title; vmModel.ReleaseYear = request.ReleaseDate; } if (f.Type == RequestType.TvShow) { var request = await _tvRequestRepository.GetChild().Include(x => x.ParentRequest).FirstOrDefaultAsync(x => x.Id == f.RequestId); vmModel.Title = request.Title; vmModel.ReleaseYear = request.ParentRequest.ReleaseDate; } vm.Add(vmModel); } return(vm); }