コード例 #1
0
ファイル: CommentsHub.cs プロジェクト: NesQ1kx/active-citizen
        public async Task SendComment(IdeaComment comment)
        {
            try
            {
                if (_projectDal.AddComment(comment))
                {
                    var commentToReturn = new
                    {
                        Id             = comment.Id,
                        CommentText    = comment.CommentText,
                        UserId         = comment.UserId,
                        IdeaId         = comment.IdeaId,
                        CreateDate     = comment.CreateDate,
                        ParrentComment = comment.ParrentComment,
                        User           = _userDal.GetUserById(comment.UserId)
                    };
                    await Clients.All.SendAsync("RecieveComment", JsonConvert.SerializeObject(commentToReturn));

                    await Clients.Caller.SendAsync("SuccessfulAdd");
                }
                else
                {
                    await Clients.Caller.SendAsync("ErrorWhileAdding", "error");
                }
            } catch (Exception e)
            {
                await Clients.Caller.SendAsync("ErrorWhileAdding", e);
            }
        }