Example #1
0
        public Task <List <CategoryModel> > HandleAsync(ListAllCategory query)
        {
            List <CategoryModel> result = new List <CategoryModel>();

            using (ReadModelContext db = new ReadModelContext())
            {
                return(db.Categories
                       .OrderBy(c => c.Name)
                       .Select(e => e.ToModel())
                       .ToListAsync());
            }
        }
Example #2
0
 public async Task <List <CategoryModel> > HandleAsync(ListAllCategory query)
 {
     using (ReadModelContext db = readModelContextFactory.Create())
     {
         return(await db.Categories.WhereUserKey(query.UserKey)
                .WhereUserKey(query.UserKey)
                .Where(c => !c.IsDeleted)
                .OrderBy(c => c.Name)
                .Select(e => e.ToModel())
                .ToListAsync());
     }
 }
        private async Task LoadAllAsync(ListAllCategory listAll, HttpQueryDispatcher.Next next)
        {
            models.Clear();
            if (!network.IsOnline)
            {
                var items = await localStorage.LoadAsync();

                if (items != null)
                {
                    models.AddRange(items);
                    return;
                }
            }

            models.AddRange((List <CategoryModel>) await next(listAll));
            await localStorage.SaveAsync(models);
        }
Example #4
0
        public async Task <List <CategoryModel> > HandleAsync(ListAllCategory query)
        {
            using (ReadModelContext db = readModelContextFactory.Create())
            {
                var sql = db.Categories.WhereUserKey(query.UserKey)
                          .WhereUserKey(query.UserKey);

                if (!query.IncludeDeleted)
                {
                    sql = sql.Where(c => !c.IsDeleted);
                }

                return(await sql
                       .OrderBy(c => c.Name)
                       .Select(e => e.ToModel(query.IncludeIsDeletedFlag))
                       .ToListAsync());
            }
        }
Example #5
0
        private async Task EnsureListAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCategory listAll)
        {
            if (models.Count == 0)
            {
                if (listAllTask == null)
                {
                    listAllTask = LoadAllAsync(dispatcher, next, listAll);
                }

                await listAllTask;
                listAllTask = null;
            }
        }
Example #6
0
        private async Task LoadAllAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCategory listAll)
        {
            models.Clear();
            if (!serverConnection.IsAvailable)
            {
                var items = await localStorage.LoadAsync();

                if (items != null)
                {
                    models.AddRange(items);
                    return;
                }
            }

            if (dispatcher != null)
            {
                models.AddRange(await dispatcher.QueryAsync(listAll));
            }
            else
            {
                models.AddRange((List <CategoryModel>) await next(listAll));
            }

            await localStorage.SaveAsync(models);
        }
Example #7
0
 private async Task LoadAllAsync(ListAllCategory listAll, HttpQueryDispatcher.Next next)
 {
     models.Clear();
     models.AddRange((List <CategoryModel>) await next(listAll));
 }
Example #8
0
        private async Task LoadAllAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCategory listAll)
        {
            models.Clear();
            if (!serverConnection.IsAvailable)
            {
                log.Debug($"Using local storage.");

                var items = await localStorage.LoadAsync();

                if (items != null)
                {
                    models.AddRange(items);
                    return;
                }
            }

            if (dispatcher != null)
            {
                log.Debug("Using dispatcher to run the query. Skipping the query result as other brach will process it.");
                await dispatcher.QueryAsync(listAll);
            }
            else
            {
                log.Debug("Using next middleware to run the query.");
                models.AddRange((List <CategoryModel>) await next(listAll));

                log.Debug("Storing to local storage.");
                await localStorage.SaveAsync(models);
            }
        }
Example #9
0
        private async Task EnsureListAsync(HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next, ListAllCategory listAll)
        {
            log.Debug($"Ensure list, currently has '{models.Count}' models.");

            if (models.Count == 0)
            {
                if (listAllTask == null)
                {
                    log.Debug($"Fire network/storage query.");
                    listAllTask = LoadAllAsync(dispatcher, next, listAll);
                }

                log.Debug($"Awating task.");

                try
                {
                    await listAllTask;
                }
                finally
                {
                    listAllTask = null;
                }

                log.Debug($"Awaiting done.");
            }
        }