private static List <Photo> GetPhotos(Categories category, int annoucementId) { var imageFolder = Path.Combine("Data/SeedData/seedimages", category.ToString()); var images = Directory.EnumerateFiles(imageFolder).Select(x => Path.GetFileName(x)).ToList(); var rand = new Random(); var randSequence = Enumerable.Range(0, images.Count()).OrderBy(x => Guid.NewGuid()).ToList(); var listOfImages = new List <Image>(); foreach (var i in Enumerable.Range(1, 6)) { var fileNumber = randSequence[i]; var fileName = Path.Combine(imageFolder, images[fileNumber]); listOfImages.Add(Image.FromFile(fileName)); } string annoucementIdImageFolder = Path.Combine(RootPath, "images", $"{annoucementId}"); var imgUrls = ImageFileProcessor.UploadFilesOnServerAndGetListOfFileNames(listOfImages, annoucementIdImageFolder); return(imgUrls.Select(x => new Photo() { PhotoUrl = x }).ToList()); }
private List <string> UploadImages(List <IFormFile> formImages, string folderName) { var images = ImageFileProcessor.ConvertListIFormFileToListImage(formImages); List <string> listOfImgUrls = ImageFileProcessor.UploadFilesOnServerAndGetListOfFileNames(images, folderName); return(listOfImgUrls); }