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 <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 <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); } }