Esempio n. 1
0
        public IActionResult GetPhotos(string path, int skip)
        {
            string FullPath = _pathHelper.GetFullPathToFile(path);
            List <EncodedPhoto> encodedPhotos = new List <EncodedPhoto>();
            List <string>       Files         = _fsService.GetAllFilesInFolder(FullPath);
            List <FileInfo>     fileInfos     = new List <FileInfo>();

            for (int i = 0; i < Files.Count; i++)
            {
                fileInfos.Add(new FileInfo(Files[i]));
            }
            fileInfos = fileInfos.OrderByDescending(f => f.CreationTime).Skip(skip * 10).Take(10).ToList();

            using (FamilyArchiveContext db = new FamilyArchiveContext())
            {
                for (int i = 0; i < fileInfos.Count; i++)
                {
                    EncodedPhoto encodedPhoto = _dbService.GetPhotoFromDb(path, fileInfos[i].Name, db);
                    if (encodedPhoto == null)
                    {
                        encodedPhoto = _fsService.GetEncodedPhotoFromFileSystem(Path.Combine(FullPath, fileInfos[i].Name));
                    }

                    encodedPhotos.Add(encodedPhoto);
                }
            }

            return(Json(encodedPhotos));
        }