public async Task<IHttpActionResult> updateAnswerReply(AnswerReply 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> PostAnswerReply(AnswerReply question) { if (User.Identity.IsAuthenticated) { if (!ModelState.IsValid) { return BadRequest("Invalid model state"); } question.time = DateTime.UtcNow; question.postedBy = User.Identity.GetUserId(); db.AnswerReplies.Add(question); await db.SaveChangesAsync(); var ret =await db.AnswerReplies.Where(x => x.Id == question.Id).Select(x => new { id = x.Id, description = x.description, postedById = x.AspNetUser.Id, postedByName = x.AspNetUser.UserName, time = x.time }).FirstOrDefaultAsync(); return Ok(ret); } return BadRequest("Not login"); }