Пример #1
0
        public static void DeleteCategory(int id, string path)
        {
            using (var db = new ShopAppEntities())
            {
                Categorie categ = db.Categorie.FirstOrDefault(el => el.ID == id);
                if (categ != null)
                {
                    string fullPath = Path.Combine(path, categ.Imagine + ".png");
                    if (File.Exists(fullPath))
                    {
                        File.Delete(fullPath);
                    }

                    db.Categorie.Remove(categ);

                    List <Categorie> rest = db.Categorie.Where(el => el.CategorieID == id).ToList();
                    foreach (var rez in rest)
                    {
                        db.Categorie.Remove(rez);
                    }

                    db.SaveChanges();
                }
            }
        }
Пример #2
0
        public static void SaveProduct(Product product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("Product");
            }

            using (var db = new ShopAppEntities())
            {
                Produs prod = db.Produs.FirstOrDefault(el => el.ID == product.ID);
                if (prod == null)
                {
                    prod = new Produs();
                    db.Produs.Add(prod);
                }
                if (db.Magazin.FirstOrDefault(el => el.ID == product.MagazinID) != null &&
                    db.Categorie.FirstOrDefault(el => el.ID == product.CategorieID) != null)
                {
                    prod.CategorieID  = product.CategorieID;
                    prod.MagazinID    = product.MagazinID;
                    prod.Denumire     = product.Denumire;
                    prod.Greutate     = product.Greutate;
                    prod.Pret         = product.Pret;
                    prod.Cantitate    = product.Cantitate;
                    prod.DataExpirate = product.DataExpirate;
                    prod.Descriere    = product.Descriere;
                    if (!String.IsNullOrWhiteSpace(product.Imagine))
                    {
                        prod.Imagine = product.Imagine;
                    }

                    db.SaveChanges();
                }
            }
        }
Пример #3
0
        public static void SaveSupplier(Supplier supplier)
        {
            if (supplier == null)
            {
                throw new ArgumentNullException("Supplier");
            }

            using (var db = new ShopAppEntities())
            {
                Furnizor sup = db.Furnizor.FirstOrDefault(el => el.ID == supplier.ID);
                if (sup == null)
                {
                    sup = new Furnizor();
                    db.Furnizor.Add(sup);
                }

                sup.ID      = supplier.ID;
                sup.Nume    = supplier.Nume;
                sup.Adresa  = supplier.Adresa;
                sup.Oras    = supplier.Oras;
                sup.Telefon = supplier.Telefon;

                db.SaveChanges();
            }
        }
Пример #4
0
        public static void SaveDelivery(Delivery delivery)
        {
            if (delivery == null)
            {
                throw new ArgumentNullException("Delivery");
            }

            using (var db = new ShopAppEntities())
            {
                Livrare liv = db.Livrare.FirstOrDefault(el => el.ID == delivery.ID);
                if (liv == null)
                {
                    liv = new Livrare();
                    db.Livrare.Add(liv);
                }

                liv.FurnizorID     = delivery.FurnizorID;
                liv.MagazinID      = delivery.MagazinID;
                liv.DataSolicitare = delivery.DataSolicitare;
                liv.DataLivrare    = delivery.DataLivrare;
                liv.Status         = delivery.Status;
                liv.Descriere      = delivery.Descriere;
                liv.Pret           = delivery.Pret;

                db.SaveChanges();
            }
        }
Пример #5
0
 public static List <string> GetMarkets(int id)
 {
     using (var db = new ShopAppEntities())
     {
         List <string> list = (from m in db.Magazin
                               join a in db.Angajat on m.ID equals a.MagazinID
                               where a.ID == id
                               select a.Magazin.Denumire).ToList();
         return(list);
     }
 }
Пример #6
0
 public static void DeleteDelivery(int id)
 {
     using (var db = new ShopAppEntities())
     {
         Livrare liv = db.Livrare.FirstOrDefault(el => el.ID == id);
         if (liv != null)
         {
             db.Livrare.Remove(liv);
             db.SaveChanges();
         }
     }
 }
Пример #7
0
 public static Market getMarketById(int id)
 {
     using (var db = new ShopAppEntities())
     {
         Magazin mag = db.Magazin.FirstOrDefault(el => el.ID == id);
         return(new Market()
         {
             ID = mag.ID,
             Adresa = mag.Adresa,
             Denumire = mag.Denumire,
             Imagine = mag.Imagine,
             Oras = mag.Oras
         });
     }
 }
