Ejemplo n.º 1
0
        public async Task <Customer> AddCustomer(RequestCustomerUpdateModel requestModel)
        {
            var dbCustomer = new Customer
            {
                CName   = requestModel.CName,
                Address = requestModel.Address,
                Phone   = requestModel.Phone,
                Email   = requestModel.Email
            };

            var createdCustomer = await _customerRepo.AddAsync(dbCustomer);

            return(createdCustomer);
        }
        public async Task <IActionResult> Add([FromBody] CustomerDto customerDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var model = _mapper.Map <CustomerDto, Customer>(customerDto);
                await _customerRepo.AddAsync(model);

                await _customerRepo.SaveAllAsync();

                var output = _mapper.Map <Customer, CustomerResponseDto>(model);
                return(Created($"/api/customers/{model.Id}", output));
            }
            catch (Exception e)
            {
                _log.LogError($"error adding customer {e}");
            }

            return(BadRequest());
        }