コード例 #1
0
        public async Task <IEnumerable <Category> > Handle(GetCategories request, CancellationToken cancellationToken)
        {
            var categories = await _context.Categories
                             .ToListAsync(cancellationToken);

            return(categories);
        }
コード例 #2
0
        public async Task <List <CategoryViewModel> > Handle(GetCategories message, CancellationToken cancellationToken)
        {
            if (message.ParentId != null && message.ParentId <= 0)
            {
                throw new Exception(Constants.INVALID_ID);
            }

            var command = context.Categories
                          .Where(c => c.ForEntity == "bun");

            if (message.ParentsOnly == true)
            {
                command = command.Where(c => c.ParentId == null);
            }
            else
            {
                command = command.Where(c => c.ParentId == message.ParentId);
            }

            var models = await command
                         .Select(c => mapper.Map <CategoryViewModel>(c))
                         .ToListAsync(cancellationToken);

            return(models);
        }
コード例 #3
0
        public async Task <QueryResult <CategoryResponse> > Handle(GetCategories request, CancellationToken cancellationToken)
        {
            Expression <Func <Category, bool> > deletedFilter = x => !x.IsDeleting;
            Expression <Func <Category, bool> > searchFilter  = x => (string.IsNullOrWhiteSpace(request.SearchQuery)) ||
                                                                x.Name.ToUpper().Contains(request.SearchQuery.ToUpper());

            var count = await _shopContext.Categories
                        .Where(deletedFilter)
                        .Where(searchFilter)
                        .CountAsync(cancellationToken).ConfigureAwait(false);

            if (count == 0)
            {
                return(new QueryResult <CategoryResponse>());
            }

            var categories = await _shopContext.Categories
                             .Where(deletedFilter)
                             .Where(searchFilter)
                             .AddPaging(request)
                             .ToListAsync(cancellationToken).ConfigureAwait(false);

            var response = categories.Select(x => x.ToResponse()).ToList();
            var paging   = CreatePaging(request, count);

            return(new QueryResult <CategoryResponse>(response, paging));
        }
コード例 #4
0
        public ReactiveAddIncomeTransactionViewModel(ITransactionService transactionService, IViewModelNavigationService navigationService, ICategoriesService categoriesService, IUserDialogs userDialogs)
        {
            _transactionService = transactionService;
            _navigationService  = navigationService;
            _categoriesService  = categoriesService;

            var isValidCategory = this.WhenAnyValue(m => m.SelectedCategory)
                                  .Select(c => c != null);

            var isValidValue = this.WhenAnyValue(m => m.Value)
                               .Select(IsValidValue);

            var canAddTransaction = isValidCategory.Merge(isValidValue);

            AddTransactionCommand = ReactiveCommand.CreateFromObservable <Unit>(AddTransactionAsync, canAddTransaction);
            GetCategories         = ReactiveCommand.CreateFromObservable <Unit, IEnumerable <CategoryModel> >(GetCategoriesAsync);

            _categories = GetCategories
                          .Select(categories => new ObservableCollection <CategoryModel>(categories))
                          .Select(categories => new ReadOnlyObservableCollection <CategoryModel>(categories))
                          .ToProperty(this, vm => vm.Categories);

            AddTransactionCommand.ThrownExceptions.Subscribe(ex => userDialogs.Alert(ex.Message));

            AddTransactionCommand
            .Subscribe(Observer.Create <Unit>(OnAddTransactionComplete));

            StateObservable
            .Where(s => s == ViewModelState.Disappered)
            .Subscribe(Observer.Create <ViewModelState>(ClearData));

            StateObservable.Where(s => s == ViewModelState.Appeared)
            .Select(_ => Unit.Default)
            .InvokeCommand(GetCategories);
        }
コード例 #5
0
        public IActionResult Index()
        {
            var g            = new GetCategories(_configuration);
            var CategoryList = g.GetList();

            return(View("../Task/Supplier/AddTask", CategoryList));
        }
