Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public JsonResult GetProducts()
        {
            var model = new WizardProductsViewModel();

            var currencyFrom = _currencyRepository.Table
                               .First(c => c.CurrencyCulture == _cultureUsed);

            var products = _productService.GetAllProducts()
                           .Where(pr => pr.ProductHeadlineRecord.ProdHeadCulture == _cultureUsed)
                           .ToList();

            var groups = _productService.GetAllProductGroups().OrderBy(aa => aa.xOrder)
                         .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).OrderBy(aa => aa.ProductRecord.xOrder)
                           .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,
                    //change when currency from back-end changed to USD
                    price = p.BaseCost //_priceConversionService.ConvertPrice(p.BaseCost, "MYR", _currencyRepository.Table.FirstOrDefault(aa => aa.Code == "USD")).Value
                }).ToArray()
            }).ToArray();

            return(Json(model, JsonRequestBehavior.AllowGet));
        }