public async Task <SaveFileCommandResponse> SaveAsync(SaveFileCommand command) { var user = await userContext.GetCurrentUserAsync(); var dataSize = await dbContext.Files.Where(x => x.UserId == user.Id).SumAsync(x => (double)x.Size / 1048576); if (dataSize + (double)command.Stream.Length / 1048576 > 100) { return(null); } var putResult = await objectStorage.PutAsync( new Models.ObjectPutParams { ContentType = command.ContentType, FileName = command.Name }, command.Stream); var file = new File { Address = putResult.Key, Name = command.Name, Size = (int)command.Stream.Length, ContentType = command.ContentType, UserId = user.Id }; await dbContext.Files.AddAsync(file); await dbContext.SaveChangesAsync(); return(new SaveFileCommandResponse { Id = file.Id, ContentType = file.ContentType, Name = file.Name, Size = file.Size }); }