Namespaceanpassungen
This commit is contained in:
@@ -4,53 +4,52 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
internal class Note {
|
||||
public string Filename { get; set; }
|
||||
public string Text { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
namespace Jugenddienst_Stunden.Models;
|
||||
internal class Note {
|
||||
public string Filename { get; set; }
|
||||
public string Text { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public void Save() =>
|
||||
public void Save() =>
|
||||
File.WriteAllText(System.IO.Path.Combine(FileSystem.AppDataDirectory, Filename), Text);
|
||||
|
||||
public void Delete() =>
|
||||
File.Delete(System.IO.Path.Combine(FileSystem.AppDataDirectory, Filename));
|
||||
public void Delete() =>
|
||||
File.Delete(System.IO.Path.Combine(FileSystem.AppDataDirectory, Filename));
|
||||
|
||||
public static Note Load(string filename) {
|
||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||
public static Note Load(string filename) {
|
||||
filename = System.IO.Path.Combine(FileSystem.AppDataDirectory, filename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
||||
if (!File.Exists(filename))
|
||||
throw new FileNotFoundException("Unable to find file on local storage.", filename);
|
||||
|
||||
return
|
||||
new() {
|
||||
Filename = Path.GetFileName(filename),
|
||||
Text = File.ReadAllText(filename),
|
||||
Date = File.GetLastWriteTime(filename)
|
||||
};
|
||||
}
|
||||
return
|
||||
new() {
|
||||
Filename = Path.GetFileName(filename),
|
||||
Text = File.ReadAllText(filename),
|
||||
Date = File.GetLastWriteTime(filename)
|
||||
};
|
||||
}
|
||||
|
||||
public static IEnumerable<Note> LoadAll() {
|
||||
// Get the folder where the notes are stored.
|
||||
string appDataPath = FileSystem.AppDataDirectory;
|
||||
public static IEnumerable<Note> LoadAll() {
|
||||
// Get the folder where the notes are stored.
|
||||
string appDataPath = FileSystem.AppDataDirectory;
|
||||
|
||||
// Use Linq extensions to load the *.notes.txt files.
|
||||
return Directory
|
||||
// Use Linq extensions to load the *.notes.txt files.
|
||||
return Directory
|
||||
|
||||
// Select the file names from the directory
|
||||
.EnumerateFiles(appDataPath, "*.notes.txt")
|
||||
// Select the file names from the directory
|
||||
.EnumerateFiles(appDataPath, "*.notes.txt")
|
||||
|
||||
// Each file name is used to load a note
|
||||
.Select(filename => Note.Load(Path.GetFileName(filename)))
|
||||
// Each file name is used to load a note
|
||||
.Select(filename => Note.Load(Path.GetFileName(filename)))
|
||||
|
||||
// With the final collection of notes, order them by date
|
||||
.OrderByDescending(note => note.Date);
|
||||
}
|
||||
// With the final collection of notes, order them by date
|
||||
.OrderByDescending(note => note.Date);
|
||||
}
|
||||
|
||||
public Note() {
|
||||
Filename = $"{Path.GetRandomFileName()}.notes.txt";
|
||||
Date = DateTime.Now;
|
||||
Text = "";
|
||||
}
|
||||
public Note() {
|
||||
Filename = $"{Path.GetRandomFileName()}.notes.txt";
|
||||
Date = DateTime.Now;
|
||||
Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user