public Task <IAsyncEnumerable <T> > GetAll() { using (InventoryManagerDbContext context = _contextFactory.CreateDbContext()) { return((Task <IAsyncEnumerable <T> >)context.Set <T>().AsAsyncEnumerable()); } }
public async Task <T> Get(Guid id) { using (InventoryManagerDbContext context = _contextFactory.CreateDbContext()) { T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.id == id); return(entity); } }
public async Task <bool> DeleteAll(IEnumerable <T> list) { using (InventoryManagerDbContext context = _contextFactory.CreateDbContext()) { context.Set <T>().RemoveRange(list); await context.SaveChangesAsync(); return(true); } }
public async Task <T> Create(T entity) { using (InventoryManagerDbContext context = _contextFactory.CreateDbContext()) { EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdResult.Entity); } }
static async Task Main(string[] args) { DbContextOptionsBuilder options = new DbContextOptionsBuilder <InventoryManagerDbContext>(); options.UseSqlite(@"Data Source=InventoryManager.db;"); using (InventoryManagerDbContext context = new InventoryManagerDbContext(options.Options)) { context.Database.Migrate(); } Action <DbContextOptionsBuilder> configureDbContext = o => o.UseSqlite(@"Data Source=InventoryManager.db;"); InventoryManagerDbContextFactory contextFactory = new InventoryManagerDbContextFactory(configureDbContext); IDataService <Container> dataService = new GenericDataService <Container>(contextFactory); ItemDefinition item1 = new ItemDefinition() { id = CreateGuid(), Name = "Test Item of Valor", Weight = 1 }; ItemDefinition item2 = new ItemDefinition() { id = CreateGuid(), Name = "Test Item of Valor", Weight = 1 }; ItemDefinition item3 = new ItemDefinition() { id = CreateGuid(), Name = "Test Item of Valor", Weight = 1 }; List <StorableItem> containerItems = new List <StorableItem>(); containerItems.Add(new ContainerItem() { id = CreateGuid(), ItemDefinition = item1, Quantity = 3 }); containerItems.Add(new ContainerItem() { id = CreateGuid(), ItemDefinition = item2, Quantity = 5 }); containerItems.Add(new ContainerItem() { id = CreateGuid(), ItemDefinition = item3, Quantity = 1 }); Container container = new Container() { id = CreateGuid(), Inventory = containerItems }; container.ItemDefinition.Name = "Test Container"; container.ItemDefinition.Weight = 3; var thing = await dataService.Create(container); var newthing = await dataService.Get(thing.id); Console.WriteLine("Great success!"); }
public async Task <bool> Delete(Guid id) { using (InventoryManagerDbContext 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 <T> Update(Guid id, T entity) { using (InventoryManagerDbContext context = _contextFactory.CreateDbContext()) { entity.id = id; context.Set <T>().Update(entity); await context.SaveChangesAsync(); return(entity); } }
private IServiceProvider CreateServiceProvider() { IServiceCollection services = new ServiceCollection(); Action <DbContextOptionsBuilder> configureDbContext = o => o.UseSqlite(@"Data Source=InventoryManager.db;"); services.AddDbContext <InventoryManagerDbContext>(configureDbContext); services.AddScoped <IDataService <ItemDefinition>, GenericDataService <ItemDefinition> >(); services.AddScoped <IRepository <ItemDefinition>, ItemDefinitionRepository>(); services.AddSingleton <InventoryManagerDbContextFactory>(new InventoryManagerDbContextFactory(configureDbContext)); DbContextOptionsBuilder options = new DbContextOptionsBuilder <InventoryManagerDbContext>(); options.UseSqlite(@"Data Source=InventoryManager.db;"); using (InventoryManagerDbContext context = new InventoryManagerDbContext(options.Options)) { context.Database.Migrate(); } return(services.BuildServiceProvider()); }
public ItemController(InventoryManagerDbContext dbContext, IAuthorizationService authorizationService) { context = dbContext; _authorizationService = authorizationService; }
public SupplierController(InventoryManagerDbContext dbContext) { context = dbContext; }
public ClothesService(InventoryManagerDbContext db) { this.db = db; }