public async Task <IActionResult> Index(int?page, int categoriesFilterApplied,
                                                int typesFilterApplied, int locationsFilterApplied)
        {
            var itemsOnPage = 9;

            var catalog = await _service.GetCatalogItemsAsync(page ?? 0, itemsOnPage,
                                                              categoriesFilterApplied, typesFilterApplied, locationsFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems   = catalog.Data,
                PaginationInfo = new PaginationInfo
                {
                    ActualPage = page ?? 0,
                    //ItemsPerPage = itemsOnPage,
                    ItemsPerPage = Math.Min(itemsOnPage, (int)catalog.Count),
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)catalog.Count / itemsOnPage)
                },
                Categories = await _service.GetCategoriesAsync(),
                Types      = await _service.GetTypesAsync(),
                Locations  = await _service.GetLocationsAsync(),
                CategoriesFilterApplied = categoriesFilterApplied,
                TypesFilterApplied      = typesFilterApplied,
                LocationsFilterApplied  = locationsFilterApplied
            };

            return(View(vm));
        }
Exemple #2
0
        public async Task <IActionResult> Index(int?BrandFilterApplied, int?TypesFilterApplied, int?page)
        {
            int itemsPage = 10;
            var catalog   = await _catalogSvc.GetCatalogItems(page ?? 0, itemsPage, BrandFilterApplied, TypesFilterApplied);

            var vm = new CatalogIndexViewModel()
            {
                CatalogItems       = catalog.Data,
                Brands             = await _catalogSvc.GetBrands(),
                Types              = await _catalogSvc.GetTypes(),
                BrandFilterApplied = BrandFilterApplied ?? 0,
                TypesFilterApplied = TypesFilterApplied ?? 0,
                PaginationInfo     = new PaginationInfo()
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = itemsPage, //catalog.Data.Count,
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling(((decimal)catalog.Count / itemsPage))
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(View(vm));
        }
Exemple #3
0
        public async Task <IActionResult> Index(int?categoriesFilterApplied,
                                                int?formatsFilterApplied, int?page)
        {
            var itemsOnPage = 9;

            var catalog = await _service.GetCatalogItemsAsync(page ?? 0, itemsOnPage,
                                                              categoriesFilterApplied, formatsFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems            = catalog.Data,
                Categories              = await _service.GetCategoriesAsync(),
                Formats                 = await _service.GetFormatsAsync(),
                CategoriesFilterApplied = categoriesFilterApplied ?? 0,
                FormatsFilterApplied    = formatsFilterApplied ?? 0,
                PaginationInfo          = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    TotalItems   = catalog.Count,
                    ItemsPerPage = catalog.Data.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)catalog.Count / itemsOnPage)
                }
            };


            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";


            return(View(vm));
        }
Exemple #4
0
        public async Task <IActionResult> Index(int?typesFilterApplied, int?categoryFilterApplied, int?locationFilterApplied, int?page)
        {
            var eventsOnPage = 10;
            var catalog      = await _service.GetEventsCatalogAsync(page ?? 0, eventsOnPage, typesFilterApplied, categoryFilterApplied, locationFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                PaginationInfo = new PaginationInfo
                {
                    ActualPage    = page ?? 0,
                    EventsPerPage = catalog.Data.Count,
                    TotalEvents   = catalog.Count,
                    TotalPages    = (int)Math.Ceiling((decimal)catalog.Count / eventsOnPage)
                },
                CatalogEvents         = catalog.Data,
                Categories            = await _service.GetEventCategoriesAsync(),
                Types                 = await _service.GetEventTypesAsync(),
                Locations             = await _service.GetEventLocationsAsync(),
                TypesFilterApplied    = typesFilterApplied ?? 0,
                CategoryFilterApplied = categoryFilterApplied ?? 0,
                LocationFilterApplied = locationFilterApplied ?? 0
            };

            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";

            return(View(vm));
        }
