コード例 #1
0
        public async Task <List <RoverPhotosViewModel> > GetRoverPhotosByDate(CancellationToken ct, IPhotosRepository repository, DateTime date, IWebHostEnvironment env, IConfiguration config)
        {
            List <RoverPhotosViewModel> roverPhotosViewModels = new List <RoverPhotosViewModel>();

            var stringDate = date.ToString("yyyy-MM-dd");

            //download photos if not exits
            await repository.GetRoverPhotosByDate(ct, stringDate, env, config);

            //get photos from the folder
            var files = Directory.GetFiles(env.WebRootPath + "/Images/" + stringDate);

            foreach (var photo in files)
            {
                RoverPhotosViewModel rvm = new RoverPhotosViewModel();
                var fullFileName         = Path.GetFileName(photo);
                var fileName             = fullFileName.Split('.')[0];
                rvm.PhotoId   = Convert.ToInt32(fileName);
                rvm.ImageSrc  = config["ProdURL:URL"].ToString() + "Images/" + stringDate + "/" + fullFileName;
                rvm.EarthDate = Convert.ToDateTime(stringDate);
                roverPhotosViewModels.Add(rvm);
            }
            return(roverPhotosViewModels);
        }