Exemple #1
0
 public virtual void Update(T entity)
 {
     try
     {
         var entry = _context.Entry(entity);
         _context.Set <T>().Attach(entity);
         entry.State = EntityState.Modified;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        // Hung Ly
        public virtual void Delete(T entity)
        {
            //EntityEntry dbEntityEntry = _context.Entry<T>(entity);
            //dbEntityEntry.State = EntityState.Deleted;

            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            EntityEntry dbEntityEntry = _context.Entry <T>(entity);

            if (dbEntityEntry.State != (EntityState)EntityState.Deleted)
            {
                dbEntityEntry.State = EntityState.Deleted;
            }
            else
            {
                _context.Set <T>().Remove(entity);
            }
        }