public ActionResult Save(Customer customer) { if (!ModelState.IsValid) { return(View("CustomerForm")); } if (customer.Id == 0) { customer.MovieLibrary = new List <Movie>(); CustomersMockData.AddCustomer(customer); } else { var customerInDb = CustomersMockData.GetCustomers().Single(c => c.Id == customer.Id); int indexOfCustomer = CustomersMockData.CustomerCollection.IndexOf(customerInDb); customerInDb.Name = customer.Name; customerInDb.IsSubcribedToNewsletter = customer.IsSubcribedToNewsletter; customerInDb.Birthdate = customer.Birthdate; CustomersMockData.CustomerCollection[indexOfCustomer] = customerInDb; } return(RedirectToAction("Index")); }
public Customer CreateCustomer(Customer customer) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } CustomersMockData.AddCustomer(customer); return(customer); }