public async Task <IActionResult> GetExtendedProduct() { var listProduct = await productService.GetAll(); var listProductColor = await productColorService.GetAll(); var listProductSize = await productSizeService.GetAll(); Guid statusIdKhoa = new Guid("1C55F3C2-D7ED-4B82-8F18-480062D092A1"); List <ExtendedProductVM> listExtendedProduct = new List <ExtendedProductVM>(); foreach (var product in listProduct.Where(m => m.StatusId != statusIdKhoa)) { IList <ProductColorVM> listProductColorVM = listProductColor .Where(m => m.ProductId == product.ProductId) .Select(m => new ProductColorVM() { Color = new ColorVM() { ColorId = m.ColorId, ColorValue = m.Color.ColorValue, Name = m.Color.Name }, ImageUrl = m.ImageUrl, ListProductSize = listProductSize .Where(n => n.ColorId == m.ColorId && n.ProductId == m.ProductId) .Select(n => new ProductSizeVM() { InventoryQuantity = n.InventoryQuantity, Size = new SizeVM() { SizeId = n.SizeId, Name = n.Size.Name } }).ToList() }).ToList(); ExtendedProductVM extendedProduct = new ExtendedProductVM { ProductId = product.ProductId, Code = product.Code, Name = product.Name, TypeProduct = new TypeProductVM() { Name = product.TypeProduct.Name, TypeProductId = product.TypeProductId }, Price = product.Price, Detail = product.Detail, Discount = product.Discount, CreatedDate = product.CreatedDate, Brand = new BrandVM() { Name = product.Brand.Name, BrandId = product.Brand.BrandId }, Status = new StatusVM() { Name = product.Status.Name, StatusId = product.Status.StatusId }, ListProductColor = listProductColorVM }; listExtendedProduct.Add(extendedProduct); } listExtendedProduct = listExtendedProduct.OrderByDescending(m => m.CreatedDate).ToList(); return(Ok(listExtendedProduct)); }
[Route("getProductColors")] //api/customer/product/getProducts public async Task <IActionResult> GetColors() { return(Ok(await productColorService.GetAll())); }