public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.Id) { return(BadRequest()); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
static void Main(string[] args) { using (var context = new TWContext()) { context.Users.Add(new User() { Firstname = "Jakob", Lastname = "Hager", Email = "*****@*****.**", Company = "JS AG", }); context.SaveChanges(); foreach (var user in context.Users) { Console.WriteLine(user.Firstname); } } }