public async Task <OpeningDataDto> Handle(FetchOpeningDataQueries request, CancellationToken cancellationToken) { var returnResponses = new OpeningDataDto(); returnResponses.EtalaseList = new List <CategoryProductDto> (); returnResponses.Category = await Context.Categories.ToListAsync(cancellationToken); returnResponses.DealoftheDay = await Context.Products.Where(x => x.IsDealoftheDay == true).ProjectTo <ProductsDto> (Mapper.ConfigurationProvider).ToListAsync(cancellationToken); returnResponses.Articles = await Context.Articles.Take(5).ProjectTo <ArticlesOpeningDto> (Mapper.ConfigurationProvider).ToListAsync(cancellationToken); var listCategories = await Context.Categories.ToListAsync(cancellationToken); foreach (var data in listCategories) { var newEtalase = new CategoryProductDto { CategoryName = data.CategoryName, }; var product = Context.Products.Where(ab => ab.CategoryName == data.CategoryName).Take(10).ProjectTo <ProductsDto> (Mapper.ConfigurationProvider).ToList(); newEtalase.Products = product; if (product.Count > 0) { returnResponses.EtalaseList.Add(new CategoryProductDto { CategoryName = data.CategoryName, Products = product, }); } } return(returnResponses); }
public void TestUpdateProductSetArchived() { var inventoryManager = new InventoryManager(); CategoryProductDto[] allProducts = inventoryManager.GetActiveProducts(null, 0, 10); if (allProducts.Length > 0) { CategoryProductDto productToUpdate = allProducts[0]; productToUpdate.ProductName = "New Name"; productToUpdate.Price = 88.88; productToUpdate.Archived = true; //inventoryManager.UpdateProduct(productToUpdate); ProductDto productDto = inventoryManager.GetProduct(productToUpdate.ProductId); Assert.IsTrue(productDto.Name == productToUpdate.ProductName); Assert.IsTrue(productDto.Price == productToUpdate.Price); Assert.IsTrue(productDto.Archived == productToUpdate.Archived); CategoryProductDto[] activeProducts = inventoryManager.GetActiveProducts(null, 0, 10); IEnumerable <CategoryProductDto> result = from product in activeProducts where product.ProductId == productToUpdate.ProductId select product; CategoryProductDto firstOrDefault = result.FirstOrDefault(); Assert.IsNull(firstOrDefault); } }
private void Child_Fetch(CategoryProductDto item) { this.CategoryXProductId = item.CategoryXProductId; this.Name = item.Name; this.SKU = item.SKU; this.ImageUrl = item.ImageUrl; this.Price = item.Price; }
public ValidationOutput GetAvailableProducts(string reference) { ValidationOutput validationOutput = _configuredProductDTOValidator.DTOReferenceIsValid(reference); if (validationOutput.HasErrors()) { return(validationOutput); } ConfiguredProduct configuredProduct = _configuredProductRepository.GetByReference(reference); if (configuredProduct == null) { validationOutput = new ValidationOutputNotFound(); validationOutput.AddError("Configured Product's reference", "There are no configured products with the given reference"); return(validationOutput); } List <ProductDto> productsDto = (List <ProductDto>)_productService .GetPartProductsAvailableToProduct(configuredProduct.ProductReference).DesiredReturn; List <Product> productsAvailable = new List <Product>(); foreach (var dto in productsDto) { productsAvailable.Add(_mapper.Map <Product>(dto)); } List <ProductDto> productsAvailableFinal = new List <ProductDto>(); foreach (var product in productsAvailable) { if (ProductFitsConfigured(product.Dimensions, configuredProduct.ConfiguredDimension)) { productsAvailableFinal.Add(_mapper.Map <ProductDto>(product)); } } var category_products = new List <CategoryProductDto>(); foreach (var product in productsAvailableFinal) { var categoryName = _categoryRepository.GetByReference(product.CategoryReference).Name; CategoryProductDto cpd = new CategoryProductDto(categoryName); if (!category_products.Contains(cpd)) { cpd.Products.Add(product); category_products.Add(cpd); } else { int index = category_products.IndexOf(cpd); category_products[index].Products.Add(product); } } validationOutput.DesiredReturn = category_products; return(validationOutput); }
public CategoryProductDto[] GetActiveProducts(string letter, int?page, int pageSize) { System.Console.WriteLine("InvetoryManager: {0}", this.GetHashCode()); return(ExecuteFaultHandledOperation( () => { int pageIndex = page ?? 1; if (pageIndex < 0 || pageIndex > pageSize) { return new CategoryProductDto[] { }; } int offset = (pageIndex - 1) * pageSize; string letterToFilter = letter ?? ""; using (ISession session = _sessionFactory.OpenSession()) { CategoryProductDto dtoAlias = null; Product keyAlias = null; Category categoryAlias = null; IList <CategoryProductDto> categoryProducts = session.QueryOver <Product>(() => keyAlias) .JoinAlias(p => p.Categories, () => categoryAlias, JoinType.InnerJoin) .Where(product => product.Archived == false) .WhereRestrictionOn(p => p.Name).IsInsensitiveLike(letterToFilter, MatchMode.Start) .OrderBy(product => product.Name).Asc .Select( Projections.Property(() => keyAlias.Name).WithAlias(() => dtoAlias.ProductName), Projections.Property(() => keyAlias.ProductId).WithAlias(() => dtoAlias.ProductId), Projections.Property(() => keyAlias.Archived).WithAlias(() => dtoAlias.Archived), Projections.Property(() => keyAlias.Price).WithAlias(() => dtoAlias.Price), Projections.Property(() => categoryAlias.Name).WithAlias(() => dtoAlias.CategoryName)) .TransformUsing(Transformers.AliasToBean <CategoryProductDto>()).Skip(offset).Take(pageSize) .List <CategoryProductDto>(); return categoryProducts.ToArray(); } })); }