Exemplo n.º 1
0
        public async Task <IActionResult> Create(CustomerCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var customer = new CustomerCreateDTO
                    {
                        PhoneNumber = model.PhoneNumber,
                        FullName    = model.FullName,
                        Email       = model.Email,
                        Gender      = model.Gender,
                        Address     = model.Address
                    };


                    await _customerService.Create(customer).ConfigureAwait(true);

                    _toastNotification.AddSuccessToastMessage("Created:- " + customer.FullName);

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                _toastNotification.AddErrorToastMessage(ex.Message);
            }
            return(View(model));
        }
        public async Task <ActionResult> Create(CustomerCreateViewModel model)
        {
            try
            {
                var CustomerDto = new CustomerCreateDTO
                {
                    PhoneNumber = model.PhoneNumber,
                    FullName    = model.FullName,
                    Email       = model.Email,
                    Gender      = model.Gender,
                    Address     = model.Address
                };


                await _customerService.Create(CustomerDto).ConfigureAwait(true);

                var Customer = await _customerRepo.GetByNumber(CustomerDto.PhoneNumber) ?? throw new CustomerNotFoundException();

                return(Ok(CreateReponseDto(Customer)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }