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);
            }
        }
示例#3
0
        public async Task <bool> DeleteAll(IEnumerable <T> list)
        {
            using (InventoryManagerDbContext context = _contextFactory.CreateDbContext())
            {
                context.Set <T>().RemoveRange(list);
                await context.SaveChangesAsync();

                return(true);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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!");
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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);
            }
        }
示例#8
0
        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());
        }
示例#9
0
 public ItemController(InventoryManagerDbContext dbContext, IAuthorizationService authorizationService)
 {
     context = dbContext;
     _authorizationService = authorizationService;
 }
示例#10
0
 public SupplierController(InventoryManagerDbContext dbContext)
 {
     context = dbContext;
 }
示例#11
0
 public ClothesService(InventoryManagerDbContext db)
 {
     this.db = db;
 }