public async Task <PostCommentResponseDto> CreateAndReturnDtoAsync (TransferredResponseToResponseDto responseDto, int authorId, IFormFile file) { string imagePath; if (file != null) { imagePath = await _imageSaver .SaveAndReturnImagePath(file, "ResponseToComment", responseDto.ResponseToCommentId); } var responseToResponse = new ResponseToComment { Comment = new Models.Comment() { Content = responseDto.Content, UserId = authorId, PostId = responseDto.PostId, Date = DateTime.Now }, ResponseToCommentId = responseDto.ResponseToCommentId, MainCommentId = responseDto.MainCommentId }; _unitOfWork.ResponseToCommentRepository .Add(responseToResponse); _unitOfWork.SaveChanges(); return(await _repository.ResponseToComment.GetByIdAsync(responseToResponse.Id, PostCommentResponseDto.Selector(authorId))); }
public async Task <Image> AddEventPhotoAsync(int eventId, IFormFile file) { var path = await _imageSaver.SaveAndReturnImagePath(file, "EventPhotos", eventId); var image = new Image { Path = path, PublishDate = DateTime.Now }; var createdImage = await _repository.Photo.Add(image); await _repository.EventPhoto.Add(eventId, createdImage.Id); return(createdImage); }
public async Task <IActionResult> CreateEventPost( [FromForm(Name = "image")] IFormFile image, [FromForm(Name = "content")] string content, [FromRoute(Name = "eventId")] int eventId, [FromHeader(Name = "userId")] int userId) { var imagePath = await _imageSaver .SaveAndReturnImagePath(image, "EventPost", userId); var newPostDto = await _mediator.Send(new CreateEventPostAndReturnDtoCommand { EventPost = new EventPost { EventId = eventId, Post = new Models.Post { Content = content, ImagePath = imagePath, Date = DateTime.Now } } }); return(Ok(newPostDto)); }
public async Task <UserPostDto> CreateAndReturnAsync(int authorId, string content, IFormFile file) { string imagePath = null; if (file != null) { imagePath = await _imageSaver .SaveAndReturnImagePath(file, "EventPost", authorId); } var userPost = new UserPost { Post = new Models.Post { Content = content, ImagePath = imagePath, Date = DateTime.Now }, UserId = authorId }; _repository.UserPost.Add(userPost); await _repository.SaveAsync(); var post = _repository.UserPost.GetById(userPost.Id); var userPostDto = _mapper.Map <UserPostDto>(post, opt => opt.Items["userId"] = authorId); return(userPostDto); }
public async Task <PostCommentDto> CreateAndReturnMainCommentAsync(NewCommentDto commentDto, int authorId, IFormFile file) { string imagePath; if (file != null) { imagePath = await _imageSaver .SaveAndReturnImagePath(file, "Comment", commentDto.PostId); } var newComment = new MainComment { Comment = new Models.Comment() { PostId = commentDto.PostId, Content = commentDto.Content, Date = DateTime.Now, UserId = authorId } }; _repository.MainComment.CreateMainComment(newComment); await _repository.SaveAsync(); var createdComment = _repository.MainComment.FindById(newComment.Id, PostCommentDto.Selector(authorId)); return(createdComment); }
public async Task <ChatMessage> CreateAndReturnMessageAsync( string text, IFormFile image, int chatId, int authorId, int receiverId) { if (text == null && image == null) { throw new EmptyMessageException(); } if (text == null && image != null) { text = ""; } string imagePath = null; if (image != null) { imagePath = await _imageSaver.SaveAndReturnImagePath(image, "ChatPhoto", chatId); var newImage = new Image { Path = imagePath, PublishDate = DateTime.Now }; await _repository.Photo.Add(newImage); } var newMessage = new ChatMessage { Content = text, ImagePath = imagePath, UserId = authorId, Date = DateTime.Now, ReceiverId = receiverId }; _repository.ChatMessages.Add(chatId, newMessage); await _repository.SaveAsync(); return(newMessage); }