Exemplo n.º 1
0
        public async Task <bool> CreateMusicSharingComment(string Musicid, SharingComments comments)
        {
            var MusicCommentRootExistsFilter = Builders <MusicComments> .Filter.Eq(r => r.Musicid, Musicid);

            var finder = await _context.MusicComments.FindAsync(MusicCommentRootExistsFilter);

            var music = await finder.FirstOrDefaultAsync();

            if (music != null)
            {
                var inserter = Builders <MusicComments> .Update.Push("comments", comments);

                var result = await _context.MusicComments.UpdateOneAsync(MusicCommentRootExistsFilter, inserter);

                return(comments._id != null);
            }
            else
            {
                // Need to create a new MusicComments record.

                var MusicCommentRoot = new MusicComments
                {
                    Musicid  = Musicid,
                    Comments = new [] { comments }
                };

                await _context.MusicComments.InsertOneAsync(MusicCommentRoot);

                return(MusicCommentRoot._id != null);
            }
        }
Exemplo n.º 2
0
        public async Task <CommonResponse> PostSharingComment(string Musicid, SharingComments comments)
        {
            comments._id      = ObjectId.GenerateNewId();
            comments.Comments = new ReplyComments[0]; // 默认没有回复,避免客户端忘了初始化值。
            comments.Like     = new string[0];
            comments.Time     = (int)DateUtil.NowToUnix();
            var result = await _sharing.CreateMusicSharingComment(Musicid, comments);

            return(new CommonResponse {
                StatusCode = result ? 0 : -1
            });
        }
Exemplo n.º 3
0
 public async Task <JsonResult> PostSharingComment([FromQuery] string musicid, [FromBody] SharingComments comment)
 {
     return(new JsonResult(await _sharing.PostSharingComment(musicid, comment)));
 }