Exemple #5
0
        public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId)
        {
            CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId ?? 0, Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied);

            try
            {
                var bannersResult = await _config["Empay:BannerEndpointUrl"]
                                    .PostJsonAsync(new
                {
                    txn_id  = "14",
                    ad_type = "banner"
                })
                                    .ReceiveJson <BannerViewModel>()
                                    .ConfigureAwait(false);

                if (bannersResult != null && bannersResult.status == "success")
                {
                    CatalogModel.Ads = bannersResult.results;
                }
            }
            catch (Exception)
            {
                // TODO: log
            }
        }
        public async Task <IActionResult> Index(int?page, int?categoryFilterApplied, string searchTerm)
        {
            const int itemsPerPage = 12;
            var       catalog      = await _catalogService.GetCatalogItems(page ?? 1, itemsPerPage, categoryFilterApplied, searchTerm);

            if (HttpContext.Session.GetString("currencyRate") != null)
            {
                TryParse(HttpContext.Session.GetString("currencyRate"), out decimal rate);
                catalog.Data.ForEach(i => i.ConvertedPrice = i.Price * rate);
            }
            else
            {
                catalog.Data.ForEach(i => i.ConvertedPrice = i.Price);
            }

            var vm = new CatalogIndexViewModel()
            {
                CatalogItems   = catalog.Data,
                Categories     = await _catalogService.GetCategories(),
                PaginationInfo = new PaginationInfo()
                {
                    ActualPage   = page ?? 1,
                    ItemsPerPage = catalog.Data.Count,
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling(((decimal)catalog.Count / itemsPerPage))
                },
                CategoryFilterApplied = categoryFilterApplied,
                SearchTerm            = searchTerm
            };

            return(View(vm));
        }
        public async Task <IActionResult> Index(int?categoryFilterApplied, int?placeFilterApplied, int?page)
        {
            var itemsOnPage = 10;
            var catalog     = await _CatalogService.GetcatalogItemsAsync(page ?? 0, itemsOnPage, categoryFilterApplied,
                                                                         placeFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                EventCatalogItems     = catalog.Data,
                Categories            = await _CatalogService.GetCategoriesAsync(),
                Places                = await _CatalogService.GetPlacesAsync(),
                CategoryFilterApplied = categoryFilterApplied ?? 0,
                PlaceFilterApplied    = placeFilterApplied ?? 0,
                PaginationInfo        = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = itemsOnPage,
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)catalog.Count / itemsOnPage)
                }
            };

            vm.PaginationInfo.PreviousPage = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
            vm.PaginationInfo.NextPage     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";


            return(View(vm));
        }
Exemple #8
0
        public async Task <IActionResult> Index(int?page, int?brandFilterApplied,
                                                int?typesFilterApplied)
        {
            var itemsOnPage = 10;

            var catalog = await _service.GetCatalogItemsAsync(page ?? 0, itemsOnPage,
                                                              brandFilterApplied, typesFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems   = catalog.Data,
                PaginationInfo = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = itemsOnPage,
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)catalog.Count / itemsOnPage)
                },
                Brands             = await _service.GetBrandsAsync(),
                Types              = await _service.GetTypesAsync(),
                BrandFilterApplied = brandFilterApplied ?? 0,
                TypesFilterApplied = typesFilterApplied ?? 0
            };


            return(View(vm));
        }
Exemple #9
0
        public async Task <IActionResult> Index(int?page, int?brandFilterApplied,
                                                int?typesFilterApplied)
        {
            var itemsOnPage = 10;
            //int?? 0 means if int is null ie no page is selected then select 0 page
            var catalog = await _service.GetCatalogItemsAsync(page ?? 0, itemsOnPage,
                                                              brandFilterApplied, typesFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems   = catalog.Data,
                PaginationInfo = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = itemsOnPage,
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)catalog.Count / itemsOnPage)
                },
                Brands             = await _service.GetBrandsAsync(), // defined in CatalogServive.cs ie get data from service
                Types              = await _service.GetTypesAsync(),
                BrandFilterApplied = brandFilterApplied ?? 0,         //BrandFilterApplied is null then leave it as 0
                TypesFilterApplied = typesFilterApplied ?? 0
            };


            return(View(vm));

            /*here it will try to find a view ie folder that matches the controller name ie Catalog so that all data can be rendered
             * through that page . Inside that Catalog folder it will look for page with name index*/
        }
