Beispiel #1
0
        public List <MLivre> getByTitle(string title, bool lazy = false)
        {
            var result = new List <MLivre>();

            using (var ctx = new modelEntities())
            {
                title = title.Replace(" ", "%");
                //todo : modifier
                if (!lazy)
                {
                    var livres = ctx.Livre.Where(x => SqlMethods.Like(x.titre, title));
                    if (livres.Count() != 0)
                    {
                        foreach (var item in livres)
                        {
                            result.Add(Mapping(item));
                        }
                    }
                    else
                    {
                        return(data.callApiTitle(title));
                    }
                }
                else
                {
                    return(data.callApiTitle(title));
                }
            }
            return(result);
        }
Beispiel #2
0
        public void InsertBookFile(string filename)
        {
            string line;

            using (var ctx = new modelEntities())
            {
                ctx.Database.Connection.Open();
                var file = new StreamReader(filename);

                while ((line = file.ReadLine()) != null)
                {
                    if (!line.Contains("id"))
                    {
                        var data = line.Split(';');
                        if (data.Length > 1 && !String.IsNullOrEmpty(data[19]))
                        {
                            var item = new Livre()
                            {
                                titre  = data[3].Split('[')[0],
                                auteur = data[14],
                                genre  = data[18],
                                isbn   = data[19]
                            };
                            ctx.Livre.Add(item);
                            ctx.SaveChanges();
                        }
                    }
                }
            }
        }
Beispiel #3
0
 public MBoite getBoxById(int idbox)
 {
     using (var ctx = new modelEntities())
     {
         var box = ctx.Boite.FirstOrDefault(x => x.id_boite == idbox);
         if (box != null)
         {
             return(Mapping(box));
         }
         return(null);
     }
 }
Beispiel #4
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);
            }
        }
Beispiel #5
0
        public List <MLivre> getBooks()
        {
            var result = new List <MLivre>();

            using (var ctx = new modelEntities())
            {
                foreach (var item in ctx.Livre.ToList())
                {
                    result.Add(Mapping(item));
                }
            }
            return(result);
        }
Beispiel #6
0
        public List <MBoite> getBoxFromcity(string city)
        {
            var result = new List <MBoite>();

            using (var ctx = new modelEntities())
            {
                foreach (var box in ctx.Boite.Where(x => x.ville == city).ToList())
                {
                    result.Add(Mapping(box));
                }
            }
            return(result);
        }
Beispiel #7
0
 public MLivre getByISBN(string isbn)
 {
     using (var ctx = new modelEntities())
     {
         var livre = ctx.Livre.FirstOrDefault(x => x.isbn == isbn);
         if (livre != null)
         {
             return(Mapping(livre));
         }
         else
         {
             return(data.callApiISBN(isbn));
         }
     }
 }
Beispiel #8
0
        public List <MLivre> getBooksFromBox(int idBox)
        {
            var result = new List <MLivre>();

            using (var ctx = new modelEntities())
            {
                var listLivre = ctx.Boite_Livre.Where(x => x.id_boite == idBox).ToList();
                foreach (var item in listLivre)
                {
                    var livre = ctx.Livre.FirstOrDefault(y => y.id_livre == item.id_livre);
                    result.Add(Mapping(livre));
                }
            }
            return(result);
        }
Beispiel #9
0
        public List <MBoite> getBoxFromLocalisation(float longitude, float latitude)
        {
            var result = new List <MBoite>();

            using (var ctx = new modelEntities())
            {
                foreach (var box in ctx.Boite.ToList())
                {
                    if (Distance(latitude, longitude, (float)box.latitude, (float)box.longitude) < 10)
                    {
                        result.Add(Mapping(box));
                    }
                }
            }
            return(result);
        }
Beispiel #10
0
 public int addBook(MLivre livre)
 {
     using (var ctx = new modelEntities())
     {
         ctx.Livre.Add(new Livre()
         {
             titre       = livre.Title,
             auteur      = livre.Author,
             isbn        = livre.isbn13,
             description = livre.Summary,
             genre       = livre.Genre,
             url_image   = livre.UrlImage
         });
         return(ctx.SaveChanges());
     }
     return(-1);
 }
        public List <Provincie> GetProvincie()
        {
            List <Provincie> listProvincie = new List <Provincie>();

            try
            {
                using (var entities = new modelEntities())
                {
                    listProvincie = (from a in entities.Provincie
                                     orderby a.Provincia ascending
                                     select a).ToList();
                }
            }
            catch (Exception e)
            {
                string errore = e.ToString();
                return(null);
            }

            return(listProvincie);
        }
        public List <Comuni> GetComuni(string sigla)
        {
            List <Comuni> listComune = new List <Comuni>();

            try
            {
                using (var entities = new modelEntities())
                {
                    listComune = (from a in entities.Comuni
                                  where a.Provincia == sigla
                                  orderby a.Comune ascending
                                  select a).ToList();
                }
            }
            catch (Exception e)
            {
                string errore = e.ToString();
                return(null);
            }

            return(listComune);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public void InsertBoxFile(string filename)
        {
            string line;

            using (var ctx = new modelEntities())
            {
                ctx.Database.Connection.Open();
                var file = new StreamReader(filename);

                while ((line = file.ReadLine()) != null)
                {
                    if (!line.Contains("Code"))
                    {
                        var data = line.Split(';');
                        if (data.Length > 1)
                        {
                            var item = new Boite()
                            {
                                adresse     = data[0],
                                code_postal = data[1],
                                ville       = data[2],
                                remarque    = data[4]
                            };
                            if (!String.IsNullOrEmpty(data[3]) && data[3] != ",")
                            {
                                var coordonate = data[3].Split(',');

                                item.latitude  = decimal.Parse(coordonate[0].Replace('.', ','));
                                item.longitude = decimal.Parse(coordonate[1].Replace('.', ','));
                            }
                            ctx.Boite.Add(item);
                            ctx.SaveChanges();
                        }
                    }
                }
            };
        }