public async Task <IHttpActionResult> Post([FromBody] Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Create _context.Movies.Add(movie); await _context.SaveChangesAsync(); return(CreatedAtRoute(routeName: "DefaultApi", routeValues: new { id = movie.Id }, content: movie)); }
public async Task <ActionResult> Save(Customer customer) { if (!ModelState.IsValid) { CustomerFormViewModel model = new CustomerFormViewModel { Customer = customer, Memberships = await _context.Memberships.ToListAsync() }; return(View("Form", model)); } if (customer.Id == null) { _context.Customers.Add(customer); } else { _context.Entry(customer).State = EntityState.Modified; } await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }