Beispiel #1
0
 public JsonResult Comment(int id, string content, int? parentid)
 {
     if (id <= 0 || string.IsNullOrEmpty(content))
         return JsonMsg(false, Msg.ArgumentError);
     var data = new WebGameCommentDto
     {
         GameID = id,
         Content = content,
         ParentID = parentid ?? 0,
         UserID = CurrentUser.ID
     };
     var result = _gameComment.Add(data);
     if (result.ID > 0)
     {
         return Json(new
         {
             Result = true,
             CreateTime = result.CreateTime.ToString("yyyy-mm-dd HH:mm:ss"),
             Floor = result.Floor,
             ID = result.ID,
             ParentID = result.ParentID,
             Comment_UserId = CurrentUser.ID,
             UserName = CurrentUser.UName,
             UserAvatar = CurrentUser.Image,
             Content = content,
             GameID = id
         });
     }
     return JsonMsg(false, Msg.CommentError);
 }
Beispiel #2
0
        public GameComment Add(WebGameCommentDto model)
        {
            var entity = Mapper.Map<GameComment>(model);
            entity.CreateTime = DateTime.Now;
            //如果为回复别人的 分页数则为父级分页数
            if (entity.ParentID > 0)
            {
                var parent = _gameCommentRepository.GetModel(t => t.ID == entity.ParentID);
                if (parent != null && parent.ID > 0)
                {
                    entity.PageIndex = parent.PageIndex;
                    entity.TopParentID = parent.TopParentID == 0 ? parent.ID : parent.TopParentID;
                }
                else
                {
                    var pageCount = _gameCommentRepository.GetCount(t => t.GameID == entity.GameID && t.ParentID == 0);
                    entity.PageIndex = pageCount / 15 + 1;
                    entity.TopParentID = 0;
                }
            }
            else//否则计算出分页数
            {
                var pageCount = _gameCommentRepository.GetCount(t => t.GameID == entity.GameID && t.ParentID == 0);
                entity.PageIndex = pageCount / 15 + 1;
                entity.TopParentID = 0;
            }
            int count = GetCount(model.GameID);
            entity.Floor = count;
            var result = _gameCommentRepository.Insert(entity);
            if (result <= 0)
            {
                //如果添加失败 回滚总数
                UpdateTotleCount(entity.GameID);

            }
            else
            {
                Task.Factory.StartNew(() =>
                {
                    _gameRepository.UpdateRelpayCount(entity.GameID);
                    if (entity.ParentID > 0)
                    {
                        _messageRemindRepository.Insert(new MessageRemind
                        {
                            UserID = entity.ParentID,
                            Type = (int)ProjectEnum.游戏,
                            IsLook = false,
                            IsDel = false,
                            DataID = result,
                            CreateTime = DateTime.Now
                        });
                    }
                });
            }
            return entity;
        }