Beispiel #1
0
        public List <DtoAuthorType> GetAuthorTypes()
        {
            var dtoauthortypes = new List <DtoAuthorType>();

            using (var client = new HttpClient())
            {
                var uri = new Uri("http://localhost/WebAPI/api/author/GetAuthorTypes");

                var response = client.GetAsync(uri).Result;

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(response.ToString());
                }

                var responseContent = response.Content;
                var responseString  = responseContent.ReadAsStringAsync().Result;

                dynamic authortypes = JArray.Parse(responseString) as JArray;

                foreach (var obj in authortypes)
                {
                    DtoAuthorType dto = obj.ToObject <DtoAuthorType>();

                    dtoauthortypes.Add(dto);
                }
            }

            return(dtoauthortypes);
        }
Beispiel #2
0
        public async Task <List <DtoAuthorType> > GetAuthorTypes()
        {
            var dtos = new List <DtoAuthorType>();

            var authors = await pc.Author.ToListAsync();

            foreach (var author in authors)
            {
                DtoAuthorType dto = new DtoAuthorType
                {
                    AuthorId = author.AuthorId,
                    Value    = author.AuthorId.ToString(),
                    Text     = author.LastName + ", " + author.FirstName
                };

                dtos.Add(dto);
            }

            return(dtos);
        }