Пример #1
0
        private ListUserDTO TODTO(UserEntity en)
        {
            ListUserDTO dto = new ListUserDTO();

            dto.Autograph       = en.Autograph;
            dto.City            = en.City;
            dto.CreateTime      = en.CreateTime;
            dto.Email           = en.Email;
            dto.Gender          = en.Gender;
            dto.HeadImgSrc      = en.HeadImgSrc;
            dto.Id              = en.Id;
            dto.NickName        = en.NickName;
            dto.LoginErrorTime  = en.LoginErrorTime;
            dto.IsActive        = en.IsActive;
            dto.LoginErrorCount = en.LoginErrorCount;
            return(dto);
        }
        public async Task <IActionResult> Comment(AddCommentModel model)
        {
            long userId = Convert.ToInt64(HttpContext.Session.GetString(ConstList.USERID));

            model.CommentUserId = userId;
            var replyUserId = await UserSvc.GetByIdAsync(model.ReplyUserId);

            if (replyUserId == null)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "您所回复的用户不存在"
                }));
            }
            if (await CommentSvc.AddNewAsync(model) < 1)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = CommentSvc.ErrorMsg
                }));
            }
            ListUserDTO commentUser = await UserSvc.GetByIdAsync(userId);

            ListContentPostDTO post;

            if (RedisHelper.Exists($"postDetail_{model.PostId}"))
            {
                post = JsonConvert.DeserializeObject <ListContentPostDTO>(await RedisHelper.GetAsync($"postDetail_{model.PostId}"));
            }
            else
            {
                post = await PostSvc.GetByIdAsync(model.PostId);

                await RedisHelper.SetAsync($"postDetail_{model.PostId}", post);
            }
            MessageModel msg = new MessageModel();

            msg.CommentUserName = commentUser.NickName;
            msg.PostId          = model.PostId;
            msg.ReplyUserId     = model.ReplyUserId;
            msg.PostTitle       = post.Title;
            await RedisHelper.SAddAsync($"msg_{model.ReplyUserId}", msg);

            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }