예제 #1
0
 public IActionResult PutById([FromRoute] int id, [FromBody] Note entity)
 {
     try
     {
         var oriNote = _dbContext.Note.SingleOrDefault(note => note.Id == id);
         if (oriNote != null)
         {
             entity.Id = id;
             _dbContext.Entry(oriNote).CurrentValues.SetValues(entity);
             _dbContext.SaveChanges();
             return(Ok());
         }
         return(BadRequest());
     }
     catch (Exception e)
     {
         TextWriter errorWriter = Console.Error;
         errorWriter.WriteLine(e.Message);
         return(BadRequest());
     }
 }
예제 #2
0
 public IActionResult Put([FromRoute] int id, [FromBody] User entity)
 {
     try
     {
         var oriUser = _dbContext.User.SingleOrDefault(user => user.Id == id);
         if (oriUser != null)
         {
             entity.Id = id;
             _dbContext.Entry(oriUser).CurrentValues.SetValues(entity);
             _dbContext.SaveChanges();
             return(Get(entity.Id));
         }
         return(BadRequest());
     }
     catch (Exception e)
     {
         TextWriter errorWriter = Console.Error;
         errorWriter.WriteLine(e.Message);
         return(BadRequest());
     }
 }