public async Task UpdateAsync(FileUpdateDTO fileUpdateDTO, int updaterId) { if (GetStringSize(fileUpdateDTO.Content) > _maxFileSize) { throw new TooHeavyFileException(_maxFileSize); } var currentFileDto = await GetByIdAsync(fileUpdateDTO.Id); var currentFileContent = currentFileDto.Content; currentFileDto.Name = fileUpdateDTO.Name; currentFileDto.Folder = fileUpdateDTO.Folder; currentFileDto.Content = fileUpdateDTO.Content; currentFileDto.UpdaterId = updaterId; currentFileDto.UpdatedAt = DateTime.Now; currentFileDto.IsOpen = fileUpdateDTO.IsOpen; var fileUpdate = _mapper.Map <File>(currentFileDto); await _fileRepository.UpdateAsync(fileUpdate); var searchFile = _mapper.Map <FileSearch>(fileUpdate); await _fileSearchRepository.UpdateAsync(searchFile); var comment = $"File {fileUpdate.Name} was edited"; var fileHistory = await initializeNewFileHistoryDTO(fileUpdate, currentFileContent, comment, updaterId); await _fileHistoryService.CreateAsync(fileHistory); }
public async Task <IActionResult> UpdateAsync([FromBody] FileUpdateDTO fileUpdateDTO) { _logger.LogInformation(LoggingEvents.UpdateItem, $"Updating file {fileUpdateDTO.Id}"); var updaterId = this.GetUserIdFromToken(); await _fileService.UpdateAsync(fileUpdateDTO, updaterId); return(NoContent()); }