public void Delete()
 {
     try
     {
         VideogamesContext context = new VideogamesContext();
         context.Entry(this).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
     catch (Exception)
     {
         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;
            }
        }
Example #3
0
        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;
            }
        }
Example #4
0
        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;
            }
        }