public void Delete() { try { VideogamesContext context = new VideogamesContext(); context.Entry(this).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } catch (Exception) { throw; } }
public void Remove() { try { VideogamesContext context = new VideogamesContext(); context.Entry(this).State = System.Data.Entity.EntityState.Deleted; //borramos el producto context.SaveChanges(); //guardamos los cambios } catch (Exception e) { throw; } }
public void Save() { bool create = this.id == 0; try { VideogamesContext context = new VideogamesContext(); if (create) { context.Entry(this).State = System.Data.Entity.EntityState.Added; } else { context.Entry(this).State = System.Data.Entity.EntityState.Modified; } context.SaveChanges(); } catch (Exception) { throw; } }
public void Save() { bool crear = this.id == 0;//sera verdadero cuando la id sea 0 try { VideogamesContext context = new VideogamesContext(); //creamos el contexto if (crear) //si se cumple crear(Su id es 0, por lo tanto es nuevo) { context.Entry(this).State = System.Data.Entity.EntityState.Added; //añadimos el producto } else//sino... { context.Entry(this).State = System.Data.Entity.EntityState.Modified;//modificamos el producto } context.SaveChanges(); //lo guardamos } catch (Exception e) { throw; } }