예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }