コード例 #1
0
        // GET: /<controller>/
        public IActionResult Product(long id, string statusMessage = null, string successMessage = null,
                                     string failureMessage         = null, string returnUrl = null)
        {
            var viewModel = new ProductViewModel()
            {
                Product = _context.Products.Where(x => x.Id == id).
                          Include(c => c.ProductBrand).
                          Include(c => c.ProductColours).
                          Include(c => c.ProductSizes).
                          Include(c => c.ProductImages).
                          SingleOrDefault(),
                StatusMessage  = statusMessage,
                SuccessMessage = successMessage,
                FailureMessage = failureMessage
            };

            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                viewModel.ReturnUrl = "~/Products";
            }
            else
            {
                viewModel.ReturnUrl = returnUrl.Replace(";amp;", "&");
            }

            viewModel.Sizes   = ProductSize.GetList(viewModel.Product.ProductSizes);
            viewModel.Colours = ProductColour.GetList(viewModel.Product.ProductColours);

            viewModel.Product.Description = viewModel.Product.Description.Replace(System.Environment.NewLine, "<br />");

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

            // get related products
            viewModel.RelatedProducts = _context.Products.
                                        Where(x => x.ProductBrandId == viewModel.Product.ProductBrandId).
                                        Include(p => p.Department).
                                        Include(p => p.ProductBrand).
                                        Include(p => p.ProductSizes).
                                        Include(p => p.ProductImages).
                                        Include(p => p.ProductColours).
                                        Where(x => x.Stock > 0).
                                        ToList();

            return(View(viewModel));
            //return ControllerHelper.RedirectToLocal(this, "/Home/ComingSoon");
        }
コード例 #2
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));
        }