You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.8 KiB
54 lines
1.8 KiB
// Author: Gockner, Simon
|
|
// Created: 2020-09-18
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using GBase.Factories;
|
|
using GBase.Interfaces;
|
|
|
|
namespace Test.GBase.GBaseIntegrationTest
|
|
{
|
|
public class Model
|
|
{
|
|
private readonly IGBase _gBase;
|
|
|
|
public Model(IGBaseFactory gBaseFactory)
|
|
{
|
|
_gBase = gBaseFactory.Create(new Settings());
|
|
Items = new List<IItem>();
|
|
Groups = new List<IGroup>();
|
|
}
|
|
|
|
public List<IItem> Items { get; private set; }
|
|
public List<IGroup> Groups { get; private set; }
|
|
|
|
public async Task Initialize(CancellationToken cancellationToken)
|
|
{
|
|
await _gBase.Init("DB", Assembly.GetExecutingAssembly(), cancellationToken);
|
|
|
|
IGBaseTable<Item> itemsTable = _gBase.GetTable<Item>();
|
|
Items = itemsTable.Entries.Cast<IItem>().ToList();
|
|
//Items = (await _gBase.GetValues<Model, Item>(this, nameof(Items), cancellationToken)).Cast<IItem>().ToList();
|
|
|
|
IGBaseTable<Group> groupsTable = _gBase.GetTable<Group>();
|
|
Groups = groupsTable.Entries.Cast<IGroup>().ToList();
|
|
//Groups = (await _gBase.GetValues<Model, Group>(this, nameof(Groups), cancellationToken)).Cast<IGroup>().ToList();
|
|
}
|
|
|
|
public async Task AddItem(Item item, CancellationToken cancellationToken)
|
|
{
|
|
Items.Add(item);
|
|
await _gBase.AddEntry(item, cancellationToken);
|
|
}
|
|
|
|
public async Task AddGroup(Group group, CancellationToken cancellationToken)
|
|
{
|
|
Groups.Add(group);
|
|
await _gBase.AddEntry(group, cancellationToken);
|
|
}
|
|
}
|
|
} |