Пример #1
0
        public async Task <Address> Update(int id, Address newAddress)
        {
            var addressExists = _addressRepository.Exists(address => address.Id.Equals(id));

            if (!Valid(newAddress) && !addressExists)
            {
                throw new InvalidUserObject("Address");
            }

            var existingAddress = await _addressRepository.GetById(id);

            return(await _addressRepository.Update(existingAddress, newAddress));
        }
Пример #2
0
        public Address Insert(Address entity)
        {
            try
            {
                entity.AddressKey = Guid.NewGuid();

                var hasAddress = _addressRepository.Exists(entity);

                if (!hasAddress)
                {
                    return(_addressRepository.Insert(entity));
                }
            }
            catch (Exception ex)
            {
                throw new InternalServerErrorException($"Not was possible insert the Address: {ex.Message}");
            }

            throw new ForbbidenException("Address already exists");
        }