public async Task <ICollection <FileHistoryDTO> > GetAllForFileAsync(string fileId) { var file = await _fileRepository.GetByIdAsync(fileId); if (file == null) { _logger.LogWarning(LoggingEvents.HaveException, $"Not found file"); throw new NotFoundException(nameof(File), fileId); } var fileHistoriesForFile = await _fileHistoryRepository.GetAllAsync(fh => fh.FileId == file.Id); return(_mapper.Map <ICollection <FileHistoryDTO> >(fileHistoriesForFile)); }
public async Task <IList <FileHistoryListDTO> > GetHistoriesForProject(int projectId) { var filesForProject = await _fileRepository.GetAllAsync(f => f.ProjectId == projectId); var files = new List <FileHistoryListDTO>(); foreach (var file in filesForProject) { var fileHistory = (await _fileHistoryRepository.GetAllAsync(fh => fh.FileId == file.Id)) .OrderByDescending(fh => fh.ChangedAt) .Select(f => _mapper.Map <FileHistoryDTO>(f)) .ToList(); files.Add(new FileHistoryListDTO() { Id = file.Id, FileName = file.Name, History = fileHistory }); } return(files); }