public async Task <CommentPostResponse> CommentPostAsync(CommentPostRequest request, string userId) { var entity = new PostCommentEntity { PostId = request.PostId, UserId = userId, Comment = request.Comment, CommentDate = DateTime.UtcNow }; var result = await _postRepository.CommentPostAsync(entity); if (!result) { return new CommentPostResponse { StatusCode = (int)HttpStatusCode.Unauthorized } } ; var response = new CommentPostResponse { StatusCode = (int)HttpStatusCode.Created }; return(response); }
public PostCommentEntity AddComment(PostCommentEntity comment, HttpPostedFileBase file) { var upload = new IOHandler("~/Uploads/PostAttachements/"); var name = upload.Save(file); using (var db = new groubel_dbEntities1()) { var newComment = new PostComment { Text = comment.Text, UserId = comment.UserId, Date = DateTime.Now, PostId = comment.PostId, Attachement = name }; db.PostComments.Add(newComment); db.SaveChanges(); comment.Id = newComment.Id; comment.Attachement = name; comment.User = _userService.GetUserById(comment.UserId, comment.UserId); _notificationService.AddNotification(comment.UserId, 0, NotificationTypeEnum.CmmentedOnYourPost, comment.PostId, "", null); return(comment); } }
/// <summary> /// Function get data post by user id and post id /// </summary> /// <param name="databaseName">databaseName</param> /// <param name="collectionName">collectionName</param> /// <param name="userId">userId</param> /// <param name="postId">postId</param> /// <returns>List post data comment</returns> public static PostCommentEntity QueryDocumentsGetPostByUserIdPostId(string databaseName, string collectionName, string userId, string postId) { DocumentClient client; // Create a new instance of the DocumentClient client = new DocumentClient(new Uri(EndpointUri), PrimaryKey); PostCommentEntity entity = client.CreateDocumentQuery <PostCommentEntity>( UriFactory.CreateDocumentCollectionUri(databaseName, collectionName)) .Where(x => x.Author.Id == userId && x.Id == postId).AsEnumerable().Select(i => new PostCommentEntity() { Id = i.Id, Author = i.Author, BaseAuthor = i.BaseAuthor, Content = i.Content, Type = i.Type, Likes = i.Likes, IsDeleted = i.IsDeleted, ImageUrls = string.IsNullOrEmpty(i.ImageUrls) == true ? i.ImageUrls : FileHelper.BaseUrlService() + i.ImageUrls, CreatedDate = i.CreatedDate, UpdatedDate = i.UpdatedDate }).FirstOrDefault(); return(entity); }
private ListPostCommentDTO TODTO(PostCommentEntity entity) { ListPostCommentDTO dto = new ListPostCommentDTO(); dto.CommentUserId = entity.CommonUserId; dto.Content = entity.Content; dto.CreateTime = entity.CreateTime; dto.Id = entity.Id; dto.IsUse = entity.IsUse; dto.PostId = entity.PostId; dto.PostTitle = entity.Post.Title; dto.ReplyUserId = entity.ReplyUserId; dto.PostUserId = entity.Post.UserId; dto.IsKnot = entity.Post.IsKnot; return(dto); }
public async Task <long> AddNewAsync(AddPostCommentDTO dto) { PostCommentEntity entity = new PostCommentEntity(); entity.CommonUserId = dto.CommentUserId; entity.Content = dto.Content; entity.PostId = dto.PostId; entity.ReplyUserId = dto.ReplyUserId; using (PostContext ctx = new PostContext()) { await ctx.PostCommonts.AddAsync(entity); await ctx.SaveChangesAsync(); return(entity.Id); } }
public PostCommentModel ToModel(PostCommentEntity entity) { var model = new PostCommentModel { Id = entity.Id, PostId = entity.PostId, Comment = entity.Comment, CommentDate = entity.CommentDate, UserId = entity.UserId }; if (entity.User == null) { return(model); } model.UserName = entity.User.UserName; model.UserPhoto = entity.User.Image; return(model); }
public async Task <bool> CommentPostAsync(PostCommentEntity entity) { await _dbContext.PostComments.AddAsync(entity); return(await SaveAsync()); }