Ejemplo n.º 1
0
        public void UpdateShop(Shop pre_shop, Shop current_shop)
        {
            using (var db = new IceCreamDB())
            {
                var query = from m in db.IceCreams
                            select m;

                IEnumerable <IceCream> iceCreams = query.ToList <IceCream>().Where(x => x.ShopId == current_shop.Id);

                foreach (var iceCream in iceCreams)
                {
                    db.IceCreams.Attach(iceCream);
                    db.IceCreams.Remove(iceCream);
                }


                if (pre_shop != null)//if we get user from main it means he is saved in db..
                {
                    db.Shops.Attach(pre_shop);
                    db.Shops.Remove(pre_shop);
                    db.SaveChanges();
                }


                db.Shops.Add(current_shop);

                db.SaveChanges();

                foreach (var iceCream in iceCreams)
                {
                    db.IceCreams.Add(iceCream);
                }
                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public void SaveShop(Shop s)
 {
     using (var db = new IceCreamDB())
     {
         db.Shops.Add(s);
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
 public void AddIceCream(IceCream i)
 {
     using (var db = new IceCreamDB())
     {
         db.IceCreams.Add(i);
         db.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public IceCream FindIceCream(string ID, string ShopId)
 {
     using (var db = new IceCreamDB())
     {
         var query = from m in db.IceCreams
                     where m.Id == ID && m.ShopId == ShopId
                     select m;
         return(query.FirstOrDefault <IceCream>());
     }
 }
Ejemplo n.º 5
0
        public IEnumerable <IceCream> GetIceCreamFromShop(string shopid)
        {
            using (var db = new IceCreamDB())
            {
                var list = from i in db.IceCreams
                           where i.ShopId == shopid
                           select i;

                return(list.ToList <IceCream>());
            }
        }
Ejemplo n.º 6
0
 public IEnumerable <IceCream> FindListIceCream(string taste, string ShopID)
 {
     using (var db = new IceCreamDB())
     {
         var query = from m in db.IceCreams
                     where m.Taste.Contains(taste) &&
                     m.ShopId == ShopID
                     select m;
         return(query);
     }
 }
Ejemplo n.º 7
0
 public void DeleteIceCream(IceCream iceCream)
 {
     using (var db = new IceCreamDB())
     {
         if (iceCream != null)
         {
             db.IceCreams.Attach(iceCream);
             db.IceCreams.Remove(iceCream);
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 8
0
 public bool CheckShop(int id, string password)
 {
     using (var db = new IceCreamDB())
     {
         var query = from m in db.Shops
                     where (m.ID == id && m.Password == password)
                     select m;
         foreach (var item in query)
         {
             return(true);//if we entered here there are items in query,user exist
         }
         return(false);
     }
 }
Ejemplo n.º 9
0
        public IEnumerable <IceCream> GetAllIceCream(Func <IceCream, bool> predicate = null)
        {
            using (var db = new IceCreamDB())
            {
                if (predicate == null)
                {
                    return(db.IceCreams.ToList <IceCream>());
                }

                return((IEnumerable <IceCream>) from s in db.IceCreams
                       where (predicate(s))
                       select s);
            }
        }
Ejemplo n.º 10
0
 public void UpdateIceCream(IceCream pre_IC, IceCream current_IC)
 {
     using (var db = new IceCreamDB())
     {
         if (pre_IC != null)
         {
             db.IceCreams.Attach(pre_IC);
             db.IceCreams.Remove(pre_IC);
             db.SaveChanges();
         }
         db.IceCreams.Add(current_IC);
         db.SaveChanges();
     }
 }
Ejemplo n.º 11
0
 public Shop findShopByLogin(String id, string password)
 {
     using (var db = new IceCreamDB())
     {
         var query = from m in db.Shops
                     where m.Id == id && m.Password == password
                     select m;
         foreach (var item in query)
         {
             return(item);//if we entered here there are items in query,user exist
         }
         return(null);
     }
 }
Ejemplo n.º 12
0
        public IEnumerable <Shop> GetAllShop(Func <Shop, bool> predicate = null)
        {
            using (var db = new IceCreamDB())
            {
                if (predicate == null)
                {
                    return(db.Shops.ToList <Shop>());
                }

                return((IEnumerable <Shop>) from s in db.Shops
                       where (predicate(s))
                       select s);
            }
        }
Ejemplo n.º 13
0
 public bool CheckShop(string id)
 {
     using (var db = new IceCreamDB())
     {
         var query = from m in db.Shops
                     where m.Id == id
                     select m;
         foreach (var item in query)
         {
             return(true);//if we entered here there are items in query,user exist
         }
         return(false);
     }
 }
Ejemplo n.º 14
0
        public bool CheckIceCream(string ID, string ShopID)
        {
            using (var db = new IceCreamDB())
            {
                var query = from m in db.IceCreams
                            where m.Id == ID && m.ShopId == ShopID
                            select m;
                foreach (var item in query)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 15
0
        public IEnumerable <IceCream> FindListIceCream(string taste, double energy, double calories, double proteins, double medianmark)
        {
            using (var db = new IceCreamDB())
            {
                var query = from m in db.IceCreams
                            where (energy <= (m.Energy + 30) && energy >= m.Energy - 30)
                            //    (!(energy > (m.Energy + 30)) || ! (energy < (m.Energy - 30)))
                            && ((calories <= (m.Calories + 5)) && calories >= (m.Calories - 5)) &&
                            ((proteins <= (m.Proteins + 2)) && proteins >= (m.Proteins - 2))
                            select m;
                return(query.ToList <IceCream>().Where(x => Taste(x.Taste).Contains(taste) && !(Median(x) < medianmark - 1)));

                //   .Where(x => !(Median(x) < medianmark - 1))
            }
        }
Ejemplo n.º 16
0
        public void AddShop(Shop s)
        {
            var db = new IceCreamDB();

            db.Shops.Add(s);
            db.SaveChanges();

            /* try
             * {
             *   using (var db = new IceCreamDB())
             *   {
             *       db.Shops.Add(s);
             *       db.SaveChanges();
             *   }
             * }
             * catch (Exception e)
             * {
             *   throw new Exception("Erreur");
             * }
             */
        }