Example #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 WebVideoCommentDto
     {
         VideoID = id,
         Content = content,
         ParentID = parentid ?? 0,
         UserID = CurrentUser.ID
     };
     var result = _comment.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,
             VideoID = id
         });
     }
     return JsonMsg(false, Msg.CommentError);
 }
 public VideoComment Add(WebVideoCommentDto model)
 {
     var entity = Mapper.Map<VideoComment>(model);
     entity.CreateTime = DateTime.Now;
     //如果为回复别人的 分页数则为父级分页数
     if (entity.ParentID > 0)
     {
         var parent = _videoCommentRepository.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 = _videoCommentRepository.GetCount(t => t.VideoID == entity.VideoID && t.ParentID == 0);
             entity.PageIndex = pageCount / 15 + 1;
             entity.TopParentID = 0;
         }
     }
     else//否则计算出分页数
     {
         var pageCount = _videoCommentRepository.GetCount(t => t.VideoID == entity.VideoID && t.ParentID == 0);
         entity.PageIndex = pageCount / 15 + 1;
         entity.TopParentID = 0;
     }
     int count = GetCount(model.VideoID);
     entity.Floor = count;
     var result = _videoCommentRepository.Insert(entity);
     if (result<=0)
     {
         //如果添加失败 回滚总数
         UpdateTotleCount(entity.VideoID);
     }
     else
     {
         Task.Factory.StartNew(() =>
         {
             _videoRepository.UpdateRelpayCount(entity.VideoID);
             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;
 }