Esempio n. 1
0
        public AddOrderResponse CheckState(string stateAbbreviation)
        {
            AddOrderResponse response = new AddOrderResponse();

            IStateRepository stateRepo = RepoFactory.CreateStateRepo();

            List <State> states = stateRepo.GetListOfStates();

            if (stateAbbreviation.Length != 2 || !stateAbbreviation.All(char.IsLetter))
            {
                response.Success = false;
                response.Message = "You have entered an invalid State format (must be 2-letter abbreviation).";
                return(response);
            }

            foreach (var state in states)
            {
                if (state.StateAbbreviation == stateAbbreviation)
                {
                    response.Success = true;
                    return(response);
                }
            }

            response.Success = false;
            response.Message = $"We do not sell products in the state of {stateAbbreviation}.";
            return(response);
        }