Exemple #10
0
        public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId)
        {
            var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageId.GetValueOrDefault(), ApplicationConstants.ITEMS_PER_PAGE, catalogModel.brandFilterApplied, catalogModel.typeFilterApplied);

            _cache.Remove(cacheKey);
            CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId.GetValueOrDefault(), ApplicationConstants.ITEMS_PER_PAGE, catalogModel.brandFilterApplied, catalogModel.typeFilterApplied);
        }
        public async Task <IActionResult> Index(int?page, int?locationFilterApplied, int?typesFilterApplied)
        {
            var itemsOnPage = 10;

            var events = await _service.GetEventItemsAsync(page ?? 0, itemsOnPage,
                                                           locationFilterApplied, typesFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems   = events.Data,
                PaginationInfo = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = (int)(events.Count / itemsOnPage > 0 ? itemsOnPage : events.Count - page * itemsOnPage),
                    TotalItems   = events.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)events.Count / itemsOnPage)
                },
                Location = await _service.GetLocationAsync(),
                Types    = await _service.GetTypeAsync(),
                LocationFilterApplied = locationFilterApplied ?? 0,
                TypesFilterApplied    = typesFilterApplied ?? 0
            };

            return(View(vm));
        }
Exemple #12
0
        public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId)
        {
            var catalog = await new GetCatalogCommand(GetCatalogFromServer, GetCatalogFromCache, pageIndex, itemsPage, brandId, typeId).ExecuteAsync();

            var vm = new CatalogIndexViewModel()
            {
                CatalogItems = catalog.Data.Select(i => new CatalogItemViewModel()
                {
                    Id         = i.Id,
                    Name       = i.Name,
                    PictureUri = i.PictureUri,
                    Price      = i.Price
                }),
                Brands             = await GetBrands(),
                Types              = await GetTypes(),
                BrandFilterApplied = brandId ?? 0,
                TypesFilterApplied = typeId ?? 0,
                PaginationInfo     = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = catalog.Data.Count,
                    TotalItems   = catalog.Count,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)catalog.Count / itemsPage)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }
Exemple #13
0
        public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId)
        {
            _logger.LogInformation("GetCatalogItems called.");

            var filterSpecification          = new CatalogFilterSpecification(brandId, typeId);
            var filterPaginatedSpecification =
                new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId);

            // the implementation below using ForEach and Count. We need a List.
            var itemsOnPage = _itemRepository.List(filterPaginatedSpecification).ToList();
            var totalItems  = _itemRepository.Count(filterSpecification);

            // Initial implementation
            itemsOnPage.ForEach(x =>
            {
                x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
            });


            // Adding a reference to use an Azure Storage Blob

            /*
             * itemsOnPage.ForEach(x =>
             * {
             *  StorageCredentials credentials = new WindowsAzure.Storage.Auth.StorageCredentials("{YOUR_STORAGE_ACCOUNT_NAME}", "{YOUR_STORAGE_PRIMARY_KEY}");
             *  CloudStorageAccount storageAccount = new WindowsAzure.Storage.CloudStorageAccount(credentials, true);
             *  Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = new WindowsAzure.Storage.Blob.CloudBlobClient(storageAccount.BlobStorageUri.PrimaryUri, credentials);
             *  Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blockblob = new WindowsAzure.Storage.Blob.CloudBlockBlob(new Uri(x.PictureUri));
             *  var blob = blockblob.OpenReadAsync();
             *  x.PictureUri = _uriComposer.ComposePicUri(blockblob.Uri.ToString());
             * });
             */

            var vm = new CatalogIndexViewModel()
            {
                CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel()
                {
                    Id         = i.Id,
                    Name       = i.Name,
                    PictureUri = i.PictureUri,
                    Price      = i.Price
                }),
                Brands             = await GetBrands(),
                Types              = await GetTypes(),
                BrandFilterApplied = brandId ?? 0,
                TypesFilterApplied = typeId ?? 0,
                PaginationInfo     = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = itemsOnPage.Count,
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }
        public async Task <IActionResult> Index(int?brandFilterApplied, int?typeFilterApplied, int?pageIndex)
        {
            const int ItemPage = 10;

            var catalogItems =
                await _catalogService.GetCatalogItems(pageIndex ?? 0, ItemPage, brandFilterApplied, typeFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems       = catalogItems.Items,
                BrandFilterApplied = brandFilterApplied ?? 0,
                TypeFilterApplied  = typeFilterApplied ?? 0,
                Brands             = await _catalogService.GetBrands(),
                Types          = await _catalogService.GetTypes(),
                PaginationInfo = new PaginationInfo
                {
                    ActualPage   = pageIndex ?? 0,
                    ItemsPerPage = ItemPage,
                    TotalItems   = catalogItems.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)catalogItems.Count / ItemPage)
                }
            };

            vm.PaginationInfo.Previous = vm.PaginationInfo.ActualPage == 0
                ? "is-disabled"
                : "";

            vm.PaginationInfo.Next = vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1
                ? "is-disabled"
                : "";

            return(View(vm));
        }
