public async Task<JsonResult> GetProductsAsync() { var model = new WizardProductsViewModel(); var colorTask = GetColorViewModelsAsync(); var productTask = GetProductViewModelsAsync(); var groupTask = GetProductGroupViewModelsAsync(); var imageTask = GetProductImageViewModelsAsync(); await Task.WhenAll(colorTask, productTask, groupTask, imageTask); model.product_colors = colorTask.Result; model.products = productTask.Result; model.product_groups = groupTask.Result; model.product_images = imageTask.Result; return Json(model, JsonRequestBehavior.AllowGet); }
public JsonResult GetProducts() { var model = new WizardProductsViewModel(); var products = _productService.GetAllProducts().Where(pr => pr.ProductHeadlineRecord.ProdHeadCulture == cultureUsed).ToList(); var groups = _productService.GetAllProductGroups().Where(gr => gr.ProdGroupCulture == cultureUsed).ToList(); var colors = _productService.GetAllColorsAvailable().Where(col => col.ProdColorCulture == cultureUsed); model.product_colors = colors.Select(c => new ColorViewModel { id = c.Id, name = c.Name, value = c.Value, importance = c.Importance }).ToArray(); model.product_images = products.Select(p => new ProductImageViewModel { id = p.ProductImageRecord.Id, product_id = p.Id, width = p.ProductImageRecord.Width, height = p.ProductImageRecord.Height, ppi = p.ProductImageRecord.Ppi, printable_back_height = p.ProductImageRecord.PrintableBackHeight, printable_back_left = p.ProductImageRecord.PrintableBackLeft, printable_back_top = p.ProductImageRecord.PrintableBackTop, printable_back_width = p.ProductImageRecord.PrintableBackWidth, printable_front_height = p.ProductImageRecord.PrintableFrontHeight, printable_front_left = p.ProductImageRecord.PrintableFrontLeft, printable_front_top = p.ProductImageRecord.PrintableFrontTop, printable_front_width = p.ProductImageRecord.PrintableFrontWidth, chest_line_back = p.ProductImageRecord.ChestLineBack, chest_line_front = p.ProductImageRecord.ChestLineFront, gender = p.ProductImageRecord.Gender }).ToArray(); model.product_groups = groups.Select(g => new ProductGroupViewModel { id = g.Id, name = g.Name, singular = g.Name.ToLower(), products = g.Products.Where(c => c.ProductRecord.WhenDeleted == null).Select(pr => pr.ProductRecord.Id).ToArray() }).ToArray(); model.products = products.Select(p => new ProductViewModel { id = p.Id, name = p.Name, headline = p.ProductHeadlineRecord.Name, colors_available = p.ColorsAvailable.Select(c => c.ProductColorRecord.Id).ToArray(), list_of_sizes = p.SizesAvailable.Count > 0 ? p.SizesAvailable .OrderBy(s => s.ProductSizeRecord.SizeCodeRecord.Id) .First() .ProductSizeRecord .SizeCodeRecord.Name + " - " + p.SizesAvailable .OrderBy(s => s.ProductSizeRecord.SizeCodeRecord.Id) .Last() .ProductSizeRecord.SizeCodeRecord.Name : "", prices = p.ColorsAvailable.Select(c => new ProductPriceViewModel { color_id = c.ProductColorRecord.Id, price = p.BaseCost }).ToArray() }).ToArray(); return Json(model, JsonRequestBehavior.AllowGet); }