Exemple #1
0
        public virtual IActionResult List()
        {
            //prepare model
            var model = _productModelFactory.PrepareProductModel(new ProductModel(), null);

            return(View(model));
        }
Exemple #2
0
        public virtual async Task <ActionResult> Index(string slug)
        {
            var currentUser = await UserManager.FindByIdAsync(HttpContext.User.Identity.GetUserId());

            var isAdmin = HttpContext.User.IsInRole("Admin");

            var product = await _productService.FindBySlugAsync(slug);

            if (product == null && int.TryParse(slug, out int productId))
            {
                product = await _productService.FindByIdAsync(productId);
            }

            if (product == null || (!product.Published && !isAdmin))
            {
                return(View("PageNotFound"));
            }

            //Increase the number of product views
            await _productService.IncreaseNumberOfViewsAsync(product);

            //Current product editor page URL (for Admin User)
            ViewBag.AdminEditCurrentPage =
                $"PopupWindows('{Url.Action("Editor", "ManageProducts", new {area = "Admin"})}', 'ProductEditor', 1200, 700, {{ id: {product.Id} }}, 'get')";

            return(View(_productModelFactory.PrepareProductModel(product, currentUser, Url)));
        }
        public virtual IActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedView());
            }

            //validate maximum number of products per vendor
            if (_vendorSettings.MaximumProductNumber > 0 && _workContext.CurrentVendor != null &&
                _productService.GetNumberOfProductsByVendorId(_workContext.CurrentVendor.Id) >= _vendorSettings.MaximumProductNumber)
            {
                ErrorNotification(string.Format(_localizationService.GetResource("Admin.Catalog.Products.ExceededMaximumNumber"),
                                                _vendorSettings.MaximumProductNumber));
                return(RedirectToAction("List"));
            }

            //prepare model
            var model = _productModelFactory.PrepareProductModel(new ProductModel(), null);

            return(View(model));
        }
Exemple #4
0
        public virtual async Task <ActionResult> PurchaseProductWizard(int productId, Guid?invoiceId)
        {
            var product = await _productService.FindByIdAsync(productId);

            var currentUser = await UserManager.FindByIdAsync(HttpContext.User.Identity.GetUserId());

            var isAdmin = User.IsInRole("Admin");

            if (product == null || (!product.Published && !isAdmin))
            {
                return(View("Partials/_PageNotFound")); // product id is invalid or not published
            }
            if (invoiceId != null)
            {
                ViewBag.InvoiceId = invoiceId.ToString();
            }
            return(View(_productModelFactory.PrepareProductModel(product, currentUser, Url)));
        }
Exemple #5
0
        public IActionResult EditProduct(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var product = _productService.GetByIdWithCategories((int)id);

            if (product == null)
            {
                return(NotFound());
            }

            var productModel = _productModelFactory.PrepareProductModel(product);

            ViewBag.Categories = _categoryService.GetAllCategories();

            return(View(productModel));
        }