public async Task <IActionResult> Delete()
        {
            if (ModelState.IsValid)
            {
                await _catalogItemViewModelService.DeleteCatalogItem(CatalogModel);
            }

            return(RedirectToPage("/Admin/Index"));
        }
示例#2
0
        public async Task <IActionResult> OnPostDeleteAsync(int id, string imageUri)
        {
            _logger.LogInformation($"Delete CatalogItem with Id {id}");
            await _catalogItemViewModelService.DeleteCatalogItem(id);

            // delete the image file
            try{
                var pathImagesString = _configuration.GetValue <string>("UploadPaths:Images");
                var path             = $"{_webHostEnvironment.WebRootPath}{imageUri}".Replace("/", "\\");
                System.IO.File.Delete(path);
            }
            catch (System.IO.IOException ioe) {
                _logger.LogWarning($"CatalogItem Image file has not been deleted, with id {id}. Error: {ioe.Message}");
                throw new System.IO.IOException(ioe.Message, ioe.InnerException);
            }
            return(RedirectToPage());
        }