Exemple #15
0
        //the client will tell what page it is. so view will tell that
        //int? is if the page number is null
        public async Task <IActionResult> Index(int?page, int?brandFilteredApplied, int?typesFilterApplied)
        {
            //telling how many pages we need to show on the ui.
            var itemsOnPage = 10;
            //calling the method in the catalog service
            //page?? 0 is a terinary operator if page is nul then 0.
            var catalog = await _service.GetCatalogItemsAsync(page ?? 0, itemsOnPage, brandFilteredApplied, typesFilterApplied);

            //there is a class called catalogindexviewmodel from there we are passing the data here
            var vm = new CatalogIndexViewModel
            {
                CatalogItems   = catalog.Data,
                PaginationInfo = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = itemsOnPage,
                    TotalItems   = catalog.Count,
                    //total pages are 15/10(total 15 count divided by itemson page)
                    //ceiling meaning rounded to the next number.
                    TotalPages = (int)Math.Ceiling((decimal)catalog.Count / itemsOnPage)
                },
                //calling brands method from service
                Brands = await _service.GetBrandsAsync(),
                //calling types method from types
                Types = await _service.GetTypesAsync(),

                //if brandsfilteredapplied if it is null make it as 0
                BrandFilterApplied = brandFilteredApplied ?? 0,
                //if typesfilteredapplied if it is null make it as 0
                TypesFilterApplied = typesFilterApplied ?? 0
            };


            return(View(vm));
        }
        public async Task <IActionResult> Index(int?page, int?locationFilterApplied, int?typeFilterApplied)
        {
            var itemsPerPage = 10;

            var catalog = await _service.GetEventItemsAsync(page ?? 0, itemsPerPage, locationFilterApplied, typeFilterApplied);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems   = catalog.Data,
                Locations      = await _service.GetEventLocationAsync(),
                Types          = await _service.GetEventTypeAsync(),
                PaginationInfo = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = itemsPerPage,
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)(catalog.Count) / itemsPerPage)
                },

                LocationFilterApplied = locationFilterApplied ?? 0,
                TypesFilterApplied    = typeFilterApplied,
            };

            return(View(vm));
        }
Exemple #17
0
        public async Task <IActionResult> Index(int?brand, int?type, int?page)
        {
            var itemsOnPage = 10;
            var catalog     = await _catalogSvc.GetCatalogItemsAsync(page ?? 0, itemsOnPage, brand, type);

            var vm = new CatalogIndexViewModel
            {
                CatalogItems       = catalog.Data,
                Brands             = await _catalogSvc.GetBrandsAsync(),
                Types              = await _catalogSvc.GetTypesAsync(),
                BrandFilterApplied = brand ?? 0,
                TypesFilterApplied = type ?? 0,
                PaginationInfo     = new PaginationInfo
                {
                    ActualPage   = page ?? 0,
                    ItemsPerPage = itemsOnPage,
                    TotalItems   = catalog.Count,
                    TotalPages   = (int)Math.Ceiling((decimal)catalog.Count / itemsOnPage)
                }
            };

            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            return(View(vm));
        }
        public async Task <CatalogIndexViewModel> GetCatalogItems(
            int pageIndex, int itemsPage,
            string searchText,
            int?brandId, int?typeId,
            bool convertPrice = true,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            _logger.LogInformation("GetCatalogItems called.");

            var pageItemsOffset              = itemsPage * pageIndex;
            var filterSpecification          = new CatalogFilterSpecification(searchText, brandId, typeId);
            var filterPaginatedSpecification =
                new CatalogFilterPaginatedSpecification(
                    pageItemsOffset, itemsPage, searchText, brandId, typeId);

            // the implementation below using ForEach and Count. We need a List.
            var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification);

            // var itemsOnPage = await ListCatalogItems(
            // itemsPage * pageIndex, itemsPage, brandId, typeId);
            var totalItems = await _itemRepository.CountAsync(filterSpecification);

            // var totalItems = await CountCatalogItems(brandId, typeId);

            foreach (var itemOnPage in itemsOnPage)
            {
                itemOnPage.PictureUri = string.IsNullOrEmpty(itemOnPage.PictureUri)
                     ? _configuration.GetValue <string>("ImagePictureUri")
                     : _uriComposer.ComposePicUri(itemOnPage.PictureUri);
            }
            var CatalogItemsTask = Task.WhenAll(itemsOnPage.Select(
                                                    catalogItem => CreateCatalogItemViewModelAsync(catalogItem, convertPrice, cancellationToken)));

            cancellationToken.ThrowIfCancellationRequested();



            var vm = new CatalogIndexViewModel()
            {
                CatalogItems       = await CatalogItemsTask, // catalogItemsList,
                Brands             = await GetBrands(),
                Types              = await GetTypes(),
                BrandFilterApplied = brandId ?? 0,
                TypesFilterApplied = typeId ?? 0,
                PaginationInfo     = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = itemsOnPage.Count,
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }
Exemple #19
0
 public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId)
 {
     CatalogModel = await _catalogViewModelService.GetCatalogItems(
         pageId ?? 0,
         Constants.ITEMS_PER_PAGE,
         catalogModel.BrandFilterApplied,
         catalogModel.TypesFilterApplied,
         catalogModel.SearchText);
 }
        public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId, int?deleteId)
        {
            CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId ?? 0, Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied);

            if (deleteId != null)
            {
                await _catalogViewModelService.DeleteCatalogItem(catalogModel.CatalogItems.Where(x => x.Id == deleteId).SingleOrDefault());
            }
        }
