public async Task <User> SaveImageAsync(User user) { if (user.Img != null) { user.Img = await _azureStorageService.UploadFileToBlobAsync("img", user.Img, "image/jpeg"); } return(_userRepository.Update(user)); }
private async Task <string> UploadFile(IFormFile file) { await using var memoryStream = new MemoryStream(); await file.CopyToAsync(memoryStream); var bytes = memoryStream.ToArray(); var result = await _azureStorageService.UploadFileToBlobAsync(file.FileName, bytes, file.ContentType); return(result); }
public ViewPost Save(int userId, PostDto postDto) { var post = new Post() { UserId = userId }; post = _postRepository.Add(post); var text = new Text() { PostId = post.Id, UserId = userId, Description = postDto.Description }; _textRepository.Add(text); var picture = new Picture() { PostId = post.Id, UserId = userId }; if (postDto.Images != null) { postDto.Images.ForEach(async delegate(string img) { var path = await _azureStorageService.UploadFileToBlobAsync("img", img, "image/jpeg"); Debug.WriteLine("Resim:" + path); picture.Img = path; _pictureRepository.Add(picture); }); } return(GetPost(post.Id)); }