Ejemplo n.º 1
0
        public JsonResult GetProductsByCategory(string categoryId)
        {
            var category = Guid.Parse(categoryId);
            var products = bus.RunQuery(new GetProductsFromCategoryQuery {
                CategoryId = category
            });
            var productViewModel = mapper.Map <ProductTileViewModel[]>(products);
            var productsJson     = JsonConvert.SerializeObject(productViewModel,
                                                               Formatting.None,
                                                               new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Json(productsJson, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            var products = bus.RunQuery(new GetLastProductsQuery {
                Amount = 4
            });
            var viewModel = mapper.Map <ProductTileViewModel[]>(products);

            foreach (var productTileViewModel in viewModel)
            {
                pictureResizer.Resize(productTileViewModel, Request.Browser.IsMobileDevice);
            }
            return(View("Index", viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult RedirectToProduct(string productId)
        {
            var encodedId = ShortGuid.Decode(productId);
            var product   = bus.RunQuery(new GetProductByIdQuery {
                ProductId = encodedId
            });

            if (product == null)
            {
                return(View("Error"));
            }

            return(Redirect(product.ProductUrl));
        }
        public void Validate(Product objectToValidate)
        {
            var productNames = bus.RunQuery(new GetAllProductNamesFromCategoryQuery {
                CategoryId = objectToValidate.IdCategory
            });
            var name = objectToValidate.UrlFriendlyName
                       .RemoveWhiteSpace()
                       .RemoveSpecialCharacters();
            var isNameExists = productNames.Any(x => string.Equals(x.Trim(), name.Trim(), StringComparison.InvariantCultureIgnoreCase));

            if (isNameExists)
            {
                objectToValidate.UrlFriendlyName = name + ShortGuid.NewGuid();
            }
            else
            {
                objectToValidate.UrlFriendlyName = name;
            }
        }
Ejemplo n.º 5
0
        public JsonResult GetCategories()
        {
            var categories = bus.RunQuery(new GetAllCategoriesQuery());

            return(Json(categories, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
 public AuthController(ICqrsBus bus)
 {
     userManager = bus.RunQuery(new GetApplicationUserManagerQuery());
 }