Example #1
0
 public void UpdateCustomer(UpdateCustomerInput input)
 {
     Logger.Info("Updating a Customer for input:" + input);
     // var customer = _customerRepository.Get(input.Id);
     // if (input.Telephone.Equals)
     //  customer.Sta=_customerRepository.Load()
 }
Example #2
0
        public async Task UpdateCustomer(UpdateCustomerInput input)
        {
            var customer = await _customerRepository.GetAsync(input.Id);

            customer.Name   = input.Name;
            customer.Number = input.Number;
            customer.Phone  = input.Phone;
        }
        public async Task <Customer> UpdateCustomer(int id, UpdateCustomerInput updateCustomerInput)
        {
            try
            {
                Customer _customer = await _customersService.UpdateCustomer(id, updateCustomerInput);

                return(_customer);
            }
            catch (Exception ex)
            {
                throw new QueryException(
                          ErrorBuilder.New()
                          .SetMessage(ex.Message)
                          .SetCode("UPDATE_ERROR")
                          .Build());
            }
        }
        public async Task <OperationResult <CustomerDto> > UpdateCustomerAsync(UpdateCustomerInput input)
        {
            var validationResult = await _customerValidator.ValidateUpdateCustomer(input);

            if (validationResult.IsSuccess)
            {
                var entity = await _customerRepository.GetCustomer(input.Email);

                entity.LastName = input.LastName;
                entity.Name     = input.Name;
                entity.Picture  = input.Picture;

                await _customerRepository.UpdateAsync(entity);

                return(OperationResult <CustomerDto> .Success(entity.ConvertToDto()));
            }

            return(OperationResult <CustomerDto> .Fail(validationResult));
        }
Example #5
0
        //Update customer record
        public async Task <Customer> UpdateCustomer(int id, UpdateCustomerInput updateCustomerInput)
        {
            //check if customer exists
            Customer customer = await db.Customers.FindAsync(id);

            if (customer == null)
            {
                throw new Exception("Customer not found");
            }
            customer.CustomerName    = updateCustomerInput.CustomerName;
            customer.PhysicalAddress = updateCustomerInput.PhysicalAddress;
            customer.Town            = updateCustomerInput.Town;
            customer.PostalCode      = updateCustomerInput.PostalCode;
            customer.Province        = updateCustomerInput.Province;
            customer.Telephone       = updateCustomerInput.Telephone;
            customer.Mobile          = updateCustomerInput.Mobile;
            customer.Email           = updateCustomerInput.Email;

            await db.SaveChangesAsync();

            return(customer);
        }
        public async Task <ValidationResult> ValidateUpdateCustomer(UpdateCustomerInput input)
        {
            ValidationResult validationResult = new();

            if (string.IsNullOrWhiteSpace(input.Email))
            {
                validationResult.Messages.Add(new(nameof(UpdateCustomerInput.Email), "Debe ingresar un email."));
            }
            else if (!input.Email.IsEmail())
            {
                validationResult.Messages.Add(new(nameof(CreateCustomerInput.Email), "Debe ingresar un email valido."));
            }
            else
            {
                Customer customer = await _customerRepository.GetCustomer(input.Email);

                if (customer is null)
                {
                    validationResult.Messages.Add(new(nameof(UpdateCustomerInput.Email), "no existe un cliente con este email."));
                }
            }

            if (string.IsNullOrWhiteSpace(input.Name))
            {
                validationResult.Messages.Add(new(nameof(UpdateCustomerInput.Name), "Debe ingresar un nombre."));
            }
            if (string.IsNullOrWhiteSpace(input.LastName))
            {
                validationResult.Messages.Add(new(nameof(UpdateCustomerInput.Name), "Debe ingresar un apellido."));
            }

            if (input.Picture is null)
            {
                validationResult.Messages.Add(new(nameof(UpdateCustomerInput.Picture), "Debe ingresar una foto de perfil."));
            }

            return(validationResult);
        }
Example #7
0
        public async Task <IActionResult> Update(UpdateCustomerInput input)
        {
            var result = await _service.UpdateCustomerAsync(input);

            return(new OperationActionResult(result));
        }