コード例 #6
0
        public IActionResult LoadUnRelatedCategory(long?ID, long?CategoryID, long?ProductID, long?ProductDetailID,
                                                   long?CategoryLevel, long?LineOfBusniess, long?SubLineOfBusniess, long?langId)
        {
            GetProductCategory operation  = new GetProductCategory();
            GetCategories      operation2 = new GetCategories();

            operation.ID                 = ID;
            operation.ProductID          = ProductID;
            operation.CategoryID         = CategoryID;
            operation.ProductDetailID    = ProductDetailID;
            operation.CategoryLevel      = CategoryLevel;
            operation.LineOfBusniess     = LineOfBusniess;
            operation.SubLineOfBusniess  = SubLineOfBusniess;
            operation2.LineOfBusniess    = LineOfBusniess;
            operation2.SubLineOfBusniess = SubLineOfBusniess;
            operation2.CategoryLevel     = CategoryLevel;
            if (langId.HasValue)
            {
                operation.LangID  = langId;
                operation2.LangID = langId;
            }
            else
            {
                operation.LangID  = 1;
                operation2.LangID = 1;
            }


            var result            = operation.QueryAsync().Result;
            var productCategories = (List <ProductCategory>)result;
            var categories        = (List <Category>)operation2.QueryAsync().Result;
            List <ProductCategory> RelatedCategories   = new List <ProductCategory>();
            List <Category>        UnRelatedCategories = new List <Category>();

            if (productCategories.Count > 0)
            {
                RelatedCategories   = productCategories.Where(p => categories.Any(s => s.ID == p.CategoryID && (s.SubLineOfBusniess == SubLineOfBusniess || s.SubLineOfBusniess == null))).ToList();
                UnRelatedCategories = categories.Where(s => productCategories.Any(p => p.CategoryID != s.ID &&
                                                                                  (s.SubLineOfBusniess == SubLineOfBusniess || s.SubLineOfBusniess == null))).ToList();

                UnRelatedCategories = UnRelatedCategories.Where(un => !RelatedCategories.Exists(re => un.ID == re.CategoryID)).ToList();
            }
            else
            {
                UnRelatedCategories = categories.Where(s => s.SubLineOfBusniess == SubLineOfBusniess || s.SubLineOfBusniess == null).ToList();
            }


            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok(new { UnRelatedCategories, RelatedCategories }));
            }
        }
コード例 #7
0
 protected override IEnumerable <CategoryViewModel> HandleCore(GetCategories query)
 {
     return(_dbContext.Categories
            .Where(x => x.Parent == null && x.Visible)
            .OrderBy(x => x.Ordinal)
            .Select(Transform));
 }
コード例 #8
0
        public IActionResult Load(long?ID, long?langId, long?lineOfBussniess, long?subLineOfBussniess, long?categoryLevel)
        {
            GetCategories operation = new GetCategories();

            operation.ID                = ID;
            operation.CategoryLevel     = categoryLevel;
            operation.LineOfBusniess    = lineOfBussniess;
            operation.SubLineOfBusniess = subLineOfBussniess;

            if (langId.HasValue)
            {
                operation.LangID = langId;
            }
            else
            {
                operation.LangID = 1;
            }

            var result = operation.QueryAsync().Result;

            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok((List <Category>)result));
            }
        }
コード例 #9
0
        public IActionResult EditTask(int Id)
        {
            GetOpenTasks  q            = new GetOpenTasks(_configuration);
            GetCategories g            = new GetCategories(_configuration);
            var           CategoryList = g.GetList();

            ViewBag.Task = q.GetSingleTask(Id);
            return(View("../Task/Supplier/EditTask", CategoryList));
        }
コード例 #10
0
ファイル: ApiServices.cs プロジェクト: sdellenb/joybox2
        public object GetJson(GetCategories request)
        {
            using (var db = dbFactory.Open()) {
                var categories = db.Select <Category>();

                return(new CategoriesResponse {
                    Status = "success",
                    Data = categories
                });
            }
        }
コード例 #11
0
 public GetCategoriesResponse GetCategories()
 {
     using (JsConfig
            .With(propertyConvention: PropertyConvention.Lenient,
                  emitLowercaseUnderscoreNames: true,
                  emitCamelCaseNames: false))
     {
         var request = new GetCategories();
         return(client.Get(request));
     }
 }
コード例 #12
0
        public object Get(GetCategories request)
        {

            using (IDbConnection db = DbFactory.Open())
            {
                var categories = db.Select<Category>().ToList();


                return new GetCategoriesResponse { Result = categories.ToList() };

            }
        }
