コード例 #1
0
        public async Task<IHttpActionResult> updateAnswer(Answer comment)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest();
            }
            db.Entry(comment).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
 public async Task<IHttpActionResult> PostAnswer(Answer question)
 {
     if (User.Identity.IsAuthenticated)
     {
         if (!ModelState.IsValid)
         {
             return BadRequest("Invalid model state");
         }
         question.time = DateTime.UtcNow;
         question.postedBy = User.Identity.GetUserId();
         db.Answers.Add(question);
         await db.SaveChangesAsync();
         var ret = db.Answers.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
         }).FirstOrDefault();
         return Ok(ret);
     }
     else
     {
         return BadRequest("Not login");
     }
 }