private async Task RemoveImagesAsync(UpdateItemDto dto, string imagesFolder, List <Image> itemImages) { foreach (var img in itemImages) { var filePath = Path.Combine(imagesFolder, img.Name); var test = dto.Images.Where(x => x.FileName == img.Name).SingleOrDefault(); if (File.Exists(filePath) && test is null) { File.Delete(filePath); this.imagesRepository.Delete(this.imagesRepository.All().SingleOrDefault(x => x.Name == img.Name)); await this.imagesRepository.SaveChangesAsync(); } } }