public async Task <IResult> HandleAsync(ListPagedCatalogItemRequest request) { var response = new ListPagedCatalogItemResponse(request.CorrelationId()); var filterSpec = new CatalogFilterSpecification(request.CatalogBrandId, request.CatalogTypeId); int totalItems = await _itemRepository.CountAsync(filterSpec); var pagedSpec = new CatalogFilterPaginatedSpecification( skip: request.PageIndex.Value * request.PageSize.Value, take: request.PageSize.Value, brandId: request.CatalogBrandId, typeId: request.CatalogTypeId); var items = await _itemRepository.ListAsync(pagedSpec); response.CatalogItems.AddRange(items.Select(_mapper.Map <CatalogItemDto>)); foreach (CatalogItemDto item in response.CatalogItems) { item.PictureUri = _uriComposer.ComposePicUri(item.PictureUri); } if (request.PageSize > 0) { response.PageCount = int.Parse(Math.Ceiling((decimal)totalItems / request.PageSize.Value).ToString()); } else { response.PageCount = totalItems > 0 ? 1 : 0; } return(Results.Ok(response)); }
public override async Task <ActionResult <CreateCatalogItemResponse> > HandleAsync(CreateCatalogItemRequest request) { var response = new CreateCatalogItemResponse(request.CorrelationId()); var newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri); newItem = await _itemRepository.AddAsync(newItem); if (newItem.Id != 0) { var picName = $"{newItem.Id}{Path.GetExtension(request.PictureName)}"; if (await _webFileSystem.SavePicture(picName, request.PictureBase64)) { newItem.UpdatePictureUri(picName); await _itemRepository.UpdateAsync(newItem); } } var dto = new CatalogItemDto { Id = newItem.Id, CatalogBrandId = newItem.CatalogBrandId, CatalogTypeId = newItem.CatalogTypeId, Description = newItem.Description, Name = newItem.Name, PictureUri = _uriComposer.ComposePicUri(newItem.PictureUri), Price = newItem.Price }; response.CatalogItem = dto; return(response); }
public async Task <CustomizeViewModel> GetCustomizeItems(int?categoryid, int?catalogItemId) { var categorySpec = new CategorySpecification(); var cats = await _categoryRepository.ListAsync(categorySpec); List <CatalogType> productTypes = new List <CatalogType>(); if (categoryid.HasValue) { var catalogSpec = new CatalogTypeSpecification(categoryid.Value); productTypes = await _catalogTypeRepository.ListAsync(catalogSpec); } return(new CustomizeViewModel { CategoryId = categoryid, CatalogItemId = catalogItemId, Categories = cats.Select(x => (x.Id, x.Name)).ToList(), ProductTypes = productTypes.Select(x => new CatalogTypeViewModel { Id = x.Id, Code = x.Code, Name = x.Name, PictureUri = _uriComposer.ComposePicUri(x.PictureUri) }).ToList() });
public async Task <IResult> HandleAsync(UpdateCatalogItemRequest request) { var response = new UpdateCatalogItemResponse(request.CorrelationId()); var existingItem = await _itemRepository.GetByIdAsync(request.Id); existingItem.UpdateDetails(request.Name, request.Description, request.Price); existingItem.UpdateBrand(request.CatalogBrandId); existingItem.UpdateType(request.CatalogTypeId); await _itemRepository.UpdateAsync(existingItem); var dto = new CatalogItemDto { Id = existingItem.Id, CatalogBrandId = existingItem.CatalogBrandId, CatalogTypeId = existingItem.CatalogTypeId, Description = existingItem.Description, Name = existingItem.Name, PictureUri = _uriComposer.ComposePicUri(existingItem.PictureUri), Price = existingItem.Price }; response.CatalogItem = dto; return(Results.Ok(response)); }
public override async Task <ActionResult <UpdateCatalogItemResponse> > HandleAsync(UpdateCatalogItemRequest request, CancellationToken cancellationToken) { var response = new UpdateCatalogItemResponse(request.CorrelationId()); var existingItem = await _itemRepository.GetByIdAsync(request.Id); existingItem.UpdateDetails(request.Name, request.Description, request.Price); existingItem.UpdateBrand(request.CatalogBrandId); existingItem.UpdateType(request.CatalogTypeId); if (string.IsNullOrEmpty(request.PictureBase64) && string.IsNullOrEmpty(request.PictureUri)) { existingItem.UpdatePictureUri(string.Empty); } await _itemRepository.UpdateAsync(existingItem); var dto = new CatalogItemDto { Id = existingItem.Id, CatalogBrandId = existingItem.CatalogBrandId, CatalogTypeId = existingItem.CatalogTypeId, Description = existingItem.Description, Name = existingItem.Name, PictureUri = _uriComposer.ComposePicUri(existingItem.PictureUri), Price = existingItem.Price }; response.CatalogItem = dto; return(response); }
private BasketViewModel BasketToViewModel(Basket basket) { var model = new BasketViewModel { BuyerId = basket.BuyerId, Id = basket.Id, Items = basket.Items.Select((item, index) => { var itemModel = new BasketItemViewModel { Id = index, CatalogItemId = item.CatalogItemId, Quantity = item.Quantity, UnitPrice = item.UnitPrice }; var catalogItemTask = _session.LoadAsync <CatalogItem>("Catalog/" + item.CatalogItemId); if (catalogItemTask.Status != TaskStatus.RanToCompletion) { throw new InvalidOperationException("Should never happen: " + catalogItemTask.Status, catalogItemTask.Exception); } var catalogItem = catalogItemTask.Result; itemModel.OldUnitPrice = catalogItem.Price; itemModel.ProductName = catalogItem.Name; itemModel.PictureUrl = _uriComposer.ComposePicUri(catalogItem.PictureUri); return(itemModel); }).ToList() }; return(model); }
public override async Task <ActionResult <CreateCatalogItemResponse> > HandleAsync(CreateCatalogItemRequest request, CancellationToken cancellationToken) { var response = new CreateCatalogItemResponse(request.CorrelationId()); var newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri); newItem = await _itemRepository.AddAsync(newItem, cancellationToken); if (newItem.Id != 0) { //We disabled the upload functionality and added a default/placeholder image to this sample due to a potential security risk // pointed out by the community. More info in this issue: https://github.com/dotnet-architecture/eShopOnWeb/issues/537 // In production, we recommend uploading to a blob storage and deliver the image via CDN after a verification process. newItem.UpdatePictureUri("eCatalog-item-default.png"); await _itemRepository.UpdateAsync(newItem, cancellationToken); } var dto = new CatalogItemDto { Id = newItem.Id, CatalogBrandId = newItem.CatalogBrandId, CatalogTypeId = newItem.CatalogTypeId, Description = newItem.Description, Name = newItem.Name, PictureUri = _uriComposer.ComposePicUri(newItem.PictureUri), Price = newItem.Price }; response.CatalogItem = dto; return(response); }
private async Task <List <BasketItemViewModel> > GetBasketItems(IReadOnlyCollection <BasketItem> basketItems) { var items = new List <BasketItemViewModel>(); foreach (var item in basketItems) { var itemModel = new BasketItemViewModel { Id = item.Id, UnitPrice = item.UnitPrice, Quantity = item.Quantity, CatalogItemId = item.CatalogItemId, }; var catalogItem = await _itemRepository.GetByIdAsync(item.CatalogItemId); if (catalogItem != null) { itemModel.PictureUrl = _uriComposer.ComposePicUri(catalogItem.PictureUri); itemModel.ProductName = catalogItem.Name; itemModel.Description = catalogItem.Description; } items.Add(itemModel); } return(items); }
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 <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); }
public StoreIndexViewModel GetStoreItems(int pageIndex, int itemsPage) { var itemsOnPage = _storeRepository.FilterBy(x => true); _logger.LogInformation("GetStoreItens called."); var filterSpecification = new StoreFilterSpecification(string.Empty); var filterPaginatedSpecification = new StoreFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, string.Empty); var vm = new StoreIndexViewModel() { StoreItems = itemsOnPage.Select(i => new StoreItemViewModel() { Id = i.Id, SecondaryId = i.SecondaryId, Name = i.Name, Description = i.Description, City = i.City, PictureUri = _uriComposer.ComposePicUri(i.PictureUri), Phone = i.Phone, ZipCode = i.ZipCode, Address = i.Address, State = i.State, License = i.License, DeliveryZipCode = i.DeliveryZipCode }), //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 OnGet(int id) { var catalogItem = await _catalogItemViewModelService.GetCatalogItem(id); CatalogModel.Id = catalogItem.Id; CatalogModel.Name = catalogItem.Name; CatalogModel.Price = catalogItem.Price; CatalogModel.PictureUri = _uriComposer.ComposePicUri(catalogItem.PictureUri); }
public async Task <CatalogIndexViewModel> SearchCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId, string keywords) { _logger.LogInformation("GetCatalogItems called."); var results = _searchSvc.SearchCatalog(pageIndex, itemsPage, brandId, typeId, keywords); var itemsOnPage = results.Results.Select(o => o.Document).ToList(); itemsOnPage.ForEach(x => { x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri); }); var vm = new CatalogIndexViewModel() { CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel() { Id = int.Parse(i.Id), Name = i.Name, PictureUri = i.PictureUri, Price = (decimal)i.Price }), Brands = await GetBrands(), Types = await GetTypes(), BrandFilterApplied = brandId ?? 0, TypesFilterApplied = typeId ?? 0, PaginationInfo = new PaginationInfoViewModel() { ActualPage = pageIndex, ItemsPerPage = itemsOnPage.Count, TotalItems = (int)results.Count, TotalPages = int.Parse(Math.Ceiling(((decimal)results.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); }
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 }
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 async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId, string searchText = null) { _logger.LogInformation("GetCatalogItems called."); var filterSpecification = new CatalogFilterSpecification(brandId, typeId, searchText); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId, searchText); // the implementation below using ForEach and Count. We need a List. var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification); var totalItems = await _itemRepository.CountAsync(filterSpecification); foreach (var itemOnPage in itemsOnPage) { itemOnPage.PictureUri = _uriComposer.ComposePicUri(itemOnPage.PictureUri); } var brands = await _brandRepository.ListAllAsync(); var vm = new CatalogIndexViewModel() { CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel() { Id = i.Id, Name = i.Name, PictureUri = i.PictureUri, Price = i.Price, Brand = brands.FirstOrDefault(b => b.Id == i.CatalogBrandId)?.Brand }), 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 <Result <CatalogDetailsViewModel> > Handle(GetCatalogDetailsQuery request, CancellationToken cancellationToken) { var data = await _itemRepository.GetByIdAsync(request.Id.Value); var vm = new CatalogDetailsViewModel() { CatalogDetail = new CatalogItemViewModel() { Id = data.Id, Name = data.Name, PictureUri = _uriComposer.ComposePicUri(data.PictureUri), Price = data.Price } }; return(Result <CatalogDetailsViewModel> .Success(vm)); }
public async Task <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId) { _logger.LogInformation("Get CatalogeItems Called.."); var filterSpecification = new CatalogFilterSpecification(brandId, typeId); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId); var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification); var totalItems = await _itemRepository.CountAsync(filterSpecification); foreach (var itemOnPage in itemsOnPage) { itemOnPage.PictureUri = _uriComposer.ComposePicUri(itemOnPage.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()) } }; 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> GetCatalogItems(CatalogFilterViewModel model) { CatalogFilterSpecification filterSpecification = new CatalogFilterSpecification(model.BrandFilterApplied, model.TypesFilterApplied, model.TextSearch); var root = _itemRepository.List(filterSpecification); var totalItems = root.Count(); var itemsOnPage = root .Skip(model.PaginationInfo.ItemsPerPage * model.PaginationInfo.ActualPage) .Take(model.PaginationInfo.ItemsPerPage) .ToList(); itemsOnPage.ForEach(x => { x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri); }); CatalogIndexViewModel 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() }; vm.CatalogFilter.BrandFilterApplied = model.BrandFilterApplied ?? 0; vm.CatalogFilter.TypesFilterApplied = model.TypesFilterApplied ?? 0; vm.CatalogFilter.PaginationInfo = new PaginationInfoViewModel() { ActualPage = model.PaginationInfo.ActualPage, ItemsPerPage = itemsOnPage.Count, TotalItems = totalItems, TotalPages = int.Parse(Math.Ceiling(((decimal)totalItems / model.PaginationInfo.ItemsPerPage)).ToString()) }; vm.CatalogFilter.PaginationInfo.Next = (vm.CatalogFilter.PaginationInfo.ActualPage == vm.CatalogFilter.PaginationInfo.TotalPages - 1) ? "is-disabled" : ""; vm.CatalogFilter.PaginationInfo.Previous = (vm.CatalogFilter.PaginationInfo.ActualPage == 0) ? "is-disabled" : ""; vm.CatalogFilter.TextSearch = model.TextSearch ?? string.Empty; return(vm); }
public async Task <CatalogIndexViewModel> GetCatalogItems(CatalogPageFiltersViewModel catalogPageFiltersViewModel, bool useCache, bool convertPrice = false, CancellationToken cancellationToken = default(CancellationToken)) { _logger.LogInformation("GetCatalogItems called."); var filterSpecification = new CatalogFilterSpecification(catalogPageFiltersViewModel.BrandFilter, catalogPageFiltersViewModel.TypesFilter, catalogPageFiltersViewModel.SearchTextFilter); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification(catalogPageFiltersViewModel.ItemsPerPage * catalogPageFiltersViewModel.PageId, catalogPageFiltersViewModel.ItemsPerPage, catalogPageFiltersViewModel.SearchTextFilter, catalogPageFiltersViewModel.OrderBy, catalogPageFiltersViewModel.Order, catalogPageFiltersViewModel.BrandFilter, catalogPageFiltersViewModel.TypesFilter); // the implementation below using ForEach and Count. We need a List. var totalItems = await _itemRepository.CountAsync(filterSpecification); var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification); foreach (var itemOnPage in itemsOnPage) { itemOnPage.PictureUri = _uriComposer.ComposePicUri(itemOnPage.PictureUri); } var catalogItemsTask = await Task.WhenAll(itemsOnPage.Select(catalogItem => CreateCatalogItemViewModel(catalogItem, convertPrice, cancellationToken))); // em caso de algures haver um cancelamento o código para aqui e devolve um erro. Escusa de proceguir no processamento cancellationToken.ThrowIfCancellationRequested(); var vm = new CatalogIndexViewModel() { CatalogItems = catalogItemsTask, Brands = await GetBrands(cancellationToken), Types = await GetTypes(cancellationToken), //BrandFilterApplied = catalogPageFiltersViewModel.BrandFilter ?? 0, //TypesFilterApplied = catalogPageFiltersViewModel.TypesFilter ?? 0, PaginationInfo = new PaginationInfoViewModel() { ActualPage = catalogPageFiltersViewModel.PageId, ItemsPerPage = itemsOnPage.Count, TotalItems = totalItems, TotalPages = catalogPageFiltersViewModel.ItemsPerPage == 0 ? 1 : int.Parse(Math.Ceiling(((decimal)totalItems / catalogPageFiltersViewModel.ItemsPerPage)).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 <CatalogIndexViewModel> GetCatalogItems(int pageIndex, int itemsPage, int?brandId, int?typeId, int?materialId) { _logger.LogInformation("GetCatalogItems called."); var filterSpecification = new CatalogFilterSpecification(brandId, typeId, materialId); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId, materialId); // the implementation below using ForEach and Count. We need a List. var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification); var totalItems = await _itemRepository.CountAsync(filterSpecification); var vm = new CatalogIndexViewModel() { CatalogItems = itemsOnPage.Select(i => new CatalogItemViewModel() { Id = i.Id, Name = i.Name, PictureUri = _uriComposer.ComposePicUri(i.PictureUri), Price = i.Price, //Material = i.Material, Material = i.Material }).ToList(), Brands = (await GetBrands()).ToList(), Types = (await GetTypes()).ToList(), Materials = (await GetMaterials()).ToList(), BrandFilterApplied = brandId ?? 0, TypesFilterApplied = typeId ?? 0, MaterialFilterApplied = materialId ?? 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); }
private async Task <List <WishlistItemViewModel> > GetWishlistItems(IReadOnlyCollection <WishlistItem> wishlistItems) { var items = new List <WishlistItemViewModel>(); foreach (var item in wishlistItems) { var itemModel = new WishlistItemViewModel { Id = item.Id, CatalogItemId = item.CatalogItemId }; var catalogItem = await _itemRepository.GetByIdAsync(item.CatalogItemId); itemModel.PictureUrl = _uriComposer.ComposePicUri(catalogItem.PictureUri); itemModel.ProductName = catalogItem.Name; items.Add(itemModel); } return(items); }
// GET: /<controller>/ public async Task <IActionResult> Index() { //var user = _appUserParser.Parse(HttpContext.User); var basket = await GetBasketFromSessionAsync(); var viewModel = new BasketViewModel() { BuyerId = basket.BuyerId, Items = basket.Items.Select(i => new BasketItemViewModel() { Id = i.Id, UnitPrice = i.UnitPrice, PictureUrl = _uriComposer.ComposePicUri(i.Item.PictureUri), ProductId = i.Item.Id.ToString(), ProductName = i.Item.Name, Quantity = i.Quantity }).ToList() }; return(View(viewModel)); }
public async Task <IResult> HandleAsync(CreateCatalogItemRequest request) { var response = new CreateCatalogItemResponse(request.CorrelationId()); var catalogItemNameSpecification = new CatalogItemNameSpecification(request.Name); var existingCataloogItem = await _itemRepository.CountAsync(catalogItemNameSpecification); if (existingCataloogItem > 0) { throw new DuplicateException($"A catalogItem with name {request.Name} already exists"); } var newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri); newItem = await _itemRepository.AddAsync(newItem); if (newItem.Id != 0) { //We disabled the upload functionality and added a default/placeholder image to this sample due to a potential security risk // pointed out by the community. More info in this issue: https://github.com/dotnet-architecture/eShopOnWeb/issues/537 // In production, we recommend uploading to a blob storage and deliver the image via CDN after a verification process. newItem.UpdatePictureUri("eCatalog-item-default.png"); await _itemRepository.UpdateAsync(newItem); } var dto = new CatalogItemDto { Id = newItem.Id, CatalogBrandId = newItem.CatalogBrandId, CatalogTypeId = newItem.CatalogTypeId, Description = newItem.Description, Name = newItem.Name, PictureUri = _uriComposer.ComposePicUri(newItem.PictureUri), Price = newItem.Price }; response.CatalogItem = dto; return(Results.Created($"api/catalog-items/{dto.Id}", response)); }
private async Task <List <BasketItemViewModel> > GetBasketItemsAsync(IReadOnlyCollection <BasketItem> basketItems) { var items = new List <BasketItemViewModel>(); foreach (var i in basketItems) { var itemModel = new BasketItemViewModel() { Id = i.Id, UnitPrice = i.UnitPrice, Quantity = i.Quantity, CatalogItemId = i.CatalogItemId, CustomizeName = i.CustomizeName }; var spec = new CatalogAttrFilterSpecification(i.CatalogItemId); var item = await _itemRepository.GetSingleBySpecAsync(spec); if (item != null) { itemModel.PictureUrl = _uriComposer.ComposePicUri(item.PictureUri); itemModel.ProductName = item.Name; } foreach (var attr in item.CatalogAttributes) { if ((i.CatalogAttribute1.HasValue && i.CatalogAttribute1 == attr.Id) || (i.CatalogAttribute2.HasValue && i.CatalogAttribute2 == attr.Id) || (i.CatalogAttribute3.HasValue && i.CatalogAttribute3 == attr.Id)) { itemModel.Attributes.Add(new AttributeViewModel { Name = attr.Name, Label = EnumHelper <AttributeType> .GetDisplayValue(attr.Type) }); } } items.Add(itemModel); } return(items); }
public override async Task <ActionResult <CreateCatalogItemResponse> > HandleAsync(CreateCatalogItemRequest request) { var response = new CreateCatalogItemResponse(request.CorrelationId()); CatalogItem newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri); newItem = await _itemRepository.AddAsync(newItem); var dto = new CatalogItemDto { Id = newItem.Id, CatalogBrandId = newItem.CatalogBrandId, CatalogTypeId = newItem.CatalogTypeId, Description = newItem.Description, Name = newItem.Name, PictureUri = _uriComposer.ComposePicUri(newItem.PictureUri), Price = newItem.Price }; response.CatalogItem = dto; return(response); }
public async Task OnGet(int orderId) { var order = await _orderRepository.GetByIdWithItemsAsyncnewfix(orderId); OrderDetails = new OrderViewModel() { OrderDate = order.OrderDate, OrderItems = order.OrderItems.Select(oi => new OrderItemViewModel() { Discount = 0, PictureUrl = _uriComposer.ComposePicUri(oi.ItemOrdered.PictureUri), ProductId = oi.ItemOrdered.CatalogItemId, ProductName = oi.ItemOrdered.ProductName, UnitPrice = oi.UnitPrice, Units = oi.Units }).ToList(), OrderNumber = order.Id, ShippingAddress = order.ShipToAddress, Status = "Pending", Total = order.Total() }; }
public override async Task <ActionResult <UpdateCatalogItemResponse> > HandleAsync(UpdateCatalogItemRequest request) { var response = new UpdateCatalogItemResponse(request.CorrelationId()); var existingItem = await _itemRepository.GetByIdAsync(request.Id); existingItem.UpdateDetails(request.Name, request.Description, request.Price); existingItem.UpdateBrand(request.CatalogBrandId); existingItem.UpdateType(request.CatalogTypeId); if (string.IsNullOrEmpty(request.PictureBase64)) { existingItem.UpdatePictureUri(string.Empty); } else { var picName = $"{existingItem.Id}{Path.GetExtension(request.PictureName)}"; if (await _webFileSystem.SavePicture($"{picName}", request.PictureBase64)) { existingItem.UpdatePictureUri(picName); } } await _itemRepository.UpdateAsync(existingItem); var dto = new CatalogItemDto { Id = existingItem.Id, CatalogBrandId = existingItem.CatalogBrandId, CatalogTypeId = existingItem.CatalogTypeId, Description = existingItem.Description, Name = existingItem.Name, PictureUri = _uriComposer.ComposePicUri(existingItem.PictureUri), Price = existingItem.Price }; response.CatalogItem = dto; return(response); }
private async Task <List <CartItemViewModel> > GetCartItems(IReadOnlyCollection <eStore.Domain.Entities.CartAggregate.CartItem> cartItems) { var items = new List <CartItemViewModel>(); foreach (var item in cartItems) { var itemModel = new CartItemViewModel { Id = item.Id, UnitPrice = item.UnitPrice, Quantity = item.Quantity, CatalogItemId = item.CatalogItemId }; var catalogItem = await _itemRepository.GetByIdAsync(item.CatalogItemId); itemModel.PictureUrl = _uriComposer.ComposePicUri(catalogItem.PictureUri); itemModel.ProductName = catalogItem.Name; items.Add(itemModel); } return(items); }
private BasketViewModel CreateViewModelFromBasket(Basket basket) { var viewModel = new BasketViewModel(); viewModel.Id = basket.Id; viewModel.BuyerId = basket.BuyerId; viewModel.Items = basket.Items.Select(i => { var itemModel = new BasketItemViewModel() { Id = i.Id, UnitPrice = i.UnitPrice, Quantity = i.Quantity, CatalogItemId = i.CatalogItemId }; var item = _itemRepository.GetById(i.CatalogItemId); itemModel.PictureUrl = _uriComposer.ComposePicUri(item.PictureUri); itemModel.ProductName = item.Name; return(itemModel); }) .ToList(); return(viewModel); }