Пример #8
0
 public static Supplier getSupplierById(int id)
 {
     using (var db = new ShopAppEntities())
     {
         Furnizor supp = db.Furnizor.FirstOrDefault(el => el.ID == id);
         return(new Supplier()
         {
             ID = supp.ID,
             Nume = supp.Nume,
             Adresa = supp.Adresa,
             Oras = supp.Oras,
             Telefon = (long)supp.Telefon
         });
     }
 }
Пример #9
0
        public static void DeleteEmployee(int id)
        {
            if (id <= 0)
            {
                throw new ArgumentNullException("Employee");
            }

            using (var db = new ShopAppEntities())
            {
                Angajat ang = db.Angajat.FirstOrDefault(el => el.ID == id);
                if (ang != null)
                {
                    db.Angajat.Remove(ang);
                    db.SaveChanges();
                }
            }
        }
Пример #10
0
        public static void DeleteProduct(int id, string path)
        {
            using (var db = new ShopAppEntities())
            {
                Produs prod = db.Produs.FirstOrDefault(el => el.ID == id);
                if (prod != null)
                {
                    string fullPath = Path.Combine(path, prod.Imagine + ".png");
                    if (File.Exists(fullPath))
                    {
                        File.Delete(fullPath);
                    }

                    db.Produs.Remove(prod);
                    db.SaveChanges();
                }
            }
        }
Пример #11
0
        public static void DeleteSupplier(int id)
        {
            if (id < 0)
            {
                throw new ArgumentNullException("Supplier");
            }

            using (var db = new ShopAppEntities())
            {
                Furnizor sup = db.Furnizor.FirstOrDefault(el => el.ID == id);

                if (sup != null)
                {
                    db.Furnizor.Remove(sup);
                    db.SaveChanges();
                }
            }
        }
Пример #12
0
 public static Delivery getDeliveryById(int id)
 {
     using (var db = new ShopAppEntities())
     {
         Livrare del = db.Livrare.FirstOrDefault(el => el.ID == id);
         return(new Delivery()
         {
             ID = del.ID,
             FurnizorID = del.FurnizorID,
             MagazinID = del.MagazinID,
             DataSolicitare = del.DataSolicitare,
             DataLivrare = del.DataLivrare,
             Status = del.Status,
             Descriere = del.Descriere,
             Pret = del.Pret
         });
     }
 }
Пример #13
0
 public static Product getProductById(int id)
 {
     using (var db = new ShopAppEntities())
     {
         Produs prod = db.Produs.FirstOrDefault(el => el.ID == id);
         return(new Product()
         {
             ID = prod.ID,
             CategorieID = prod.CategorieID,
             MagazinID = prod.MagazinID,
             Denumire = prod.Denumire,
             Greutate = prod.Greutate,
             Pret = prod.Pret,
             Cantitate = prod.Cantitate,
             DataExpirate = prod.DataExpirate,
             Descriere = prod.Descriere,
         });
     }
 }
Пример #14
0
        public static void DeleteMatket(int id, string path)
        {
            if (id <= 0)
            {
                throw new ArgumentNullException("Market");
            }

            using (var db = new ShopAppEntities())
            {
                Magazin mag = db.Magazin.FirstOrDefault(el => el.ID == id);
                if (mag != null)
                {
                    string fullPath = Path.Combine(path, mag.Imagine + ".png");
                    if (File.Exists(fullPath))
                    {
                        File.Delete(fullPath);
                    }

                    db.Magazin.Remove(mag);
                    db.SaveChanges();
                }
            }
        }
Пример #15
0
        public static void SaveMarket(Market market)
        {
            if (market == null)
            {
                throw new ArgumentNullException("Market");
            }

            using (var db = new ShopAppEntities())
            {
                Magazin mag = db.Magazin.FirstOrDefault(el => el.ID == market.ID);
                if (mag == null)
                {
                    mag = new Magazin();
                    db.Magazin.Add(mag);
                }

                mag.Adresa   = market.Adresa;
                mag.Denumire = market.Denumire;
                mag.Imagine  = market.Imagine;
                mag.Oras     = market.Oras;

                db.SaveChanges();
            }
        }