public ActionResult Save(Customer customer) { /* if (!ModelState.IsValid) * { * var viewModel = new NewCustomerViewModel * { * Customer = customer, * MembershipTypes = _context.MembershipTypes.ToList() * }; * * return View("New", viewModel); * }*/ if (customer.Id == 0) { _context.Customers.Add(customer); } else { var customerInDb = _context.Customers.SingleOrDefault(c => c.Id == customer.Id); customerInDb.Name = customer.Name; customerInDb.IsScubscribedToNewsletter = customer.IsScubscribedToNewsletter; customerInDb.MembershipType = customer.MembershipType; customerInDb.Birthdate = customer.Birthdate; } _context.SaveChanges(); return(RedirectToAction("Index", "Customer")); }
public CustomerDto CreateCustomer(CustomerDto customerDto) { /* if (!ModelState.IsValid) * { * throw new HttpResponseException(HttpStatusCode.BadRequest); * }*/ var customer = Mapper.Map <CustomerDto, Customer>(customerDto); _context.Customers.Add(customer); _context.SaveChanges(); customerDto.Id = customer.Id; return(customerDto); }
public ActionResult Save(Movie movie) { _Context.Movies.Add(movie); _Context.SaveChanges(); return(RedirectToAction("Index", "Movie")); }