Ejemplo n.º 1
0
 public IActionResult Detail([FromQuery] int id)
 {
     try
     {
         var product = _productService.GetOne(c => c.Id == id);
         if (product == null)
         {
             return(NotFound());
         }
         product.ProductsCategories = _productCategories.GetAll(c => c.Products_Id == id);
         var response = new
         {
             product
         };
         return(Ok(response));
     }
     catch (Exception e)
     {
         var error    = e.InnerException != null ? e.InnerException.Message : e.Message;
         var response = new
         {
             error = error
         };
         return(StatusCode(512, response));
     }
 }
Ejemplo n.º 2
0
        public override ActionResult Search()
        {
            var model          = new ProductSearchViewModel();
            var formCollection = new FormCollection(Request.Form);

            TryUpdateModel <ProductSearchViewModel>(model, formCollection);

            var keyword = Request.QueryString["keyword"];

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                model.Keywords = keyword;
            }

            var selectedColours = Request.QueryString["SelectedColours"];

            if (!string.IsNullOrWhiteSpace(selectedColours))
            {
                model.SelectedColours = selectedColours;
            }

            model.ProductCategories = _productCategoriesService.GetAll().ToList();
            model.Options           = _skuAttributeOptionsService.GetAll().ToList();

            model.IsPatternsFilterVisible       = model.Options.Any(x => x.SkuAttribute.Name == "Pattern");
            model.IsEndUseFilterVisible         = model.Options.Any(x => x.SkuAttribute.Name == "End Use");
            model.IsTypeFilterVisible           = model.Options.Any(x => x.SkuAttribute.Name == "Type");
            model.IsFlameRetardantFilterVisible = model.Options.Any(x => x.SkuAttribute.Name == "Flame Retardant");
            model.IsMatindalFilterVisible       = model.Options.Any(x => x.SkuAttribute.Name == "Martindale");
            model.IsPriceFilterVisible          = model.IsPatternsFilterVisible && model.IsEndUseFilterVisible && model.IsTypeFilterVisible &&
                                                  model.IsFlameRetardantFilterVisible && model.IsMatindalFilterVisible;
            model.IsProductCategoryFilterVisibel = model.IsPatternsFilterVisible && model.IsEndUseFilterVisible && model.IsTypeFilterVisible &&
                                                   model.IsFlameRetardantFilterVisible && model.IsMatindalFilterVisible;

            return(PartialView(model));
        }