Files

56 lines
2.0 KiB
C#

using System.Collections.ObjectModel;
using System.ComponentModel;
namespace NoteApp.Model
{
public class Note : INotifyPropertyChanged
{
private bool _pinned = false;
private string _title = "";
private string _content = "";
private string _creationDate = "";
private string _lastEditDate = "";
private int _viewed = 0;
public bool Pinned { get => _pinned; set { _pinned = value; OnPropertyChanged(nameof(Pinned)); } }
public string Title { get => _title; set { _title = value; OnPropertyChanged(nameof(Title)); } }
public string Content { get => _content; set { _content = value; OnPropertyChanged(nameof(Content)); } }
public string CreationDate { get => _creationDate; set { _creationDate = value; OnPropertyChanged(nameof(CreationDate)); } }
public string LastEditDate { get => _lastEditDate; set { _lastEditDate = value; OnPropertyChanged(nameof(LastEditDate)); } }
public int Viewed { get => _viewed; set { _viewed = value; OnPropertyChanged(nameof(Viewed)); } }
public ObservableCollection<string> Tags { get; set; } = [];
public Note(){
CreationDate = DateTime.Now.ToString("dd/MM/yyyy, HH:mm");
LastEditDate = DateTime.Now.ToString("dd/MM/yyyy, HH:mm");
}
public void Update(string title, string content){
Title = title;
Content = content;
LastEditDate = DateTime.Now.ToString("dd/MM/yyyy, HH:mm");
}
public void TogglePin(){
Pinned = !Pinned;
}
public void View(){
Viewed++;
}
public void AddTag(string tag){
Tags.Add(tag);
}
public void RemoveTag(string tag){
Tags.Remove(tag);
}
public event PropertyChangedEventHandler? PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}