public virtual async Task <bool> Delete(int id) { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); T entityToDelete = await context.Set <T>().FirstOrDefaultAsync(e => e.ID == id); if (entityToDelete == null) { return(false); } context.Set <T>().Remove(entityToDelete); await context.SaveChangesAsync(); return(true); }
public override async Task <IEnumerable <Guarantee> > GetAll() { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); IEnumerable <Guarantee> entities = await context.Set <Guarantee>().Include(b => b.Customer).ToListAsync(); return(entities); }
public override async Task <ServiceItem> Get(int id) { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); ServiceItem entity = await context.Set <ServiceItem>().Include(c => c.Customer).FirstOrDefaultAsync(e => e.ID == id); return(entity); }
public async Task <IEnumerable <ServiceItem> > GetByCustomer(int customerID) { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); IEnumerable <ServiceItem> entities = await context.Set <ServiceItem>().Include(b => b.Customer).Where(c => c.Customer.ID == customerID).ToListAsync(); return(entities); }
public virtual async Task <T> Get(int id) { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); T entity = await context.Set <T>().FirstOrDefaultAsync(e => e.ID == id); return(entity); }
public virtual async Task <IEnumerable <T> > GetAll() { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); IEnumerable <T> entities = await context.Set <T>().ToListAsync(); return(entities); }
public virtual async Task <T> Update(int id, T entity) { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); entity.ID = id; context.Set <T>().Update(entity); await context.SaveChangesAsync(); return(entity); }
public virtual async Task <T> Create(T entity) { await using SMGAppDbContext context = ContextFactory.CreateDbContext(); EntityEntry <T> createdEntity = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdEntity.Entity); }