Ejemplo n.º 1
0
        public async Task <IEnumerable <Category> > Handle(GetCategories request, CancellationToken cancellationToken)
        {
            var categories = await _context.Categories
                             .ToListAsync(cancellationToken);

            return(categories);
        }
        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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        public IActionResult Index()
        {
            var g            = new GetCategories(_configuration);
            var CategoryList = g.GetList();

            return(View("../Task/Supplier/AddTask", CategoryList));
        }
        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 }));
            }
        }
 protected override IEnumerable <CategoryViewModel> HandleCore(GetCategories query)
 {
     return(_dbContext.Categories
            .Where(x => x.Parent == null && x.Visible)
            .OrderBy(x => x.Ordinal)
            .Select(Transform));
 }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 10
0
        public object GetJson(GetCategories request)
        {
            using (var db = dbFactory.Open()) {
                var categories = db.Select <Category>();

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

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


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

            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 14
0
        public object Get(GetCategories request)
        {
            var result = icategoryService.GetAllCategories();

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

            // STATUS CODE

            return(null);
        }
        public async Task ListCategories()
        {
            APIResponse response = await GetCategories.ExecuteStrategy(null);

            if (response.IsSuccess)
            {
                Categories = JsonConvert.DeserializeObject <List <CategoryModel> >(response.Response);
            }
            else
            {
                Exception e;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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.")));
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 22
0
        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));
        }
Ejemplo n.º 23
0
 public async Task <IActionResult> Get([FromRoute] GetCategories query)
 => Select(await Dispatcher.QueryAsync(query));
Ejemplo n.º 24
0
 public async Task <IEnumerable <CategoryDto> > HandleAsync(GetCategories query)
 {
     return(await _categoryService.BrowseAsync());
 }
Ejemplo n.º 25
0
 public IActionResult GetCategories(
     [FromServices] GetCategories getCategories) =>
 Ok(getCategories.Do());
Ejemplo n.º 26
0
        public async Task <IEnumerable <CategoryOfProduct> > HandleAsync(GetCategories query)
        {
            var categories = await _context.CategoriesOfProduct.OrderBy(cop => cop.Name).ToListAsync();

            return(categories);
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> GetCategories([FromQuery] GetCategories query)
        {
            var result = await _mediator.Send(query);

            return(JsonResult(result));
        }
Ejemplo n.º 28
0
 public Task <List <CategoryReadModel> > HandleAsync(GetCategories query)
 {
     return(_categoryRead.GetCategoriesAsync());
 }
Ejemplo n.º 29
0
 public void OnGet([FromServices] GetFeaturedProducts getFeaturedProducts,
                   [FromServices] GetCategories getCategories)
 {
     Products   = getFeaturedProducts.Action();
     Categories = getCategories.Action();
 }
Ejemplo n.º 30
0
        public IActionResult GetCategories([FromServices] GetCategories getCategories)
        {
            var categories = getCategories.Do();

            return(Ok(categories));
        }
Ejemplo n.º 31
0
 public async Task <PageModel <CategoryModel> > GetCategoriesAsync([FromBody] GetCategories getCategories)
 {
     return(await _mediator.Send(getCategories));
 }