Beispiel #1
0
        /// <summary>
        ///add new comment to post
        /// </summary>
        /// <param name="comment"></param>
        public async Task <IHttpActionResult> AddComment(CommentModel comment)
        {
            comment.UserID    = CurrentUser.UserID;
            comment.CreatedOn = DateTime.Now;
            ModelState.Remove("post.PostedBy");
            ModelState.Remove("post.PostedDate");
            comment.PostedByName   = CurrentUser.FullName;
            comment.PostedByAvatar = CurrentUser.ProfilePicture;

            if (ModelState.IsValid)
            {
                try
                {
                    BroadcastComment model = _post.AddComment(comment);
                    await _broadcaster.AddComment(model, comment.broadCastType);

                    return(Ok(model.Comment));
                }
                catch (Exception ex)
                {
                    Logs.Error("Error adding comment to post", ex);
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest(ModelState.JsonValidation()));
            }
        }
        /// <summary>
        /// broadcast comment to post
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private async Task BroadcastAddCommentToWeb(BroadcastComment model)
        {
            IList <string> connectionIDs = _user.GetFollowerListByConnectID(model.Comment.UserID, Enums.PageType.Profile, Enums.FriendshipStatus.FA)
                                           .Where(x => x.ConnectedBy == (byte)Enums.BroadCastType.Web).Select(x => x.ConnectionID).ToList();

            await _postBroadCaster.Clients.Clients(connectionIDs)
            .addComment(model.Comment, model.Notification);
        }
Beispiel #3
0
        public List <BroadcastComment> Delete([FromBody] BroadcastComment comment)
        {
            int  broadcastID = comment.BroadcastID;
            bool delete      = DB.ExecuteCommand("DELETE FROM Comments WHERE CommentID = @CommentID AND BroadcastID=@BroadcastID",
                                                 (cmd) => {
                cmd.Parameters.AddWithValue("@CommentID", comment.CommentID);
                cmd.Parameters.AddWithValue("@BroadcastID", comment.BroadcastID);
            }) == 1;

            if (delete)
            {
                return(GetCommentsByBroadcast(broadcastID));
            }

            return(null);
        }
        /// <summary>
        /// Select a broad casting way to new comment to a post
        /// </summary>
        /// <param name="post"></param>
        public async Task AddComment(BroadcastComment model, Enums.BroadCastType BroadCastType)
        {
            try
            {
                switch (BroadCastType)
                {
                case Enums.BroadCastType.Web:
                    await BroadcastAddCommentToWeb(model);

                    break;
                }
            }
            catch (Exception ex)
            {
                ExceptionService.LogError("Error broadcasting comment to post", ex);
            }
        }
Beispiel #5
0
        public List <BroadcastComment> AddComment([FromBody] BroadcastComment comment)
        {
            int  broadcastID = comment.BroadcastID;
            bool insert      = DB.ExecuteCommand("INSERT INTO Comments( BroadcastID, UserEmail, Username, Comment, CreateAt) VALUES ( @BroadcastID, @UserEmail, @Username, @Comment, @CreateAt)",
                                                 (cmd) => {
                cmd.Parameters.AddWithValue("@BroadcastID", comment.BroadcastID);
                cmd.Parameters.AddWithValue("@UserEmail", comment.UserEmail);
                cmd.Parameters.AddWithValue("@Username", comment.Username);
                cmd.Parameters.AddWithValue("@Comment", comment.Comment);
                cmd.Parameters.AddWithValue("@CreateAt", DateTime.Now);
            }) == 1;

            if (insert)
            {
                return(GetCommentsByBroadcast(broadcastID));
            }

            return(null);
        }