Example #1
0
        public OperationResult <bool> AddAddress(string id, Addresses address)
        {
            var result = new OperationResult <bool>();

            try
            {
                var customer = _customerRepo.Get(id);
                if (customer != null)
                {
                    if (!CountryValidator.Validate(address.Country))
                    {
                        result.Data             = false;
                        result.Status           = eOperationStatus.GeneralError;
                        result.ExceptionMessage = "Country code does not exists";
                    }
                    else if (_addrRepo.Get(address.AddressId) != null)
                    {
                        result.Data             = false;
                        result.Status           = eOperationStatus.GeneralError;
                        result.ExceptionMessage = $"Address:{address.AddressId} already exists";
                    }
                    else
                    {
                        address.CustomerId = id;
                        _addrRepo.Add(address);

                        var saveResult = _context.SaveChanges();
                        if (saveResult > 0)
                        {
                            result.Data   = true;
                            result.Status = eOperationStatus.Success;
                        }
                        else
                        {
                            result.Data   = false;
                            result.Status = eOperationStatus.GeneralError;
                        }
                    }
                }
                else
                {
                    result.Data             = false;
                    result.Status           = eOperationStatus.NotFound;
                    result.ExceptionMessage = "Customer not found";
                }
            }
            catch (Exception ex)
            {
                result.Data             = false;
                result.ExceptionMessage = ex.Message;
                result.Status           = eOperationStatus.GeneralError;
            }
            return(result);
        }
Example #2
0
 public void Add(Addresses address)
 {
     addressesRepository.Add(address);
 }