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