Exemplo n.º 1
0
        public async Task <IActionResult> Update(CustomerUpdateViewModel model)
        {
            try
            {
                var customer = new CustomerUpdateDTO
                {
                    CusId       = model.CusId,
                    FullName    = model.FullName,
                    Address     = model.Address,
                    PhoneNumber = model.PhoneNumber,
                    Gender      = model.Gender,
                    Email       = model.Email
                };


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

                _toastNotification.AddSuccessToastMessage("Updated to :- " + customer.FullName);
            }
            catch (Exception ex)
            {
                _toastNotification.AddErrorToastMessage(ex.Message);
            }

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Update(CustomerUpdateViewModel model)
        {
            try
            {
                var CustomerDto = new CustomerUpdateDTO
                {
                    CusId       = model.CusId,
                    FullName    = model.FullName,
                    Address     = model.Address,
                    PhoneNumber = model.PhoneNumber,
                    Gender      = model.Gender,
                    Email       = model.Email
                };

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

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

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