public Photo FindFT(string filePath) { // TODO: ファイルIO講座で実装 // 保存したcsvからidを検索 //string ext = Path.GetExtension(filePath).ToLower(); //return photoFileExtensions.Any(x => x == ext); using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8)) { while (sr.Peek() > -1) { string line = sr.ReadLine(); string[] photoData = line.Split(','); if (photoData[1] == filePath) { // あったよ Domain.Model.File file = new Domain.Model.File(photoData[1]); //Domain.Model.Album album = new Domain.Model.Album(photoData[3]); Domain.Model.Album album = albumRepository.FindBy(photoData[3]); return(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album)); } } return(null); } }
public List <Photo> FindFav(Photo entity) { // TODO: ファイルIO講座で実装 // 保存したcsvからidを検索 using (StreamReader sr = new StreamReader(CsvFilePath)) { List <Photo> favlist = new List <Photo>(); while (sr.Peek() > -1) { string line = sr.ReadLine(); string[] photoData = line.Split(','); if (photoData[2] == "true") { // あったよ Domain.Model.File file = new Domain.Model.File(photoData[1]); Domain.Model.Album album = albumRepository.FindBy(photoData[3]); //favlistに該当する写真の情報を出力する favlist.Add(entity); return(favlist); } } return(null); } }
public Photo FindBy(string id) { // TODO: ファイルIO講座で実装 // 保存したcsvからidを検索 using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8)) { while (sr.Peek() > -1) { string line = sr.ReadLine(); string[] photoData = line.Split(','); if (photoData[0] == id) { // あったよ Domain.Model.File file = new Domain.Model.File(photoData[1]); //Domain.Model.Album album = new Domain.Model.Album(photoData[3]); Domain.Model.Album album = albumRepository.FindBy(photoData[3]); return(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album)); } } // なかったよ return(null); //throw new NotImplementedException(); } }
/// <summary> /// Csvファイル内のすべてのフォトの取得 /// (引数にフォトを渡した場合はそのフォトと同じIDのフォトをリストから除く) /// </summary> /// <returns></returns> IQueryable <Photo> FindAll(Photo photo = null) { List <Photo> photos = new List <Photo>(); if (System.IO.File.Exists(CsvFilePath)) { using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8)) { while (sr.Peek() > -1) { string line = sr.ReadLine(); string[] photoData = line.Split(','); Domain.Model.File file = new Domain.Model.File(photoData[1]); Domain.Model.Album album = albumRepository.FindBy(photoData[3]); if (photo == null || photo.Id != photoData[0]) { photos.Add(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album)); } } } return(photos.AsQueryable()); } else { // なかったよ return(null); } }
public Photo Find(Func <IQueryable <Photo>, Photo> query) { // TODO: イベント・デリゲート講座で実装予定 List <Photo> photos = new List <Photo>(); if (System.IO.File.Exists(CsvFilePath)) { using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8)) { while (sr.Peek() > -1) { string line = sr.ReadLine(); string[] photoData = line.Split(','); Domain.Model.File file = new Domain.Model.File(photoData[1]); Domain.Model.Album album = albumRepository.FindBy(photoData[3]); photos.Add(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album)); } } return(query(photos.AsQueryable <Photo>())); } else { // なかったよ return(null); } }
public IEnumerable <Photo> FindByIsFavorite() { List <Photo> photo_list = new List <Photo>(); if (System.IO.File.Exists(CsvFilePath)) { using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8)) { while (sr.Peek() > -1) { string line = sr.ReadLine(); string[] photoData = line.Split(','); bool isFavorite = Convert.ToBoolean(photoData[2]); if (isFavorite == true) { // あったよ Domain.Model.File file = new Domain.Model.File(photoData[1]); Domain.Model.Album album = albumRepository.FindBy(photoData[3]); photo_list.Add(new Photo(photoData[0], file, isFavorite, photoData[3], album)); } } } } // なかったよ return(photo_list); }