コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }