Exemplo n.º 1
0
        public MLivre callApiISBN(string isbn)
        {
            using (var ctx = new modelEntities())
            {
                var json  = callAPI(URL_BASE + API_KEY + BOOK_REQUEST + isbn);
                var data  = json["data"].Children();
                var livre = parseBook(data.First());

                ctx.Livre.Add(DLivre.Mapping(livre));
                ctx.SaveChanges();
                return(livre);
            }
        }
Exemplo n.º 2
0
        public List <MLivre> callApiTitle(string title)
        {
            var result = new List <MLivre>();

            using (var ctx = new modelEntities())
            {
                title = title.Replace(" ", "+");
                var json = callAPI(URL_BASE + API_KEY + BOOKS_TITLE_REQUEST + title);
                var data = json["data"].Children().ToList();
                foreach (var item in data)
                {
                    var livre = parseBook(item);
                    if (ctx.Livre.FirstOrDefault(x => x.isbn == livre.isbn13) != null)
                    {
                        ctx.Livre.Add(DLivre.Mapping(livre));
                        ctx.SaveChanges();
                    }
                    result.Add(livre);
                }
            }
            return(result);
        }