public IActionResult DeleteImages(List <string> Ids) { try { var imageToDelete = new List <Guid>(); foreach (var id in Ids) { var image = _imageManagerService.GetImageById(Guid.Parse(id)); if (image != null) { // delete image from local disk var dir = Path.Combine(_hostingEnvironment.WebRootPath, "images/app"); var imagePath = Path.Combine(dir, image.FileName); if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } imageToDelete.Add(image.Id); } } // delete image from database _imageManagerService.DeleteImages(imageToDelete); return(new NoContentResult()); } catch (Exception) { throw; } }
// GET: /Manufacturer/List public IActionResult List() { var manufacturerEntities = _manufacturerService.GetAllManufacturers(); var manufacturerList = new List <ManufacturerListModel>(); foreach (var manufacturer in manufacturerEntities) { var manufacturerModel = _mapper.Map <Manufacturer, ManufacturerListModel>(manufacturer); // get the image if (manufacturer.MainImage != null) { var image = _imageManagerService.GetImageById(Guid.Parse(manufacturer.MainImage)); if (image != null) { manufacturerModel.MainImageFileName = image.FileName; } } manufacturerList.Add(manufacturerModel); } return(View(manufacturerList)); }