Exemple #21
0
 public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId)
 {
     CatalogModel = await _catalogViewModelService.GetCatalogItems(
         pageId ?? 0, 1000,
         catalogModel.SearchFilter,
         catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied,
         convertPrice : true,
         HttpContext.RequestAborted);
 }
Exemple #22
0
        public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId)
        {
            var culture  = CultureInfo.CurrentCulture.Name;
            var cacheKey = CacheHelpers.GenerateCatalogItemCacheKey(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, culture, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied);

            _cache.Remove(cacheKey);

            CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId.GetValueOrDefault(), Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied);
        }
Exemple #23
0
        public async Task OnGet(CatalogIndexViewModel catalogModel, int?pageId)
        {
            CatalogModel = await _catalogViewModelService.GetCatalogItems(pageId ?? 0, Constants.ITEMS_PER_PAGE, catalogModel.BrandFilterApplied, catalogModel.TypesFilterApplied, HttpContext.RequestAborted);

            CatalogModel.ResultView  = catalogModel.ResultView; // HACK
            CatalogModel.ResultViews = Enum <ResultView> .GetAll()
                                       .Select(resultView => new SelectListItem {
                Value = resultView.ToString(), Text = resultView.ToString()
            });
        }
Exemple #24
0
        public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId, string username, int recommendations)
        {
            _logger.LogInformation("GetCatalogItems called.");

            var filterSpecification = new CatalogFilterSpecification(brandId, typeId);
            var root = _itemRepository.List(filterSpecification);

            var totalItems = root.Count();

            var itemsOnPage = root
                              .Skip(itemsPage * pageIndex)
                              .Take(itemsPage)
                              .ToList();

            itemsOnPage.ForEach(x =>
            {
                x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
            });

            var vm = new CatalogIndexViewModel()
            {
                CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel()
                {
                    Id         = i.Id,
                    Name       = i.Name,
                    PictureUri = i.PictureUri,
                    Price      = i.Price
                }),
                Brands             = await GetBrands(),
                Types              = await GetTypes(),
                BrandFilterApplied = brandId ?? 0,
                TypesFilterApplied = typeId ?? 0,
                PaginationInfo     = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = itemsOnPage.Count,
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
                }
            };

            if (pageIndex == 0 && !String.IsNullOrEmpty(username))
            {
                vm.RecommendedCatalogItems = (await GetRecommendations(username, recommendations)).ToArray();
            }
            else
            {
                vm.RecommendedCatalogItems = Enumerable.Empty <CatalogItemViewModel>();
            }

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }
        public async Task <CatalogIndexViewModel> GetCategoryCatalogItems(int categoryId, int pageIndex, int?itemsPage)
        {
            //TODO: Move to repo

            //Get Category Name
            var category = await _db.Categories.FindAsync(categoryId);

            var filterSpecification = new CatalogFilterSpecification(null, null, categoryId);
            var root = await _itemRepository
                       .ListAsync(filterSpecification);

            var totalItems = root.Count();

            var iPage = itemsPage ?? totalItems;

            var allItems = root.ToList();

            var itemsOnPage = allItems
                              .Skip(iPage * pageIndex)
                              .Take(iPage)
                              .ToList();

            itemsOnPage.ForEach(x =>
            {
                x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
            });

            if (allItems?.Count > 0)
            {
                var vm = new CatalogIndexViewModel()
                {
                    CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel()
                    {
                        CatalogItemId   = i.Id,
                        CatalogItemName = i.Name,
                        PictureUri      = i.PictureUri,
                        Price           = i.Price ?? i.CatalogType.Price,
                        ProductSku      = i.Sku,
                        CatalogTypeName = i.CatalogType?.Name
                    }),
                    PaginationInfo = new PaginationInfoViewModel()
                    {
                        ActualPage   = pageIndex,
                        ItemsPerPage = itemsOnPage.Count,
                        TotalItems   = totalItems,
                        TotalPages   = iPage != 0 ? int.Parse(Math.Ceiling(((decimal)totalItems / iPage)).ToString()) : 0
                    }
                };
                vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
                vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";
                return(vm);
            }
            return(null);
        }
