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); } }
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); }
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); }
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); }