예제 #1
0
 public void AddCommentReply(CommentReply comment)
 {
     if (Context.User.Identity.IsAuthenticated)
     {
         comment.time = DateTime.UtcNow;
         comment.postedBy =Context.User.Identity.GetUserId();
         db.CommentReplies.Add(comment);
         db.SaveChanges();
         var ret = db.CommentReplies.Where(x => x.Id == comment.Id).Select(x => new
         {
             description = x.description,
             postedById = x.postedBy,
             postedByName = x.AspNetUser.Email,
             time = x.time,
             imageExtension = x.AspNetUser.dpExtension,
             id = x.Id,
         }).FirstOrDefault();
         Clients.Caller.appendCommentReplyToMe(ret);
         Clients.Others.appendCommentReply(ret);
     }
 }
예제 #2
0
        public async Task<IHttpActionResult> updateCommentReply(CommentReply comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest();
            }
            db.Entry(comment).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #3
0
 public async Task<IHttpActionResult> PostCommentReply(CommentReply comment)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     if (!(HttpContext.Current.Request.IsAuthenticated))
     {
         return BadRequest();
     }
     comment.time = DateTime.UtcNow;
     comment.postedBy = User.Identity.GetUserId();
     db.CommentReplies.Add(comment);
     await db.SaveChangesAsync();
     var ret = db.CommentReplies.Where(x => x.Id == comment.Id).Select(x => new
     {
         description = x.description,
         postedById = x.postedBy,
         postedByName = x.AspNetUser.Email,
         time = x.time,
         imageExtension = x.AspNetUser.dpExtension,
         id = x.Id,
     }).FirstOrDefault();
     return Ok(ret);
 }
예제 #4
0
 public async Task<IHttpActionResult> PostCommentReply(CommentReply comment)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     if (!(HttpContext.Current.Request.IsAuthenticated))
     {
         return BadRequest();
         //return BadRequest("you must be logged in post comment");
     }
     comment.time = DateTime.UtcNow;
     comment.postedBy = User.Identity.GetUserId();
     db.CommentReplies.Add(comment);
     await db.SaveChangesAsync();
     var ret = db.CommentReplies.Where(x => x.Id == comment.Id).Select(x => new
     {
         description = x.description,
         postedById = x.postedBy,
         postedByName = x.AspNetUser.UserName,
         time = x.time,
         id = x.Id,
     }).FirstOrDefault();
     return Ok(ret);
     // return CreatedAtRoute("DefaultApi", new { id = comment.Id }, comment);
 }