Example #1
0
        public ActionResult ImportFromXlsx()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                return(AccessDeniedView());
            }

            //a vendor cannot import categories
            if (_workContext.CurrentVendor != null)
            {
                return(AccessDeniedView());
            }

            try
            {
                var file = Request.Files["importexcelfile"];
                if (file != null && file.ContentLength > 0)
                {
                    _importManager.ImportCategoryFromXlsx(file.InputStream);
                }
                else
                {
                    ErrorNotification(_localizationService.GetResource("Admin.Common.UploadFile"));
                    return(RedirectToAction("List"));
                }
                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Category.Imported"));
                return(RedirectToAction("List"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("List"));
            }
        }
        public IActionResult ImportFromXlsx(IFormFile importexcelfile)
        {
            //a vendor cannot import categories
            if (_workContext.CurrentVendor != null)
            {
                return(AccessDeniedView());
            }

            try
            {
                if (importexcelfile != null && importexcelfile.Length > 0)
                {
                    _importManager.ImportCategoryFromXlsx(importexcelfile.OpenReadStream());
                }
                else
                {
                    ErrorNotification(_localizationService.GetResource("Admin.Common.UploadFile"));
                    return(RedirectToAction("List"));
                }
                SuccessNotification(_localizationService.GetResource("Admin.Catalog.Category.Imported"));
                return(RedirectToAction("List"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("List"));
            }
        }
Example #3
0
        public async Task <IActionResult> ImportFromXlsx(IFormFile importexcelfile)
        {
            //a vendor and staff cannot import categories
            if (_workContext.CurrentVendor != null || await _groupService.IsStaff(_workContext.CurrentCustomer))
            {
                return(AccessDeniedView());
            }

            try
            {
                if (importexcelfile != null && importexcelfile.Length > 0)
                {
                    await _importManager.ImportCategoryFromXlsx(importexcelfile.OpenReadStream());
                }
                else
                {
                    Error(_translationService.GetResource("Admin.Common.UploadFile"));
                    return(RedirectToAction("List"));
                }
                Success(_translationService.GetResource("Admin.Catalog.Category.Imported"));
                return(RedirectToAction("List"));
            }
            catch (Exception exc)
            {
                Error(exc);
                return(RedirectToAction("List"));
            }
        }