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(); } } }
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(); } } }
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(); } }
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(); } }
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); } }
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(); } } }
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 }); } }
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 }); } }
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(); } } }
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(); } } }
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 }); } }
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, }); } }
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(); } } }
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(); } }