Example #1
0
        public async Task <MusicCommentResult> EditMusicComment(MusicComment model)
        {
            var result = new MusicCommentResult();

            try
            {
                var comment = await db.MusicComments.FindAsync(model.IdComment);

                comment.Comment = model.Comment;
                await db.SaveChangesAsync();

                var user = await db.Users.FindAsync(comment.UserId);

                result.MusicCommentInfo.IdComment       = comment.IdComment;
                result.MusicCommentInfo.Comment         = comment.Comment;
                result.MusicCommentInfo.CommentDate     = comment.CommentDate;
                result.MusicCommentInfo.MusicId         = comment.MusicId;
                result.MusicCommentInfo.ParentIdComment = comment.ParentIdComment;
                result.MusicCommentInfo.UserId          = comment.UserId;
                result.MusicCommentInfo.UserLogin       = user.Login;
                result.MusicCommentInfo.UserAvatar      = user.Avatar;
                result.Result             = true;
                result.CommentChangedType = CommentChangedType.Edited;
            }
            catch
            {
                result.Result = false;
            }
            return(result);
        }
Example #2
0
        public async Task <MusicCommentResult> DeleteMusicComment(Guid musicCommentId)
        {
            var result = new MusicCommentResult();

            try
            {
                var comment = await db.MusicComments.FindAsync(musicCommentId);

                db.MusicComments.Remove(comment);
                var subComments = await FindSubComments(comment.IdComment.Value);

                db.MusicComments.RemoveRange(subComments);
                await db.SaveChangesAsync();

                var user = await db.Users.FindAsync(comment.UserId);

                result.MusicCommentInfo.IdComment       = comment.IdComment;
                result.MusicCommentInfo.Comment         = comment.Comment;
                result.MusicCommentInfo.CommentDate     = comment.CommentDate;
                result.MusicCommentInfo.MusicId         = comment.MusicId;
                result.MusicCommentInfo.ParentIdComment = comment.ParentIdComment;
                result.MusicCommentInfo.UserId          = comment.UserId;
                result.MusicCommentInfo.UserLogin       = user.Login;
                result.MusicCommentInfo.UserAvatar      = user.Avatar;
                result.Result             = true;
                result.CommentChangedType = CommentChangedType.Deleted;
            }
            catch
            {
                result.Result = false;
            }
            return(result);
        }
Example #3
0
        public async Task <MusicCommentResult> CommentOn(MusicComment model)
        {
            var result = new MusicCommentResult();

            try
            {
                model.CommentDate = DateTime.Now;
                db.MusicComments.Add(model);
                db.SaveChanges();
                var user = await db.Users.FindAsync(model.UserId);

                result.MusicCommentInfo.IdComment       = model.IdComment;
                result.MusicCommentInfo.Comment         = model.Comment;
                result.MusicCommentInfo.CommentDate     = model.CommentDate;
                result.MusicCommentInfo.MusicId         = model.MusicId;
                result.MusicCommentInfo.ParentIdComment = model.ParentIdComment;
                result.MusicCommentInfo.UserId          = model.UserId;
                result.MusicCommentInfo.UserLogin       = user.Login;
                result.MusicCommentInfo.UserAvatar      = user.Avatar;
                result.Result             = true;
                result.CommentChangedType = CommentChangedType.Added;
            }
            catch
            {
                result.Result = false;
            }
            return(result);
        }