Ejemplo n.º 1
0
        public IActionResult EditProduct(long id, string statusMessage = null, string successMessage = null, string failureMessage = null)
        {
            var viewModel = new NewEditProductViewModel()
            {
                Product = _context.Products.Where(x => x.Id == id).
                          Include(c => c.ProductBrand).
                          Include(c => c.ProductColours).
                          Include(c => c.ProductSizes).
                          Include(c => c.ProductImages).
                          Include(c => c.Department).
                          SingleOrDefault(),
                StatusMessage  = statusMessage,
                SuccessMessage = successMessage,
                FailureMessage = failureMessage,
                ReturnUrl      = "~/ManageProducts"
            };

            viewModel.ProductSizes   = ProductSize.GetList(viewModel.Product.ProductSizes);
            viewModel.ProductColours = ProductColour.GetList(viewModel.Product.ProductColours);
            viewModel.ProductImages  = ProductImage.GetList(viewModel.Product.ProductImages);
            viewModel.Brands         = ProductBrand.GetList(_context.ProductBrands.OrderBy(b => b.Brand).OrderBy(x => x.Brand).ToList());
            viewModel.Colours        = Colour.GetList(_context.Colours.OrderBy(c => c.Value).ToList());
            viewModel.Departments    = Department.GetList(_context.Departments.OrderBy(d => d.DepartmentName).ToList());
            viewModel.Sizes          = Size.GetList(_context.Sizes.OrderBy(s => s.Value).ToList());
            viewModel.Brand          = viewModel.Product.ProductBrand.Brand;
            viewModel.Department     = viewModel.Product.Department.DepartmentName;

            if (viewModel.Product.ProductImages.Count == 0)
            {
                viewModel.Product.ProductImages.Add(new ProductImage()
                {
                    Uri = "https://farm5.staticflickr.com/4705/40336899591_bdc86eddb2_o.png"
                });
            }

            return(View(viewModel));
        }