Esempio n. 1
0
        /// <summary>
        /// Method to get a list of all the Users listed in a current city from the DWP Api
        /// </summary>
        /// <param name="city"> A string representing the city i.e. "London" </param>
        /// <returns> List<User> representing all the users listed in the given city </returns>
        public static async Task <List <User> > GetAllUsersListedInCity(string city)
        {
            string      url   = baseUrl + String.Format("city/{0}/users", city);
            List <User> users = new List <User>();

            users = await DwpApiRequests.GetRequiredUsers(url);

            return(users);
        }
Esempio n. 2
0
        /// <summary>
        /// Method to get a list of all the current Users from the DWP Api
        /// </summary>
        /// <returns> List<User> representing all the current users </returns>
        public static async Task <List <User> > GetAllUsers()
        {
            string      url   = baseUrl + "users";
            List <User> users = new List <User>();

            users = await DwpApiRequests.GetRequiredUsers(url);

            return(users);
        }
Esempio n. 3
0
        /// <summary>
        /// Method to get all users whose coordinates show they
        /// are within a given distance of a given city
        /// </summary>
        /// <param name="city"> A string representing the city name </param>
        /// <param name="distance"> A double representing the distance from the city in miles </param>
        /// <returns> List<User> of all users whose coordinates show they are with the given
        /// distance from the given city according to Dwp Api </returns>
        public static async Task <List <User> > GetAllUserGivenDistanceFromCity(string city, double distance)
        {
            //get all users
            List <User> allUsers = new List <User>();

            allUsers = await DwpApiRequests.GetAllUsers();

            //get city coordinates
            double[] cityCoordinates = new double[2];
            cityCoordinates = DistanceCalculations.GetCoordinatesOfLocation(city);
            //check which users are within distance to city
            //loop if user in within distance add to Users object
            List <User> usersDistanceFromCity = allUsers.Where(u => DistanceCalculations.GetDistanceBetweenTwoLocations(
                                                                   u.latitude, u.longitude, cityCoordinates[0], cityCoordinates[1]) <= distance).ToList();

            return(usersDistanceFromCity);
        }
Esempio n. 4
0
        /// <summary>
        /// Method to get all users listed as living in a city
        /// </summary>
        /// <param name="city"> A string representing the city name </param>
        /// <returns> List<User> of   according to Dwp Api </returns>
        public static async Task <List <User> > GetAllUsersListedInACity(string city)
        {
            //paramter check city
            Regex expression = new Regex(@"^[a-z,A-Z][a-z]+$");
            bool  result     = expression.IsMatch(city);

            if (!result)
            {
                throw new Exception("The city has not been entered in the correct format " +
                                    "i.e api/values/london or api/values/london/50");
            }
            city = char.ToUpper(city[0]) + city.Substring(1);
            List <User> usersInCity = new List <User>();

            usersInCity = await DwpApiRequests.GetAllUsersListedInCity(city);

            return(usersInCity);
        }