public IActionResult OnPost(int productId)
        {
            picturesPath    = serverFilesManager.GetEnvFullPath(configuration.GetValue <string>("UploadPaths:Pictures"));
            attachmentsPath = serverFilesManager.GetEnvFullPath(configuration.GetValue <string>("UploadPaths:Attachments"));

            Product = productsData.GetById(productId);
            var childs = productsData.GetChilds(productId);

            if (childs.Count() > 0)
            {
                foreach (var child in childs)
                {
                    child.ParentId = null;
                    child.Parent   = null;
                }
            }

            var picturesIdsToDelete    = Product.Pictures.Select(p => p.Id).ToList();
            var attachmentsIdsToDelete = Product.Attachments.Select(a => a.Id).ToList();

            var deletedPictures    = productsData.RemovePictures(picturesIdsToDelete).Select(p => p.Name);
            var deletedAttachments = productsData.RemoveAttachments(attachmentsIdsToDelete).Select(p => p.Name);

            serverFilesManager.DeleteFilesFromServer(deletedPictures, picturesPath);
            serverFilesManager.DeleteFilesFromServer(deletedAttachments, attachmentsPath);

            productsData.Remove(productId);
            productsData.Commit();

            return(RedirectToPage("./List"));
        }
Exemplo n.º 2
0
        public IActionResult OnGet(int productId)
        {
            PicturesPath    = configuration.GetValue <string>("UploadPaths:Pictures");
            AttachmentsPath = configuration.GetValue <string>("UploadPaths:Attachments");

            Product = productsData.GetById(productId);

            if (Product == null)
            {
                return(RedirectToPage("NotFound"));
            }
            else
            {
                Pictures      = productsData.GetProductPicturesURLs(productId, PicturesPath);
                Attachments   = productsData.GetProductAttachmentsURLs(productId, AttachmentsPath);
                ChildProducts = productsData.GetChilds(productId);

                return(Page());
            }
        }