Exemple #1
0
        public async Task <IActionResult> SearchProducts(string search, string partialName = "", int partialIndex = 0)
        {
            var products = new GetProductSearch(_ctx).Do(new GetProductSearchQuery
            {
                SearchString = search
            }).ToList();

            if (!string.IsNullOrEmpty(partialName))
            {
                if (partialName.Contains("_FavLine"))
                {
                    foreach (var product in products)
                    {
                        product.ProductAddPartialHtml = await _viewRenderService.RenderToStringAsync(partialName, new FavouriteListProductViewModel()
                        {
                            Index      = partialIndex,
                            Id         = product.Id,
                            Code       = product.Code,
                            ImageUrl   = product.ImageUrl,
                            Name       = product.Name,
                            Price      = product.PriceDec.ToString(),
                            Qty        = 1,
                            Uom        = product.UOM,
                            TotalPrice = product.PriceDec.ToString(),
                            Deleted    = false
                        });
                    }
                }
                else if (partialName.Contains("_QuoteLine"))
                {
                    foreach (var product in products)
                    {
                        product.ProductAddPartialHtml = await _viewRenderService.RenderToStringAsync(partialName, new QuoteProductViewModel()
                        {
                            Index       = partialIndex,
                            ProductId   = product.Id,
                            ProductCode = product.Code,
                            ImageUrl    = product.ImageUrl,
                            ProductName = product.Name,
                            Price       = product.PriceDec,
                            Qty         = 1,
                            Uom         = product.UOM,
                            Deleted     = false
                        });
                    }
                }
            }

            return(Ok(products));
        }
Exemple #2
0
        public async Task <IActionResult> OnGet(string category, string id, string topName, string sortValue)
        {
            SortOrderValue = sortValue;
            if (SortOrderValue == "undefined")
            {
                SortOrderValue = "AZ";
            }
            //MainCats = new GetCategories(_context).Do();
            //TopCatName = topName;

            if (category == "main")
            {
                var mainCategory = _context.MainCategories.Where(m => m.Id == id)
                                   .Include(m => m.SubCategories)
                                   .FirstOrDefault();

                CategoryModel = new CategoryViewModel()
                {
                    Id              = id,
                    Name            = mainCategory.CamelName,
                    ChildCategories = mainCategory.SubCategories
                                      .Where(s => !s.Deleted)
                                      .OrderBy(s => s.Name)
                                      .Select(s => new CategoryViewModel()
                    {
                        Id       = s.Id,
                        Name     = s.Name,
                        Type     = "sub",
                        ImageUrl = s.ImageUrl
                    })
                };
            }
            else if (category == "sub")
            {
                var subCategory = await _context.SubCategories.Where(s => s.Id == id)
                                  .Include(s => s.MainCategory)
                                  .Include(s => s.TertiaryCategories)
                                  .FirstOrDefaultAsync();

                CategoryModel = new CategoryViewModel()
                {
                    Id              = id,
                    Name            = subCategory.Name,
                    ChildCategories = subCategory.TertiaryCategories
                                      .Where(t => !t.Deleted)
                                      .OrderBy(t => t.Name)
                                      .Select(t => new CategoryViewModel()
                    {
                        Id       = t.Id,
                        Name     = t.Name,
                        Type     = "tri",
                        ImageUrl = t.ImageUrl
                    }),
                    Path = new List <CategoryViewModel>()
                    {
                        new CategoryViewModel()
                        {
                            Id   = subCategory.MainCategoryId,
                            Name = subCategory.MainCategory.CamelName,
                            Type = "main"
                        }
                    }
                };
            }
            else if (category == "tri")
            {
                var tertiaryCategory = await _context.TertiaryCategories.Where(t => t.Id == id)
                                       .Include(t => t.SubCategory)
                                       .ThenInclude(s => s.MainCategory)
                                       .FirstOrDefaultAsync();

                CategoryModel = new CategoryViewModel()
                {
                    Id   = id,
                    Name = tertiaryCategory.Name,
                    Path = new List <CategoryViewModel>()
                    {
                        new CategoryViewModel()
                        {
                            Id   = tertiaryCategory.SubCategory.MainCategory.Id,
                            Name = tertiaryCategory.SubCategory.MainCategory.CamelName,
                            Type = "main",
                        },
                        new CategoryViewModel()
                        {
                            Id   = tertiaryCategory.SubCategoryId,
                            Name = tertiaryCategory.SubCategory.Name,
                            Type = "sub"
                        }
                    }
                };
            }

            if (!CategoryModel.ChildCategories.Any())
            {
                // Query Products Only if no child category
                Products = new GetProductSearch(_context).Do(new GetProductSearchQuery {
                    CategoryId = id, CategoryType = category
                });
            }

            UserLists = new GetLists(_context).Do(GetUserId());
            return(Page());
        }