Exemple #1
0
        public async Task <List <StaffMember> > GetStaff(string whereClause = "")
        {
            var staffList = new List <StaffMember>();

            var token = await GetToken();

            if (string.IsNullOrEmpty(token))
            {
                return(staffList);
            }

            if (string.IsNullOrEmpty(whereClause))
            {
                whereClause = "oid > 0";
            }

            var postParams = new Dictionary <string, string>()
            {
                { "token", token },
                { "f", "pjson" },
                { "where", whereClause },
                { "outfields", "*" },
            };

            var content = new FormUrlEncodedContent(postParams);
            var result  = await httpClient.PostAsync(_cardiffServer + _staffLayer + "query", content);

            if (result.StatusCode != System.Net.HttpStatusCode.OK || result.Content == null)
            {
                return(staffList);
            }

            string json = await result.Content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(json))
            {
                return(staffList);
            }

            var staffListJSON = JObject.Parse(json);

            if (staffListJSON == null)
            {
                return(staffList);
            }

            var users = staffListJSON.GetValue("features") as JArray;

            if (users == null || users.Count == 0)
            {
                return(staffList);
            }

            foreach (var user in users)
            {
                var staffMember = StaffMember.fromJSON(user as JObject);
                if (staffMember == null)
                {
                    continue;
                }

                staffList.Add(staffMember);
            }

            return(staffList);
        }