public CustomerBase CustomerAdd(CustomerAdd newItem) { //Attempt to add the new item //Notice how we map the incoming data to the design model object var addedItem = ds.Customers.Add(mapper.Map <CustomerAdd, Customer>(newItem)); ds.SaveChanges(); //If successful, return the added item, mapped to a view model object return((addedItem == null) ? null : mapper.Map <Customer, CustomerBase>(addedItem)); }
public ActionResult Create(CustomerAdd newItem) { //Validate the input if (!ModelState.IsValid) { return(View(newItem)); } //process the input var addedItem = m.CustomerAdd(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("details", new { id = addedItem.CustomerId })); } }