public static OperationInfo Update(Product product) { try { using (var db = new PoligonEntities()) { if (db.Product.All(x => x.ID != product.ID)) { return(new OperationInfo { OperationStatus = OperationStatus.NotExist, Message = "Wybrany produkt nie istnieje w bazie. Odśwież liste." }); } db.Product.Attach(product); db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(new OperationInfo { OperationStatus = OperationStatus.ok, Message = "Produkt zmodyfikowany!" }); } } catch (Exception) { return(new OperationInfo { OperationStatus = OperationStatus.Exception, Message = "Nieoczekiwany błąd." }); } }
public static OperationInfo Add(Product product) { try { using (var db = new PoligonEntities()) { db.Product.Attach(product); db.Entry(product).State = EntityState.Added; db.SaveChanges(); return(new OperationInfo { OperationStatus = OperationStatus.ok, Message = "Produkt dodano!" }); } } catch (Exception) { return(new OperationInfo { OperationStatus = OperationStatus.Exception, Message = "Nieoczekiwany błąd." }); } }
public static ObservableCollection <Product> GetAll() { using (var db = new PoligonEntities()) { return(new ObservableCollection <Product>(db.Product)); } }