コード例 #13
0
        public async Task GetSubCategories_Expected2Categories()
        {
            var queryHandler = new GetCategoriesHandler(BasicNeeds);
            var query        = new GetCategories()
            {
                ParentsOnly = false, ParentId = 1
            };

            var actual = await queryHandler.Handle(query, CancellationToken.None);

            Assert.IsTrue(actual.Count == 2);
        }
コード例 #14
0
        public object Get(GetCategories request)
        {
            var result = icategoryService.GetAllCategories();

            if (result.Success)
            {
                return(result.Entities.ToList());
            }

            // STATUS CODE

            return(null);
        }
コード例 #15
0
        public async Task ListCategories()
        {
            APIResponse response = await GetCategories.ExecuteStrategy(null);

            if (response.IsSuccess)
            {
                Categories = JsonConvert.DeserializeObject <List <CategoryModel> >(response.Response);
            }
            else
            {
                Exception e;
            }
        }
コード例 #16
0
        public void OnGet(
            [FromServices] GetProducts getProducts,
            [FromServices] GetCategories getCategories,
            int pageNumber = 1, int pageSize = PageZize)
        {
            IndexViewModel = new IndexViewModel {
                Products   = getProducts.Do(pageNumber, pageSize),
                Categories = getCategories.Do()
            };
            var taskCount = getProducts.GetProductsCount();
            int count     = taskCount.Result;

            PageViewModel = new PageViewModel(count, pageNumber, PageZize);
        }
コード例 #17
0
ファイル: DBObject.cs プロジェクト: JackyEnclave/TeaTimeSite
        public static void Initial(DBContent content)
        {
            if (!content.Category.Any())
            {
                content.Category.AddRange(GetCategories.Select(cont => cont.Value));
            }

            if (!content.Goods.Any())
            {
                content.AddRange(
                    new Goods
                {
                    name        = "Иу Шань Шу Пуэр",
                    shortDesc   = @"""Знаменитый Юньнаньский чай""",
                    longDesc    = "Классика от Мэнхайской чайной фабрики - знаменитый V93",
                    img         = "/img/v93.jpg",
                    price       = 5m,
                    isFavorite  = true,
                    isAvailable = true,
                    Category    = GetCategories["Пуэры"],
                },

                    new Goods
                {
                    name        = "Да Хун Пао",
                    shortDesc   = @"""Большой Красный Халат""",
                    longDesc    = "Наряду с теплыми медово-шоколадными нотами мирно соседствуют веселые звенящие цветочные ноты, дополняясь древесностью и фруктовостью",
                    img         = "/img/dhp.jpg",
                    price       = 5.5m,
                    isFavorite  = true,
                    isAvailable = true,
                    Category    = GetCategories["Улуны"],
                },

                    new Goods
                {
                    name        = "Хун Маофен",
                    shortDesc   = @"""Красные Ворсистые Пики""",
                    longDesc    = "Бюджетнейший красный чай, выпивается мной литрами, когда нет желания церемониться",
                    img         = "/img/hmf.jpg",
                    price       = 3.2m,
                    isFavorite  = true,
                    isAvailable = true,
                    Category    = GetCategories["Красный чай"],
                }
                    );
            }
            content.SaveChanges();
        }
コード例 #18
0
        public void OnGetByCategoryId(
            [FromServices] GetProducts getProducts,
            [FromServices] GetCategories getCategories,
            string categoryId,
            int pageNumber = 1, int pageSize = PageZize)
        {
            IndexViewModel = new IndexViewModel {
                Products   = getProducts.Do(categoryId, pageNumber, pageSize),
                Categories = getCategories.Do()
            };
            selectedCategoryId = categoryId;
            var taskCount = getProducts.GetProductsCount(selectedCategoryId);
            int count     = taskCount.Result;

            PageViewModel = new PageViewModel(count, pageNumber, PageZize);
        }
コード例 #19
0
        public void OnGetSearchProduct(
            [FromServices] GetProducts getProducts,
            [FromServices] GetCategories getCategories,
            string searchString)
        {
            IndexViewModel = new IndexViewModel {
                Products = string.IsNullOrEmpty(searchString)
                                        ? getProducts.Do(1, PageZize)
                                        : getProducts.Do(searchString),
                Categories = getCategories.Do()
            };
            var taskCount = getProducts.GetProductsCount();
            int count     = taskCount.Result;

            PageViewModel = new PageViewModel(count, 1, PageZize);
        }
