Beispiel #1
0
        public async Task <ProductosForIndex2VM> GetProducto()
        {
            List <ProductoCategoria> listaProductosCategorias = await _productoCategoriasService.GetProductosCategorias();

            List <Categoria> listaCategorias = await _categoriasService.GetCategorias();

            ProductosForIndex2VM productosForIndex2VMs = await _productosService.GetProductosForIndex2(listaCategorias, listaProductosCategorias);

            return(productosForIndex2VMs);
        }
Beispiel #2
0
        //Servicio para carga el ViewModel "ProductosForIndex2" en el background y guardarlo en el caché del servidor
        public async Task LoadProductsTask()
        {
            Console.WriteLine("Entra el Task");
            ProductosForIndex2VM listasListaProductos;

            if (!_memoryCache.TryGetValue("ProductosForIndex2", out listasListaProductos))
            {
                listasListaProductos = await _productosService.GetProductosForIndex2();

                //_memoryCache.Set("Categorias", listaCategorias);
                _memoryCache.Set("ProductosForIndex2", listasListaProductos);
                Console.WriteLine("Productos cargados en background");
            }
            else
            {
                Console.WriteLine("Productos ya estaban en caché");
            }
        }
        public async Task <ActionResult <IEnumerable <ProductosForIndex2VM> > > GetAllProductosVM()
        {
            var listaProductosVM = await _productosService.GetProductosForIndex2();

            return(Ok(listaProductosVM));
        }
        public async Task <IActionResult> Index2(string postalCode)
        {
            if (string.IsNullOrEmpty(postalCode))
            {
                if (string.IsNullOrEmpty(HttpContext.Session.GetString("sessionPostalCode")))
                {
                    string postalCodeFromIP = await _helperService.GetPostalCodeFromIP();

                    string cityAndRegionFromIP = await _helperService.GetCityAndRegionFromIP();

                    HttpContext.Session.SetString("sessionPostalCode", postalCodeFromIP);
                    HttpContext.Session.SetString("sessionCity", cityAndRegionFromIP);
                }
            }
            else
            {
                HttpContext.Session.SetString("sessionPostalCode", postalCode);
                string cityFromPostalCode = await _helperService.GetCityFromPostalCode(postalCode);

                HttpContext.Session.SetString("sessionCity", cityFromPostalCode);
            }

            string cp   = HttpContext.Session.GetString("sessionPostalCode");
            string city = HttpContext.Session.GetString("sessionCity");

            ViewData["PostalCode"] = cp;
            ViewData["City"]       = city;


            List <Categoria>         listaCategorias;
            List <ProductoCategoria> listaProductosCategorias;
            ProductosForIndex2VM     listasListaProductos;


            if (!_memoryCache.TryGetValue("ProductosForIndex2", out listasListaProductos))
            {
                listaCategorias = await _categoriasService.GetCategorias();

                listaProductosCategorias = await _productoCategoriasService.GetProductosCategorias();

                listasListaProductos = await _productosService.GetProductosForIndex2(listaCategorias, listaProductosCategorias);

                _memoryCache.Set("Categorias", listaCategorias);
                _memoryCache.Set("ProductosForIndex2", listasListaProductos);
            }
            else
            {
                listasListaProductos = _memoryCache.Get("ProductosForIndex2") as ProductosForIndex2VM;
            }

            if (!_memoryCache.TryGetValue("Categorias", out listaCategorias))
            {
                listaCategorias = await _categoriasService.GetCategorias();

                _memoryCache.Set("Categorias", listaCategorias);
            }
            else
            {
                listaCategorias = _memoryCache.Get("Categorias") as List <Categoria>;
            }

            ViewData["Categorias"] = listaCategorias;
            return(View(listasListaProductos));
        }