コード例 #1
0
        public Comment_vm GetCm_Vm(CommentRequest cmRequest)
        {
            var cm = _context.Comment.OrderByDescending(x => x.Id).
                     FirstOrDefault(x => x.Content.Contains(cmRequest.Content) &&
                                    x.UserId == cmRequest.UserId);
            var us    = _context.AppUser.FirstOrDefault(x => x.Id == cm.UserId);
            var cm_vm = new Comment_vm
            {
                Id            = cm.Id,
                Content       = cm.Content,
                CreateDate    = cm.CreateDate,
                UserId        = cm.UserId,
                CommentId     = cm.CommentId,
                VideoId       = cm.VideoId,
                ReplyFor      = cm.ReplyFor,
                Like          = cm.Like,
                DisLike       = cm.DisLike,
                Avartar       = us.Avartar,
                FirtsName     = us.FirtsName,
                LastName      = us.LastName,
                LoginExternal = us.LoginExternal
            };

            return(cm_vm);
        }
コード例 #2
0
        public List <Comment_vm> GetAll_vm(List <AppUser> user, List <Comment> comments)
        {
            List <Comment_vm> listCm_vm = new List <Comment_vm>();

            var list = from cm in comments
                       join us in user on cm.UserId equals us.Id
                       select new
            {
                cm,
                us
            };

            foreach (var item in list)
            {
                var cm_vm = new Comment_vm();
                cm_vm.Id            = item.cm.Id;
                cm_vm.Content       = item.cm.Content;
                cm_vm.CreateDate    = item.cm.CreateDate;
                cm_vm.UserId        = item.cm.UserId;
                cm_vm.CommentId     = item.cm.CommentId;
                cm_vm.VideoId       = item.cm.VideoId;
                cm_vm.Like          = item.cm.Like;
                cm_vm.DisLike       = item.cm.DisLike;
                cm_vm.Avartar       = item.us.Avartar;
                cm_vm.FirtsName     = item.us.FirtsName;
                cm_vm.LastName      = item.us.LastName;
                cm_vm.ReplyFor      = item.cm.ReplyFor;
                cm_vm.LoginExternal = item.us.LoginExternal;
                listCm_vm.Add(cm_vm);
            }
            return(listCm_vm);
        }
コード例 #3
0
 public async Task <int> CreateNotifiComment(Comment_vm video_user, Comment comment_fromUser, Video video)
 {
     if (video_user != null && comment_fromUser != null && video != null)
     {
         var user = _context.AppUser.FirstOrDefault(X => X.Id == video_user.UserId);
         if (user != null)
         {
             var notifi = new Notification();
             notifi.AvartarUser   = user.Avartar;
             notifi.UserId        = video_user.UserId;
             notifi.FromUserId    = comment_fromUser.UserId;
             notifi.LoginExternal = user.LoginExternal;
             notifi.PoterImg      = video.PosterImg;
             notifi.Content       = ": Đã trả lời bình luận " + comment_fromUser.Content + " của bạn";
             notifi.VideoId       = video.Id;
             notifi.Status        = true;
             notifi.CreateDate    = new GetDateNow().DateNow;
             notifi.UserName      = user.FirtsName + " " + user.LastName;
             _context.Notification.Add(notifi);
             return(await _context.SaveChangesAsync());
         }
     }
     return(-1);
 }