Exemple #26
0
        public async Task OnGet(CatalogIndexViewModel catalogModel)
        {
            //Shop Stuff
            CatalogModel = await _catalogService.GetCatalogItems(0, null, null, null, null, HttpContext.Request.Query["oa"]);

            //DamaStuff
            var config = await _shopService.GetDamaHomePageConfig();

            MetaDescription      = config.MetaDescription;
            Title                = config.Title;
            CatalogModel.Banners = config.Banners;
        }
        public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int?itemsPage, int?illustrationId, int?typeId, int?categoryId)
        {
            _logger.LogInformation("GetCatalogItems called.");

            var filterSpecification = new CatalogFilterSpecification(illustrationId, typeId, categoryId);
            var root = await _itemRepository
                       .ListAsync(filterSpecification);

            var totalItems = root.Count();

            var iPage = itemsPage ?? totalItems;

            var itemsOnPage = root
                              .Skip(iPage * pageIndex)
                              .Take(iPage)
                              .OrderByDescending(x => x.IsFeatured)
                              .ThenBy(x => x.CatalogType.Code.StartsWith("QF") ? 0 : x.CatalogType.Code.StartsWith("SM") ? 1 : 2)
                              .ThenBy(x => x.Name)
                              .ToList();

            itemsOnPage.ForEach(x =>
            {
                x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
            });

            var vm = new CatalogIndexViewModel()
            {
                CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel()
                {
                    CatalogItemId   = i.Id,
                    CatalogItemName = i.Name,
                    PictureUri      = i.PictureUri,
                    Price           = i.Price ?? i.CatalogType.Price,
                    ProductSku      = i.Sku
                }),
                //Illustrations = await GetIllustrations(),
                Types = await GetTypes(),
                IllustrationFilterApplied = illustrationId ?? 0,
                TypesFilterApplied        = typeId ?? 0,
                PaginationInfo            = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = itemsOnPage.Count,
                    TotalItems   = totalItems,
                    TotalPages   = iPage != 0 ? int.Parse(Math.Ceiling(((decimal)totalItems / iPage)).ToString()) : 0
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }
Exemple #28
0
        public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId) // @issue@I02 // @issue@I05
        {
            _logger.LogInformation("GetCatalogItems called.");                                                           // @issue@I02

            var filterSpecification = new CatalogFilterSpecification(brandId, typeId);                                   // @issue@I02
            var root = _itemRepository.List(filterSpecification);                                                        // @issue@I02

            var totalItems = root.Count();                                                                               // @issue@I02

            var itemsOnPage = root                                                                                       // @issue@I02
                              .Skip(itemsPage * pageIndex)
                              .Take(itemsPage)
                              .ToList();

            /*
             * var itemsOnPage = root // @issue@I06
             *  .Skip(itemsPage * pageIndex) // @issue@I06
             *  .Take(itemsPage) // @issue@I06
             *  .ToList(); // @issue@I06
             */
            itemsOnPage.ForEach(x => // @issue@I02
            {
                x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
            });

            var vm = new CatalogIndexViewModel() // @issue@I02
            {
                CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel()
                {
                    Id         = i.Id,
                    Name       = i.Name,
                    PictureUri = i.PictureUri,
                    Price      = i.Price
                }),
                Brands             = await GetBrands(),
                Types              = await GetTypes(),
                BrandFilterApplied = brandId ?? 0,
                TypesFilterApplied = typeId ?? 0,
                PaginationInfo     = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = itemsOnPage.Count,
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : ""; // @issue@I02
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";                                // @issue@I02

            return(vm);                                                                                                           // @issue@I02
        }
