コード例 #1
0
ファイル: LocalDataStore.cs プロジェクト: tcerdaj/PoolGuy
        public async Task <T> Load(Guid id)
        {
            try
            {
                if (!Initialized)
                {
                    return(null);
                }

                await CreateTabletIfNotExist();

                return(await DatabaseAsync.Table <T>().FirstOrDefaultAsync(x => x.Id == id).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception at Load Id: {0} {1}", typeof(T).Name, e);
                throw;
            }
        }
コード例 #2
0
ファイル: LocalDataStore.cs プロジェクト: tcerdaj/PoolGuy
        public async Task CreateTableAsync()
        {
            try
            {
                if (!Initialized)
                {
                    if (DatabaseAsync.TableMappings.All(m => m.MappedType.Name != typeof(T).Name))
                    {
                        await DatabaseAsync.CreateTableAsync(typeof(T), CreateFlags.None).ConfigureAwait(false);

                        AddRegisteredTablet(typeof(T).Name);
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception at ClearTableAsync: {0} {1}", typeof(T).Name, e);
                throw;
            }
        }
コード例 #3
0
        public async Task <List <T> > List(SQLControllerListCriteriaModel criteria)
        {
            try
            {
                if (criteria == null)
                {
                    return(null);
                }

                criteria.View = typeof(T).Name;

                var query = SQLQuery.BuildListQuery <T>(criteria);

                return(await DatabaseAsync.QueryAsync <T>(query));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception at List criteria: {0} {1}", typeof(T).Name, e);
                throw;
            }
        }
コード例 #4
0
ファイル: LocalDataStore.cs プロジェクト: tcerdaj/PoolGuy
        public async Task <T> Modify(T model)
        {
            try
            {
                if (model == null)
                {
                    return(null);
                }

                if (model.Id == Guid.Empty)
                {
                    model.Id = Guid.NewGuid();

                    if (model.Created == null || model.Created == DateTime.MinValue)
                    {
                        model.Created = DateTime.Now.ToUniversalTime();
                    }

                    await DatabaseAsync.InsertAsync(model).ConfigureAwait(false);

                    return(model);
                }
                else
                {
                    model.Modified = DateTime.Now.ToUniversalTime();
                    await DatabaseAsync.UpdateAsync(model).ConfigureAwait(false);

                    return((T)model);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception at Modify: {0} {1}", typeof(T).Name, e);
                throw e;
            }
        }