Esempio n. 1
0
        public ActionResult Delete(int id, int?page)
        {
            var website = WebsiteService.GetById(id);

            if (website != null)
            {
                WebsiteService.Delete(website);
            }

            return(RedirectToAction("Index", new { page }));
        }
        public ActionResult ImportPackage(DeploymentViewModel.ImportViewModel importForm)
        {
            var           model         = _deploymentViewModelBuilder.Build(ShowExport());
            StructureInfo structureInfo = null;
            PackageInfo   packageInfo   = null;

            if (!ValidateImportForm(importForm))
            {
                return(View(nameof(Index), model));
            }
            _package.Type = importForm.PackageName;

            try
            {
                structureInfo = _package.GetStructureInfo();
                structureInfo.CreateExampleProducts = importForm.CreateExampleProducts;

                packageInfo      = _package.CreatePackageInfo(structureInfo, importForm.Name, importForm.DomainName);
                model.ShowImport = true;
                model.CanImport  = true;

                Solution.Instance.SearchService.IndexJobConsumer.Stop();

                _packageService.Import(structureInfo, packageInfo);
                _structureInfoService.UpdatePropertyReferences(structureInfo, packageInfo);
                model.ImportMessage = "accelerator.deployment.import.success".AsAngularResourceString();
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Package installation error.");
                model.ImportMessage = "accelerator.deployment.error".AsAngularResourceString();
                try
                {
                    foreach (var variant in structureInfo.ProductCatalog.Variants)
                    {
                        var newVariant = _variantService.Get(structureInfo.Id(variant.SystemId));
                        if (newVariant != null)
                        {
                            _variantService.Delete(newVariant);
                        }
                    }

                    foreach (var product in structureInfo.ProductCatalog.BaseProducts)
                    {
                        var newProduct = _baseProductService.Get(structureInfo.Id(product.SystemId));
                        if (newProduct != null)
                        {
                            _baseProductService.Delete(newProduct);
                        }
                    }

                    foreach (var category in structureInfo.ProductCatalog.Categories)
                    {
                        var newCategory = _categoryService.Get(structureInfo.Id(category.SystemId));
                        if (newCategory != null)
                        {
                            _categoryService.Delete(newCategory);
                        }
                    }

                    _channelService.Delete(packageInfo.Channel);
                    _marketService.Delete(packageInfo.Market);
                    _websiteService.Delete(packageInfo.Website);
                    _assortmentService.Delete(packageInfo.Assortment);
                    _folderService.Delete(packageInfo.Folder);
                    _inventoryService.Delete(packageInfo.Inventory);
                    _priceListService.Delete(packageInfo.PriceList);
                }
                catch (Exception ee)
                {
                    _logger.LogError(ee, "Package installation cleanup error.");
                }
            }
            finally
            {
                Solution.Instance.SearchService.IndexJobConsumer.Start();
            }

            return(View(nameof(Index), model));
        }