Exemple #1
0
        public static void SaveCategory(Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("Category");
            }
            try
            {
                using (var db = new ShopAppEntities())
                {
                    Categorie categ = db.Categorie.FirstOrDefault(el => el.ID == category.ID);
                    if (categ == null)
                    {
                        categ = new Categorie();
                        db.Categorie.Add(categ);
                    }

                    if (db.Categorie.FirstOrDefault(el => el.ID == category.CategorieID) != null)
                    {
                        categ.CategorieID = category.CategorieID;
                        categ.Nume        = category.Nume;
                        categ.Cod         = category.Cod;
                        categ.Descriere   = category.Descriere;
                        categ.Imagine     = category.Imagine;

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        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();
                }
            }
        }
Exemple #3
0
        public static void SaveEmployee(Employee employee)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("Employee");
            }

            using (var db = new ShopAppEntities())
            {
                Angajat ang = db.Angajat.FirstOrDefault(el => el.ID == employee.ID);
                if (ang == null)
                {
                    ang = new Angajat();
                    db.Angajat.Add(ang);
                }

                ang.MagazinID    = employee.MagazinID;
                ang.Nume         = employee.Nume;
                ang.Prenume      = employee.Prenume;
                ang.CNP          = employee.CNP;
                ang.Email        = employee.Email;
                ang.Parola       = employee.Parola;
                ang.DataAngajare = employee.DataAngajare;
                ang.Salariu      = employee.Salariu;
                ang.Functie      = employee.Functie;

                db.SaveChanges();
            }
        }
        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();
                }
            }
        }
Exemple #5
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();
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
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();
         }
     }
 }
Exemple #8
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();
                }
            }
        }
        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();
                }
            }
        }
Exemple #10
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();
                }
            }
        }
Exemple #11
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();
                }
            }
        }
Exemple #12
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();
            }
        }