コード例 #20
0
 public string GetCategoriesList()
 {
     if (SecureAuthentication != null)
     {
         int Output = CheckLoginReturnUserId(SecureAuthentication).ValueFromSQL;
         if (Output > 0)
         {
             GetCategories proc = new GetCategories();
             return("{\"CategoriesList\" : " + Serialize(proc.GetCategoriesList()) + "}");
         }
         else
         {
             return(Serialize(new AuthResponse(0, Output == -1 ? "Authentication is NULL" : "Invalid Authentication")));
         }
     }
     return(Serialize(new AuthResponse(0, "Authentication information not provided.")));
 }
コード例 #21
0
        public async Task ListCategories()
        {
            APIResponse response = await GetCategories.ExecuteStrategy(null);

            if (response.IsSuccess)
            {
                Categories = JsonConvert.DeserializeObject <List <CategoryModel> >(response.Response);

                /*int categoryIdxCounter = 0;
                 * foreach (var c in Categories)
                 * {
                 *  if (Product.IdCategory == c.IdCategory)
                 *  {
                 *      ProductIndexCategory = categoryIdxCounter;
                 *  }
                 *  categoryIdxCounter += 1;
                 * }*/
            }
            else
            {
                Exception e;
            }
        }
コード例 #22
0
ファイル: CategoryViewComponent.cs プロジェクト: Bronwin87/OB
        public IViewComponentResult Invoke()
        {
            List <MainCategory> mainMenu = new List <MainCategory>();

            // netcore caching
            // https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-2.2
            if (!_cache.TryGetValue(_menuCacheKey, out mainMenu))
            {
                // "MainMenu" key not in cache, get data from DB
                mainMenu = new GetCategories(_ctx).DoMenu().ToList();

                var cacheOptions = new MemoryCacheEntryOptions()
                                   // Sets cache entry size (only used if mimimum cache size is set in startup)
                                   //.SetSize(1)
                                   // Set's cache timeout period, resets if accessed
                                   .SetSlidingExpiration(TimeSpan.FromMinutes(30));

                // Save menu data in cache
                _cache.Set(_menuCacheKey, mainMenu, cacheOptions);
            }

            return(View(mainMenu));
        }
コード例 #23
0
 public async Task <IActionResult> Get([FromRoute] GetCategories query)
 => Select(await Dispatcher.QueryAsync(query));
コード例 #24
0
 public async Task <IEnumerable <CategoryDto> > HandleAsync(GetCategories query)
 {
     return(await _categoryService.BrowseAsync());
 }
コード例 #25
0
 public IActionResult GetCategories(
     [FromServices] GetCategories getCategories) =>
 Ok(getCategories.Do());
コード例 #26
0
        public async Task <IEnumerable <CategoryOfProduct> > HandleAsync(GetCategories query)
        {
            var categories = await _context.CategoriesOfProduct.OrderBy(cop => cop.Name).ToListAsync();

            return(categories);
        }
コード例 #27
0
        public async Task <IActionResult> GetCategories([FromQuery] GetCategories query)
        {
            var result = await _mediator.Send(query);

            return(JsonResult(result));
        }
コード例 #28
0
 public Task <List <CategoryReadModel> > HandleAsync(GetCategories query)
 {
     return(_categoryRead.GetCategoriesAsync());
 }
コード例 #29
0
 public void OnGet([FromServices] GetFeaturedProducts getFeaturedProducts,
                   [FromServices] GetCategories getCategories)
 {
     Products   = getFeaturedProducts.Action();
     Categories = getCategories.Action();
 }
コード例 #30
0
ファイル: CategoriesController.cs プロジェクト: Astrank/epe
        public IActionResult GetCategories([FromServices] GetCategories getCategories)
        {
            var categories = getCategories.Do();

            return(Ok(categories));
        }
コード例 #31
0
 public async Task <PageModel <CategoryModel> > GetCategoriesAsync([FromBody] GetCategories getCategories)
 {
     return(await _mediator.Send(getCategories));
 }