public async Task <ActionResult <int> > CreateCustomerAsync([FromBody] CustomersCreateViewModel customersCreateViewModel) { var data = this._mapper.Map <CustomersCreateDto>(customersCreateViewModel); var result = await this._customerService.CreateCustomerAsync(data); return(Ok(result)); }
public ActionResult Create([Bind(Include = "FirstName,LastName,Email,StreetName,StreetNumber,Country,ZipCode")] CustomersCreateViewModel postCustomersCreateViewModel) { if (postCustomersCreateViewModel == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { //Use AutoMapper to copy properties from ViewModel to Entities. Customer customer = Mapper.Map <Customer>(postCustomersCreateViewModel); Address address = Mapper.Map <Address>(postCustomersCreateViewModel); customer.Address = address; _manager.Create(customer); return(RedirectToAction("Index")); } return(View(postCustomersCreateViewModel)); }