Exemple #29
0
        public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId)
        {
            _logger.LogInformation("GetCatalogItems called.");

            var filterSpecification = new CatalogFilterSpecification(brandId, typeId);
            var catalogItems        = await _itemRepository.GetAsync(filterSpecification);

            if (catalogItems != null)
            {
                var totalItems = catalogItems.Count();

                var itemsOnPage = catalogItems
                                  .Skip(itemsPage * pageIndex)
                                  .Take(itemsPage)
                                  .ToList();

                itemsOnPage.ForEach(x =>
                {
                    x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
                });

                var viewModel = new CatalogIndexViewModel()
                {
                    CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel()
                    {
                        Id         = i.Id,
                        Name       = i.Name,
                        PictureUri = i.PictureUri,
                        Price      = i.Price
                    }),
                    Brands             = await GetBrands(),
                    Types              = await GetTypes(),
                    BrandFilterApplied = brandId ?? 0,
                    TypesFilterApplied = typeId ?? 0,
                    PaginationInfo     = new PaginationInfoViewModel()
                    {
                        ActualPage   = pageIndex,
                        ItemsPerPage = itemsOnPage.Count,
                        TotalItems   = totalItems,
                        TotalPages   = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString())
                    }
                };

                viewModel.PaginationInfo.Next     = (viewModel.PaginationInfo.ActualPage == viewModel.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
                viewModel.PaginationInfo.Previous = (viewModel.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

                return(viewModel);
            }

            return(null);
        }
        // public CatalogService(
        //     ILoggerFactory loggerFactory,
        //     IRepository<CatalogItem> itemRepository,
        //     IAsyncRepository<CatalogBrand> brandRepository,
        //     IAsyncRepository<CatalogType> typeRepository,
        //     IUriComposer uriComposer)
        // {
        //     _logger = loggerFactory.CreateLogger<CatalogService>();
        //     _itemRepository = itemRepository;
        //     _brandRepository = brandRepository;
        //     _typeRepository = typeRepository;
        //     _uriComposer = uriComposer;
        // }

        public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId)
        {
            _logger.LogInformation($"Catalog service URL is : {_remoteServiceBaseUrl}");
            var uri = API.Catalog.GetAllCatalogItems(_remoteServiceBaseUrl, pageIndex, itemsPage, brandId, typeId);

            var responseString = await _httpClient.GetStringAsync(uri);

            var catalog = JsonConvert.DeserializeObject <Catalog>(responseString);

            // var filterSpecification = new CatalogFilterSpecification(brandId, typeId);
            // var root = _itemRepository.List(filterSpecification);

            // var totalItems = root.Count();

            // var itemsOnPage = root
            //     .Skip(itemsPage * pageIndex)
            //     .Take(itemsPage)
            //     .ToList();

            // itemsOnPage.ForEach(x =>
            // {
            //     x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri);
            // });

            var vm = new CatalogIndexViewModel()
            {
                CatalogItems = catalog.Data.Select(i => new CatalogItemViewModel()
                {
                    Id         = i.Id,
                    Name       = i.Name,
                    PictureUri = i.PictureUri,
                    Price      = i.Price
                }),
                Brands             = await GetBrands(),
                Types              = await GetTypes(),
                BrandFilterApplied = brandId ?? 0,
                TypesFilterApplied = typeId ?? 0,
                PaginationInfo     = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = catalog.Data.Count,
                    TotalItems   = catalog.Count,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)catalog.Count / itemsPage)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : "";

            return(vm);
        }