public async Task <T> GetByID(object id)
        {
            try
            {
                Context = new zModel();
                T item = await Context.Set <T>().FindAsync(id.ConvertType <T>());

                return(item ?? new T());
            }
            catch { return(new T()); }
        }
        public async Task <IEnumerable <T> > GetAll()
        {
            try
            {
                Context = new zModel();
                IEnumerable <T> lstResult = await Context.Set <T>().ToListAsync();

                return(lstResult);
            }
            catch { return(new List <T>()); }
        }
        public async Task <bool> DeleteEntry(T Item)
        {
            try
            {
                Context = new zModel();
                await Context.Database.BeginTransactionAsync();

                Context.Set <T>().Attach(Item);
                Context.Set <T>().Remove(Item);
                await Context.SaveChangesAsync();

                Context.Database.CommitTransaction();
                return(true);
            }
            catch
            {
                Context.Database.RollbackTransaction();
                return(false);
            }
        }
        public async Task <bool> DeleteEntries(object[] ids)
        {
            try
            {
                Context = new zModel();
                await Context.Database.BeginTransactionAsync();

                foreach (object id in ids)
                {
                    T Item = await Context.Set <T>().FindAsync(id);

                    Context.Set <T>().Remove(Item);
                }
                await Context.SaveChangesAsync();

                Context.Database.CommitTransaction();
                return(true);
            }
            catch
            {
                Context.Database.RollbackTransaction();
                return(false);
            }
        }
        public async Task <bool> UpdateEntries(T[] Items)
        {
            try
            {
                Context = new zModel();
                await Context.Database.BeginTransactionAsync();

                Context.Set <T>().UpdateRange(Items);
                await Context.SaveChangesAsync();

                Context.Database.CommitTransaction();
                return(true);
            }
            catch
            {
                Context.Database.RollbackTransaction();
                return(false);
            }
        }
Esempio n. 6
0
 public List <T> GetItems()
 {
     return(context.Set <T>().ToList());
 }
Esempio n. 7
0
 public Repository(zModel db)
 {
     this.db = db;
     entity  = db.Set <T>();
 }