public async Task <FileItemDto> CreateFileAsync(UserDto userDto, IFormFile file) { var user = mapper.Map <UserDto, User>(userDto); var primaryFolder = await unitOfWork.StorageItems.GetUserPrimaryFolderAsync(user); if (primaryFolder == null) { throw new ArgumentNullException("User doesn't have primary folder"); } else { try { var formFileContent = await file.ProcessFormFileAsync(fileSizeLimit); var fileItem = file.CreateFileItemFormFile(primaryFolder, user); string fullPath = StorageItemsHelpers.GetStorageItemFullPath(targetPath, fileItem.RelativePath); await fileManager.CreateFileAsync(fullPath, formFileContent); await unitOfWork.StorageItems.AddAsync(fileItem); await unitOfWork.CommitAsync(); var fileDto = mapper.Map <StorageItem, FileItemDto>(fileItem); return(fileDto); } catch (Exception ex) { throw ex; } } }