public async Task <OperationResult <AddressDto> > UpdateAddressAsync(UpdateAddressInput input)
        {
            var validatioResult = await _addressValidator.ValidateUpdateAddressAsync(input);

            if (validatioResult.IsSuccess)
            {
                var addresses = await _addressRepository.GetByCustomerAsync(input.CustomerEmail);

                var address = input.ConvertToEntity();


                foreach (var e in addresses.Addresses.Where(a => a.Id == input.AddressId))
                {
                    e.Name           = address.Name;
                    e.ZipCode        = address.ZipCode;
                    e.City           = address.City;
                    e.Street         = address.Street;
                    e.Number         = address.Number;
                    e.Depatarment    = address.Depatarment;
                    e.BetweenStreet1 = address.BetweenStreet1;
                    e.BetweenStreet2 = address.BetweenStreet2;
                    e.Observations   = address.Observations;
                    e.Phone          = address.Phone;
                    e.Type           = address.Type;
                    e.CustomerEmail  = address.CustomerEmail;
                }

                await _addressRepository.UpdateAsync(addresses);

                return(OperationResult <AddressDto> .Success(address.ConvertToDto()));
            }

            return(OperationResult <AddressDto> .Fail(validatioResult));
        }
        public void ConvertToEntity_InputNotNull_ReturnSameObservations()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.Observations, address.Observations);
        }
        public void ConvertToEntity_InputNotNull_ReturnSameId()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.AddressId, address.Id);
        }
        public void ConvertToEntity_InputNotNull_ReturnSameNumber()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.Number, address.Number);
        }
        public void ConvertToEntity_InputNotNull_ReturnSameCustomerEmail()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.CustomerEmail, address.CustomerEmail);
        }
        public void ConvertToEntity_InputNotNull_ReturnSameDepatarment()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.Depatarment, address.Depatarment);
        }
        public void ConvertToEntity_InputNotNull_ReturnSameZipCode()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.ZipCode, address.ZipCode);
        }
        public void ConvertToEntity_InputNotNull_ReturnSameBetweenStreet2()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.BetweenStreet2, address.BetweenStreet2);
        }
        public void ConvertToEntity_InputNotNull_ReturnSameStreet()
        {
            UpdateAddressInput input = MockUpdateAddressInput();

            Address address = input.ConvertToEntity();

            Assert.Equal(input.Street, address.Street);
        }
        public async Task UpdateAsync(UpdateAddressInput input)
        {
            var entity = await FindAsync(input.Id);

            entity.Description = input.Description;
            entity.ZipCode     = input.ZipCode;
            entity.Latitude    = input.Latitude;
            entity.Longitude   = input.Longitude;
            entity.CityId      = input.CityId;
            await _context.SaveChangesAsync();
        }
Exemple #11
0
        public async Task <ValidationResult> ValidateUpdateAddressAsync(UpdateAddressInput input)
        {
            ValidationResult validationResult = new();

            if (string.IsNullOrWhiteSpace(input.CustomerEmail))
            {
                validationResult.Messages.Add(new(nameof(UpdateAddressInput.CustomerEmail), "Debe indicar un cliente."));
            }
            else
            {
                Customer customer = await _customerRepository.GetCustomer(input.CustomerEmail);

                if (customer is null)
                {
                    validationResult.Messages.Add(new(nameof(UpdateAddressInput.CustomerEmail), "No existe el cliente."));
                }

                AddressCustomer addressCustomer = await _addressRepository.GetByCustomerAsync(input.CustomerEmail);

                if (addressCustomer is null || addressCustomer.Addresses is null || !addressCustomer.Addresses.Any(x => x.Id == input.AddressId))
                {
                    validationResult.Messages.Add(new(nameof(UpdateAddressInput.AddressId), "La dirección no existe."));
                }
            }

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

            if (string.IsNullOrWhiteSpace(input.ZipCode))
            {
                validationResult.Messages.Add(new(nameof(UpdateAddressInput.ZipCode), "Debe ingresar un código postal."));
            }
            if (string.IsNullOrWhiteSpace(input.City))
            {
                validationResult.Messages.Add(new(nameof(UpdateAddressInput.City), "Debe ingresar una ciudad."));
            }
            if (string.IsNullOrWhiteSpace(input.Street))
            {
                validationResult.Messages.Add(new(nameof(UpdateAddressInput.Street), "Debe ingresar una calle."));
            }

            if (!Enum.IsDefined(input.Type))
            {
                validationResult.Messages.Add(new(nameof(UpdateAddressInput.Type), "El tipo de dirección no es valido."));
            }

            return(validationResult);
        }
Exemple #12
0
 public static Address ConvertToEntity(this UpdateAddressInput source)
 {
     return(new()
     {
         Id = source.AddressId,
         Depatarment = source.Depatarment,
         BetweenStreet1 = source.BetweenStreet1,
         BetweenStreet2 = source.BetweenStreet2,
         City = source.City,
         Name = source.Name,
         Number = source.Number,
         Observations = source.Observations,
         Phone = source.Phone,
         Street = source.Street,
         Type = source.Type,
         ZipCode = source.ZipCode,
         CustomerEmail = source.CustomerEmail
     });
 }
Exemple #13
0
        public async Task <IActionResult> UpdateAddressAsync(UpdateAddressInput input)
        {
            var result = await _service.UpdateAddressAsync(input);

            return(new OperationActionResult(result));
        }
Exemple #14
0
 public async Task Put([FromBody] UpdateAddressInput input) => await _service.UpdateAsync(input);