Exemplo n.º 1
0
        protected bool ValidAddress(BaseAddressDto address)
        {
            var stateId = address.StateId;
            var cityId  = address.CityId;

            if (!_databaseProvider.StateExists(stateId))
            {
                ModelState.AddModelError("Not Found Entity", "There is no State with the specified Id");
                return(false);
            }
            if (cityId.HasValue && cityId != 0)
            {
                if (!_databaseProvider.CityExists((int)cityId))
                {
                    ModelState.AddModelError("Not Found Entity", "There is no City with the specified Id");
                    return(false);
                }
                if (!_databaseProvider.CityExistsInState(stateId, (int)cityId))
                {
                    ModelState.AddModelError("Wrong Entity", "The City input Id does not correspond with the State input Id");
                    return(false);
                }
            }

            return(true);
        }