public async Task <bool> Delete(Guid id) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id); context.Set <T>().Remove(entity); await context.SaveChangesAsync(); return(true); } }
public async Task <DiskDrive> Get(string serialNumber) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { DiskDrive entity = await context.Set <DiskDrive>().FirstOrDefaultAsync((e) => e.SerialNumber == serialNumber); return(entity); } }
public async Task <LabSystem> Get(string hostName) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { LabSystem entity = await context.Set <LabSystem>().FirstOrDefaultAsync((e) => e.HostName == hostName); return(entity); } }
public async Task <T> Create(T entity) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdResult.Entity); } }
public async Task <T> Update(Guid id, T entity) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { entity.Id = id; context.Set <T>().Update(entity); await context.SaveChangesAsync(); return(entity); } }
public async Task <IEnumerable <T> > GetAll() { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { context.DiskDrives.Load(); IEnumerable <T> entities = await context.Set <T>().ToListAsync(); return(entities); } }
public async Task <T> Get(Guid id) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { context.DiskDrives.Load(); T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id); return(entity); } }
public async Task <LabSystem> CreateOrUpdate(string hostName, LabSystem entity) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { context.DiskDrives.Load(); entity.HostName = hostName; EntityEntry <LabSystem> result = context.Set <LabSystem>().CreateOrUpdate(entity, context, e => e.HostName == entity.HostName); await context.SaveChangesAsync(); return(result.Entity); } }
public async Task <T> CreateOrUpdate(Guid id, T entity) { using (LabSystemsContext context = _contextFactory.CreateDbContext()) { context.DiskDrives.Load(); entity.Id = id; EntityEntry <T> result = context.Set <T>().CreateOrUpdate <T>(entity, context, e => e.Id == entity.Id); await context.SaveChangesAsync(); return(result.Entity); } }