├── Enums ├── ThemeType.cs └── Enums.csproj ├── Notebook ├── ApplicationConfig.json ├── Content │ ├── Images │ │ ├── Logo │ │ │ └── Logo.ico │ │ └── Controls │ │ │ ├── MenuControl │ │ │ ├── Default.png │ │ │ └── MouseEnter.png │ │ │ └── WindowControls │ │ │ ├── Close │ │ │ ├── Default.png │ │ │ └── MouseEnter.png │ │ │ └── CloseLeftMenu │ │ │ └── Default.png │ ├── Font │ │ └── ProximaNova │ │ │ ├── proxima-nova-thin.ttf │ │ │ └── proxima-nova-light.ttf │ ├── Animations │ │ └── AnimationDictionary.xaml │ └── Theme │ │ └── ClassicTheme.xaml ├── AssemblyInfo.cs ├── Views │ ├── UserControls │ │ ├── NoteView.xaml.cs │ │ ├── SettingsView.xaml.cs │ │ ├── CreateNoteView.xaml.cs │ │ ├── DeleteNoteView.xaml.cs │ │ ├── NoteView.xaml │ │ ├── SettingsView.xaml │ │ ├── DeleteNoteView.xaml │ │ └── CreateNoteView.xaml │ ├── MainView.xaml.cs │ ├── LoginView.xaml.cs │ ├── LoginView.xaml │ └── MainView.xaml ├── ViewModels │ ├── Abstract │ │ └── BaseViewModel.cs │ ├── UserControls │ │ ├── NoteViewModel.cs │ │ ├── DeleteNoteViewModel.cs │ │ ├── SettingsViewModel.cs │ │ └── CreateNoteViewModel.cs │ ├── MainViewModel.cs │ └── LoginViewModel.cs ├── App.xaml ├── GlobalUsings.cs ├── App.xaml.cs └── Notebook.csproj ├── Services ├── Abstract │ ├── Users │ │ ├── IUserRegistrationService.cs │ │ ├── IUserAuthorizationService.cs │ │ ├── IUserRepositoryService.cs │ │ └── IUserFacadeService.cs │ ├── IActiveSessionService.cs │ └── Notes │ │ ├── INoteFacadeService.cs │ │ └── INoteRepositoryService.cs ├── GlobalUsings.cs ├── Services.csproj ├── ApplicationRunnerService.cs ├── ResourcesDictionaryManagerService.cs ├── Users │ ├── UserAuthorizationService.cs │ ├── UserRepositoryService.cs │ ├── UserRegistrationService.cs │ └── UserFacadeService.cs ├── Notes │ ├── NoteRepositoryService.cs │ └── NoteFacadeService.cs ├── ActiveSessionService.cs └── ApplicationConfiguratorService.cs ├── Models ├── Abstract │ ├── IBaseModel.cs │ └── BaseModel.cs ├── Serialize │ └── ApplicationSettings.cs ├── Models.csproj ├── User.cs └── Note.cs ├── MVVM ├── MVVM.csproj └── Command │ └── RelayCommand.cs ├── Data ├── GlobalUsings.cs ├── Repositories │ ├── Abstract │ │ ├── INoteRepository.cs │ │ └── IUserRepository.cs │ ├── UserRepository.cs │ └── NoteRepository.cs ├── Data.csproj └── Context │ └── ApplicationContext.cs ├── Common ├── Common.csproj └── StringHelper.cs ├── .gitattributes ├── Notebook.sln └── .gitignore /Enums/ThemeType.cs: -------------------------------------------------------------------------------- 1 | namespace Enums; 2 | 3 | public enum ThemeType 4 | { 5 | Classic, 6 | Dark 7 | } 8 | -------------------------------------------------------------------------------- /Notebook/ApplicationConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "Theme": 0, 3 | "DataBaseConnection": "Data Source=.\\ApplicationDataBase.db" 4 | } -------------------------------------------------------------------------------- /Notebook/Content/Images/Logo/Logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Images/Logo/Logo.ico -------------------------------------------------------------------------------- /Notebook/Content/Font/ProximaNova/proxima-nova-thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Font/ProximaNova/proxima-nova-thin.ttf -------------------------------------------------------------------------------- /Notebook/Content/Font/ProximaNova/proxima-nova-light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Font/ProximaNova/proxima-nova-light.ttf -------------------------------------------------------------------------------- /Notebook/Content/Images/Controls/MenuControl/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Images/Controls/MenuControl/Default.png -------------------------------------------------------------------------------- /Notebook/Content/Images/Controls/MenuControl/MouseEnter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Images/Controls/MenuControl/MouseEnter.png -------------------------------------------------------------------------------- /Notebook/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, 5 | ResourceDictionaryLocation.SourceAssembly 6 | )] 7 | -------------------------------------------------------------------------------- /Notebook/Content/Images/Controls/WindowControls/Close/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Images/Controls/WindowControls/Close/Default.png -------------------------------------------------------------------------------- /Services/Abstract/Users/IUserRegistrationService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Abstract.Users; 2 | 3 | public interface IUserRegistrationService 4 | { 5 | bool Register(User user); 6 | } 7 | -------------------------------------------------------------------------------- /Notebook/Content/Images/Controls/WindowControls/Close/MouseEnter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Images/Controls/WindowControls/Close/MouseEnter.png -------------------------------------------------------------------------------- /Services/Abstract/Users/IUserAuthorizationService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Abstract.Users; 2 | 3 | public interface IUserAuthorizationService 4 | { 5 | bool Authorize(User user); 6 | } 7 | -------------------------------------------------------------------------------- /Models/Abstract/IBaseModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Models.Abstract; 4 | 5 | public interface IBaseModel 6 | { 7 | int Id { get; set; } 8 | DateTime CreatedDate { get; set; } 9 | } -------------------------------------------------------------------------------- /Notebook/Content/Images/Controls/WindowControls/CloseLeftMenu/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DimaInNature/Notebook/HEAD/Notebook/Content/Images/Controls/WindowControls/CloseLeftMenu/Default.png -------------------------------------------------------------------------------- /Models/Abstract/BaseModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Models.Abstract; 4 | 5 | public abstract class BaseModel : IBaseModel 6 | { 7 | public int Id { get; set; } 8 | public DateTime CreatedDate { get; set; } = DateTime.UtcNow; 9 | } -------------------------------------------------------------------------------- /MVVM/MVVM.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | enable 6 | true 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Enums/Enums.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | enable 6 | true 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Services/Abstract/IActiveSessionService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Abstract; 2 | 3 | public interface IActiveSessionService 4 | { 5 | void StartSession(User user); 6 | void EndSession(); 7 | User GetUser(); 8 | bool GetStatus(); 9 | } 10 | -------------------------------------------------------------------------------- /Data/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Data.Context; 2 | global using Data.Repositories.Abstract; 3 | global using Microsoft.EntityFrameworkCore; 4 | global using Models; 5 | global using System.Collections.Generic; 6 | global using System.Linq; 7 | global using System.Threading.Tasks; -------------------------------------------------------------------------------- /Services/Abstract/Notes/INoteFacadeService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Abstract.Notes; 2 | 3 | public interface INoteFacadeService 4 | { 5 | void Write(Note noteItem); 6 | void Erase(Note noteItem); 7 | IEnumerable GetAll(); 8 | Note GetNoteById(int id); 9 | } 10 | -------------------------------------------------------------------------------- /Models/Serialize/ApplicationSettings.cs: -------------------------------------------------------------------------------- 1 | using Enums; 2 | using System; 3 | 4 | namespace Models.Serialize; 5 | 6 | [Serializable] 7 | public class ApplicationSettings 8 | { 9 | public ThemeType Theme { get; set; } 10 | 11 | public string DataBaseConnection { get; set; } 12 | } -------------------------------------------------------------------------------- /Data/Repositories/Abstract/INoteRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Data.Repositories.Abstract; 2 | 3 | public interface INoteRepository 4 | { 5 | Task AddNoteAsync(Note noteItem); 6 | Task DeleteNote(Note noteItem); 7 | Note GetNoteById(int id); 8 | IEnumerable GetAll(); 9 | } 10 | -------------------------------------------------------------------------------- /Data/Repositories/Abstract/IUserRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Data.Repositories.Abstract; 2 | 3 | public interface IUserRepository 4 | { 5 | Task AddUserAsync(User userItem); 6 | Task DeleteUser(User userItem); 7 | User GetUserById(int id); 8 | IEnumerable GetAll(); 9 | } 10 | -------------------------------------------------------------------------------- /Services/Abstract/Notes/INoteRepositoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Abstract.Notes; 2 | 3 | public interface INoteRepositoryService 4 | { 5 | void AddNote(Note noteItem); 6 | void DeleteNote(Note noteItem); 7 | IEnumerable GetAll(); 8 | Note GetNoteById(int id); 9 | } 10 | -------------------------------------------------------------------------------- /Services/Abstract/Users/IUserRepositoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Abstract.Users; 2 | 3 | public interface IUserRepositoryService 4 | { 5 | void AddUser(User userItem); 6 | void DeleteUser(User userItem); 7 | IEnumerable GetAll(); 8 | User GetUserById(int id); 9 | } 10 | -------------------------------------------------------------------------------- /Services/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Data.Repositories.Abstract; 2 | global using Models; 3 | global using Services.Abstract; 4 | global using Services.Abstract.Notes; 5 | global using Services.Abstract.Users; 6 | global using System; 7 | global using System.Collections.Generic; 8 | global using System.Linq; -------------------------------------------------------------------------------- /Services/Abstract/Users/IUserFacadeService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Abstract.Users; 2 | 3 | public interface IUserFacadeService 4 | { 5 | bool Register(User userItem); 6 | void DeleteUser(User userItem); 7 | IEnumerable GetAll(); 8 | User GetUserById(int id); 9 | bool Authorize(User user); 10 | } 11 | -------------------------------------------------------------------------------- /Common/Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | enable 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Models/Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | enable 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Notebook/Views/UserControls/NoteView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace Notebook.Views.UserControls; 4 | 5 | public partial class NoteView : UserControl 6 | { 7 | public NoteView() 8 | { 9 | InitializeComponent(); 10 | DataContext = (Application.Current as App)? 11 | .ServiceProvider.GetService(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Notebook/Views/UserControls/SettingsView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace Notebook.Views.UserControls; 4 | 5 | public partial class SettingsView : UserControl 6 | { 7 | public SettingsView() 8 | { 9 | InitializeComponent(); 10 | DataContext = (Application.Current as App)? 11 | .ServiceProvider.GetService(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Notebook/ViewModels/Abstract/BaseViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace MVVM.ViewModel.Abstract; 4 | 5 | public abstract class BaseViewModel : INotifyPropertyChanged 6 | { 7 | public event PropertyChangedEventHandler? PropertyChanged; 8 | 9 | public void OnPropertyChanged(string propertyName) => 10 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 11 | } -------------------------------------------------------------------------------- /Notebook/Views/UserControls/CreateNoteView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace Notebook.Views.UserControls; 4 | 5 | public partial class CreateNoteView : UserControl 6 | { 7 | public CreateNoteView() 8 | { 9 | InitializeComponent(); 10 | DataContext = (Application.Current as App)? 11 | .ServiceProvider.GetService(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Models/User.cs: -------------------------------------------------------------------------------- 1 | using Models.Abstract; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace Models; 5 | 6 | [Table("Users")] 7 | public class User : BaseModel 8 | { 9 | public string Login { get; set; } 10 | public string Password { get; set; } 11 | 12 | public User(string login, string password) => 13 | (Login, Password) = (login, password); 14 | 15 | public User() { } 16 | } -------------------------------------------------------------------------------- /Common/StringHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace Common; 4 | 5 | public static class StringHelper 6 | { 7 | public static bool StrIsNotNullOrWhiteSpace(params string[] stringsArray) => 8 | stringsArray.All(stroke => !string.IsNullOrWhiteSpace(stroke)); 9 | 10 | public static bool StrIsNullOrWhiteSpace(params string[] stringsArray) => 11 | stringsArray.All(stroke => string.IsNullOrWhiteSpace(stroke)); 12 | } -------------------------------------------------------------------------------- /Notebook/Views/MainView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Notebook.Views; 2 | 3 | public partial class MainView : Window 4 | { 5 | public MainView() 6 | { 7 | InitializeComponent(); 8 | DataContext = (Application.Current as App)? 9 | .ServiceProvider.GetService(); 10 | } 11 | 12 | private void WindowDragMove(object sender, MouseButtonEventArgs e) 13 | { 14 | if (e.LeftButton == MouseButtonState.Pressed) 15 | DragMove(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Services/Services.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | enable 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Data/Data.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | enable 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Notebook/Views/UserControls/DeleteNoteView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace Notebook.Views.UserControls; 4 | 5 | public partial class DeleteNoteView : UserControl 6 | { 7 | public DeleteNoteView() 8 | { 9 | InitializeComponent(); 10 | DataContext = (Application.Current as App)? 11 | .ServiceProvider.GetService(); 12 | } 13 | 14 | public DeleteNoteView(Note deletableNote) : this() 15 | { 16 | var vm = DataContext as DeleteNoteViewModel; 17 | vm.DeletableNote = deletableNote; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Notebook/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Services/ApplicationRunnerService.cs: -------------------------------------------------------------------------------- 1 | namespace Services; 2 | 3 | public class ApplicationRunnerService 4 | { 5 | private readonly ApplicationConfiguratorService _configurator; 6 | 7 | private readonly ResourcesDictionaryManagerService _recourceManager; 8 | 9 | public ApplicationRunnerService(ApplicationConfiguratorService configurator, 10 | ResourcesDictionaryManagerService recourceManager) 11 | { 12 | _configurator = configurator; 13 | _recourceManager = recourceManager; 14 | } 15 | 16 | public void Run() 17 | { 18 | var theme = _configurator.Theme; 19 | _recourceManager.SwitchTheme(theme); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Models/Note.cs: -------------------------------------------------------------------------------- 1 | using Models.Abstract; 2 | using System; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | namespace Models; 6 | 7 | [Table("Notes")] 8 | public class Note : BaseModel 9 | { 10 | public string Title { get; set; } 11 | public string Text { get; set; } 12 | public int CreatorId { get; set; } 13 | public DateOnly CreationDate { get; set; } 14 | 15 | public Note(string title, 16 | string text, User creator) 17 | { 18 | Title = title; 19 | Text = text; 20 | CreatorId = creator.Id; 21 | CreationDate = DateOnly.FromDateTime(dateTime: DateTime.UtcNow); 22 | } 23 | 24 | public Note() { } 25 | } 26 | -------------------------------------------------------------------------------- /Services/ResourcesDictionaryManagerService.cs: -------------------------------------------------------------------------------- 1 | using Enums; 2 | using System.Windows; 3 | 4 | namespace Services; 5 | 6 | public class ResourcesDictionaryManagerService 7 | { 8 | public void SwitchTheme(ThemeType theme) 9 | { 10 | Application.Current.Resources 11 | .MergedDictionaries.Clear(); 12 | 13 | var url = new Uri( 14 | uriString: $@"/Content/Theme/{theme}Theme.xaml", 15 | uriKind: UriKind.Relative); 16 | 17 | var resource = Application 18 | .LoadComponent(url) as ResourceDictionary; 19 | 20 | Application.Current.Resources 21 | .MergedDictionaries.Add(resource); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Services/Users/UserAuthorizationService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Users; 2 | 3 | public class UserAuthorizationService : IUserAuthorizationService 4 | { 5 | private readonly IUserRepositoryService _repository; 6 | 7 | public UserAuthorizationService(IUserRepositoryService repository) 8 | { 9 | _repository = repository; 10 | } 11 | 12 | public bool Authorize(User user) 13 | { 14 | ArgumentNullException.ThrowIfNull(user); 15 | 16 | var existUser = _repository.GetAll() 17 | .FirstOrDefault(u => u.Login == user.Login && 18 | user.Password == user.Password); 19 | 20 | return existUser is not null; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Services/Notes/NoteRepositoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Notes; 2 | 3 | public class NoteRepositoryService : INoteRepositoryService 4 | { 5 | private readonly INoteRepository _repository; 6 | 7 | public NoteRepositoryService(INoteRepository repository) 8 | { 9 | _repository = repository; 10 | } 11 | 12 | public void AddNote(Note noteItem) => 13 | _repository.AddNoteAsync(noteItem); 14 | 15 | public void DeleteNote(Note noteItem) => 16 | _repository.DeleteNote(noteItem); 17 | 18 | public IEnumerable GetAll() => 19 | _repository.GetAll(); 20 | 21 | public Note GetNoteById(int id) => 22 | _repository.GetNoteById(id); 23 | } 24 | -------------------------------------------------------------------------------- /Services/Users/UserRepositoryService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Users; 2 | 3 | public class UserRepositoryService : IUserRepositoryService 4 | { 5 | private readonly IUserRepository _repository; 6 | 7 | public UserRepositoryService(IUserRepository repository) 8 | { 9 | _repository = repository; 10 | } 11 | 12 | public void AddUser(User userItem) => 13 | _repository.AddUserAsync(userItem); 14 | 15 | public void DeleteUser(User userItem) => 16 | _repository.DeleteUser(userItem); 17 | 18 | public IEnumerable GetAll() => 19 | _repository.GetAll(); 20 | 21 | public User GetUserById(int id) => 22 | _repository.GetUserById(id); 23 | } 24 | -------------------------------------------------------------------------------- /Services/Notes/NoteFacadeService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Notes; 2 | 3 | public class NoteFacadeService : INoteFacadeService 4 | { 5 | private readonly INoteRepositoryService _repositoryService; 6 | 7 | public NoteFacadeService(INoteRepositoryService repository) 8 | { 9 | _repositoryService = repository; 10 | } 11 | 12 | public void Write(Note noteItem) => 13 | _repositoryService.AddNote(noteItem); 14 | 15 | public void Erase(Note noteItem) => 16 | _repositoryService.DeleteNote(noteItem); 17 | 18 | public IEnumerable GetAll() => 19 | _repositoryService.GetAll(); 20 | 21 | public Note GetNoteById(int id) => 22 | _repositoryService.GetNoteById(id); 23 | } 24 | -------------------------------------------------------------------------------- /Data/Repositories/UserRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Data.Repositories; 2 | 3 | public class UserRepository : IUserRepository 4 | { 5 | private readonly ApplicationContext _context; 6 | 7 | public UserRepository(ApplicationContext context) 8 | { 9 | _context = context; 10 | } 11 | 12 | public async Task AddUserAsync(User userItem) 13 | { 14 | await _context.Users.AddAsync(entity: userItem); 15 | await _context.SaveChangesAsync(); 16 | } 17 | 18 | public async Task DeleteUser(User userItem) 19 | { 20 | _context.Users.Attach(entity: userItem); 21 | _context.Users.Remove(entity: userItem); 22 | await _context.SaveChangesAsync(); 23 | } 24 | 25 | public IEnumerable GetAll() => _context.Users; 26 | 27 | public User GetUserById(int id) => 28 | _context.Users.FirstOrDefault(user => user.Id == id); 29 | } -------------------------------------------------------------------------------- /Data/Repositories/NoteRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Data.Repositories; 2 | 3 | public class NoteRepository : INoteRepository 4 | { 5 | private readonly ApplicationContext _context; 6 | 7 | public NoteRepository(ApplicationContext context) 8 | { 9 | _context = context; 10 | } 11 | 12 | public async Task AddNoteAsync(Note noteItem) 13 | { 14 | await _context.Notes.AddAsync(entity: noteItem); 15 | await _context.SaveChangesAsync(); 16 | } 17 | 18 | public async Task DeleteNote(Note noteItem) 19 | { 20 | _context.Notes.Attach(entity: noteItem); 21 | _context.Notes.Remove(entity: noteItem); 22 | await _context.SaveChangesAsync(); 23 | } 24 | 25 | public IEnumerable GetAll() => _context.Notes; 26 | 27 | public Note? GetNoteById(int id) => 28 | _context.Notes.FirstOrDefault(note => note.Id == id); 29 | } 30 | -------------------------------------------------------------------------------- /Notebook/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Common; 2 | global using Data.Context; 3 | global using Data.Repositories; 4 | global using Data.Repositories.Abstract; 5 | global using Enums; 6 | global using Microsoft.EntityFrameworkCore; 7 | global using Microsoft.Extensions.DependencyInjection; 8 | global using Models; 9 | global using MVVM.Command; 10 | global using MVVM.ViewModel.Abstract; 11 | global using Notebook.ViewModels; 12 | global using Notebook.ViewModels.UserControls; 13 | global using Notebook.Views; 14 | global using Notebook.Views.UserControls; 15 | global using Services; 16 | global using Services.Abstract; 17 | global using Services.Abstract.Notes; 18 | global using Services.Abstract.Users; 19 | global using Services.Notes; 20 | global using Services.Users; 21 | global using System; 22 | global using System.Collections.Generic; 23 | global using System.Linq; 24 | global using System.Windows; 25 | global using System.Windows.Input; -------------------------------------------------------------------------------- /MVVM/Command/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Input; 3 | 4 | namespace MVVM.Command; 5 | 6 | public sealed class RelayCommand : ICommand 7 | { 8 | private readonly Action _execute; 9 | 10 | private readonly Func _canExecute; 11 | 12 | public event EventHandler CanExecuteChanged 13 | { 14 | add { CommandManager.RequerySuggested += value; } 15 | remove { CommandManager.RequerySuggested -= value; } 16 | } 17 | 18 | public bool CanExecute(object parameter) => 19 | _canExecute == null || _canExecute(parameter); 20 | 21 | public void Execute(object parameter) => 22 | _execute?.Invoke(parameter); 23 | 24 | public RelayCommand(Action executeAction) 25 | : this(executeAction, null) => 26 | _execute = executeAction; 27 | 28 | public RelayCommand(Action executeAction, 29 | Func canExecuteFunc) => 30 | (_canExecute, _execute) = (canExecuteFunc, executeAction); 31 | } -------------------------------------------------------------------------------- /Notebook/Views/LoginView.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Notebook.Views; 2 | 3 | public partial class LoginView : Window 4 | { 5 | public LoginView() 6 | { 7 | InitializeComponent(); 8 | DataContext = (Application.Current as App)? 9 | .ServiceProvider.GetService(); 10 | } 11 | 12 | private LoginViewModel ViewModel => (LoginViewModel)DataContext; 13 | 14 | private void WindowDragMove(object sender, MouseButtonEventArgs e) 15 | { 16 | if (e.LeftButton == MouseButtonState.Pressed) 17 | DragMove(); 18 | } 19 | 20 | private void EnterPasswordPasswordBox_OnPasswordChanged(object sender, RoutedEventArgs e) => 21 | (ViewModel.Password, ViewModel.SecurePassword) = 22 | (EnterPasswordPasswordBox.Password, EnterPasswordPasswordBox.SecurePassword); 23 | 24 | private void RegisterPasswordPasswordBox_OnPasswordChanged(object sender, RoutedEventArgs e) => 25 | (ViewModel.RegisterPassword, ViewModel.SecureRegisterPassword) = 26 | (RegisterPasswordPasswordBox.Password, RegisterPasswordPasswordBox.SecurePassword); 27 | } 28 | -------------------------------------------------------------------------------- /Services/Users/UserRegistrationService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Users; 2 | 3 | public class UserRegistrationService : IUserRegistrationService 4 | { 5 | private readonly IUserRepositoryService _repository; 6 | 7 | public UserRegistrationService(IUserRepositoryService repositoryService) 8 | { 9 | _repository = repositoryService; 10 | } 11 | 12 | public bool Register(User user) 13 | { 14 | ArgumentNullException.ThrowIfNull(user); 15 | 16 | int usersByLoginCount = _repository.GetAll() 17 | .Where(u => u.Login == user.Login) 18 | .Count(); 19 | 20 | if (usersByLoginCount < 1) 21 | { 22 | int usersByLoginAndPasswordCount = _repository.GetAll() 23 | .Where(u => u.Login == user.Login && u.Password == user.Password) 24 | .Count(); 25 | 26 | if (usersByLoginAndPasswordCount < 1) 27 | { 28 | _repository.AddUser(user); 29 | return true; 30 | } 31 | else 32 | return false; 33 | } 34 | else 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Services/ActiveSessionService.cs: -------------------------------------------------------------------------------- 1 | namespace Services; 2 | 3 | public class ActiveSessionService : IActiveSessionService 4 | { 5 | private readonly IUserRepositoryService _userRepository; 6 | 7 | public ActiveSessionService(IUserRepositoryService userRepositoryService) 8 | { 9 | _userRepository = userRepositoryService; 10 | } 11 | 12 | private User _activeUser; 13 | 14 | private bool _isActive = false; 15 | 16 | public bool GetStatus() => _isActive; 17 | 18 | public void StartSession(User activeUser) 19 | { 20 | if (_isActive is false) 21 | { 22 | _activeUser = string.IsNullOrWhiteSpace(activeUser.Login) || 23 | string.IsNullOrWhiteSpace(activeUser.Password) 24 | ? throw new ArgumentException("Invalid user data") 25 | : _userRepository.GetAll().FirstOrDefault( 26 | user => user.Login == activeUser.Login && 27 | user.Password == activeUser.Password) 28 | ?? throw new ArgumentNullException("There is no user with such data"); 29 | 30 | _isActive = true; 31 | } 32 | } 33 | 34 | public User GetUser() => GetStatus() 35 | ? _activeUser 36 | : throw new InvalidOperationException("The session is not active."); 37 | 38 | public void EndSession() 39 | { 40 | if (_isActive) 41 | { 42 | _activeUser = null; 43 | 44 | _isActive = false; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Notebook/ViewModels/UserControls/NoteViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Notebook.ViewModels.UserControls; 2 | 3 | public class NoteViewModel : BaseViewModel 4 | { 5 | private readonly IActiveSessionService _activeSessionService; 6 | private readonly INoteFacadeService _noteFacadeService; 7 | 8 | public NoteViewModel(IActiveSessionService activeSessionService, 9 | INoteFacadeService noteFacadeService) 10 | { 11 | _noteFacadeService = noteFacadeService; 12 | _activeSessionService = activeSessionService; 13 | 14 | InitializeData(); 15 | } 16 | 17 | #region Properties 18 | 19 | public List Notes 20 | { 21 | get => _notes is null 22 | ? new List() 23 | : _notes; 24 | set 25 | { 26 | _notes = value is null 27 | ? new List() 28 | : value; 29 | OnPropertyChanged(nameof(Notes)); 30 | } 31 | } 32 | 33 | private List _notes; 34 | 35 | public Note SelectedNote 36 | { 37 | get => _selectedNote; 38 | set 39 | { 40 | _selectedNote = value; 41 | OnPropertyChanged(nameof(SelectedNote)); 42 | } 43 | } 44 | 45 | private Note _selectedNote; 46 | 47 | #endregion 48 | 49 | #region Other logic 50 | 51 | private void InitializeData() 52 | { 53 | Notes = _noteFacadeService.GetAll() 54 | .Where(note => note.CreatorId == _activeSessionService.GetUser().Id) 55 | .ToList(); 56 | } 57 | 58 | #endregion 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Data/Context/ApplicationContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Data.Context; 4 | 5 | public class ApplicationContext : DbContext 6 | { 7 | public ApplicationContext(DbContextOptions options) 8 | : base(options) 9 | { 10 | Database.EnsureCreated(); 11 | } 12 | 13 | public DbSet Notes => Set(); 14 | 15 | public DbSet Users => Set(); 16 | 17 | protected override void OnModelCreating(ModelBuilder modelBuilder) 18 | { 19 | modelBuilder.Entity().HasIndex(user => user.Id).IsUnique(); 20 | modelBuilder.Entity().HasData(GetUsers()); 21 | modelBuilder.Entity().HasIndex(note => note.Id).IsUnique(); 22 | modelBuilder.Entity().HasData(GetNotes()); 23 | 24 | base.OnModelCreating(modelBuilder); 25 | } 26 | 27 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 28 | { 29 | base.OnConfiguring(optionsBuilder); 30 | } 31 | 32 | private List GetUsers() 33 | { 34 | return new() 35 | { 36 | new() 37 | { 38 | Id = 1, 39 | Login = "Admin", 40 | Password = "Root" 41 | } 42 | }; 43 | } 44 | 45 | private List GetNotes() 46 | { 47 | return new() 48 | { 49 | new() 50 | { 51 | Id = 1, 52 | Text = "This is first note", 53 | Title = "Hello World", 54 | CreationDate = DateOnly.FromDateTime(DateTime.UtcNow), 55 | CreatorId = 1 56 | } 57 | }; 58 | } 59 | } -------------------------------------------------------------------------------- /Notebook/ViewModels/UserControls/DeleteNoteViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Notebook.ViewModels.UserControls; 2 | 3 | public class DeleteNoteViewModel : BaseViewModel 4 | { 5 | private readonly INoteFacadeService _noteService; 6 | 7 | public DeleteNoteViewModel(INoteFacadeService noteService) 8 | { 9 | _noteService = noteService; 10 | 11 | InitializeCommands(); 12 | } 13 | 14 | #region Properties 15 | 16 | public Note? DeletableNote 17 | { 18 | get => _deletableNote; 19 | set 20 | { 21 | _deletableNote = value; 22 | OnPropertyChanged(nameof(DeletableNote)); 23 | } 24 | } 25 | 26 | private Note? _deletableNote; 27 | 28 | #endregion 29 | 30 | #region Commands 31 | 32 | public ICommand DeleteNoteCommand { get; private set; } 33 | 34 | #endregion 35 | 36 | #region Command Methods 37 | 38 | #region Execute 39 | 40 | private void ExecuteDeleteNote(object obj) 41 | { 42 | _noteService.Erase(noteItem: DeletableNote); 43 | 44 | DeletableNote = null; 45 | 46 | MessageBox.Show(messageBoxText: "Запись удалена", caption: "Успех", 47 | button: MessageBoxButton.OK, icon: MessageBoxImage.Information); 48 | } 49 | 50 | #endregion 51 | 52 | #region CanExecute 53 | 54 | private bool CanExecuteDeleteNote(object obj) => 55 | DeletableNote is not null; 56 | 57 | #endregion 58 | 59 | #endregion 60 | 61 | #region Other logic 62 | 63 | private void InitializeCommands() 64 | { 65 | DeleteNoteCommand = new RelayCommand(executeAction: ExecuteDeleteNote, 66 | canExecuteFunc: CanExecuteDeleteNote); 67 | } 68 | 69 | #endregion 70 | } 71 | -------------------------------------------------------------------------------- /Services/Users/UserFacadeService.cs: -------------------------------------------------------------------------------- 1 | namespace Services.Users; 2 | 3 | public class UserFacadeService : IUserFacadeService, IUserAuthorizationService, IUserRegistrationService 4 | { 5 | private readonly IUserRepositoryService _repository; 6 | private readonly IUserAuthorizationService _authorizationService; 7 | private readonly IUserRegistrationService _registrationService; 8 | private readonly IActiveSessionService _activeSessionService; 9 | 10 | public UserFacadeService(IUserRepositoryService repository, 11 | IUserAuthorizationService authorizationService, IActiveSessionService activeSession, 12 | IUserRegistrationService registrationService) 13 | { 14 | _repository = repository; 15 | _authorizationService = authorizationService; 16 | _activeSessionService = activeSession; 17 | _registrationService = registrationService; 18 | } 19 | 20 | public bool Register(User userItem) 21 | { 22 | bool registerIsSuccessfull = 23 | _registrationService.Register(user: userItem); 24 | 25 | if (registerIsSuccessfull) 26 | _activeSessionService.StartSession(user: userItem); 27 | 28 | return registerIsSuccessfull; 29 | } 30 | 31 | public void DeleteUser(User userItem) => 32 | _repository.DeleteUser(userItem); 33 | 34 | public IEnumerable GetAll() => 35 | _repository.GetAll(); 36 | 37 | public User GetUserById(int id) => 38 | _repository.GetUserById(id); 39 | 40 | public bool Authorize(User user) 41 | { 42 | bool authIsSuccessfull = _authorizationService.Authorize(user); 43 | 44 | if (authIsSuccessfull) 45 | _activeSessionService.StartSession(user: user); 46 | 47 | return authIsSuccessfull; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Notebook/ViewModels/UserControls/SettingsViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Notebook.ViewModels.UserControls; 2 | 3 | public class SettingsViewModel : BaseViewModel 4 | { 5 | private readonly ResourcesDictionaryManagerService _recourceManager; 6 | private readonly ApplicationConfiguratorService _configurator; 7 | 8 | public SettingsViewModel(ResourcesDictionaryManagerService recourceManager, 9 | ApplicationConfiguratorService configurator) 10 | { 11 | _recourceManager = recourceManager; 12 | _configurator = configurator; 13 | 14 | SelectedIndex = (int)_configurator.Theme; 15 | 16 | InitializeCommands(); 17 | } 18 | 19 | #region Data 20 | 21 | public List ThemeItems 22 | { 23 | get => _themeItems; 24 | set 25 | { 26 | _themeItems = value; 27 | OnPropertyChanged(nameof(ThemeItems)); 28 | } 29 | } 30 | 31 | private List _themeItems = new() 32 | { 33 | ThemeType.Classic.ToString(), 34 | ThemeType.Dark.ToString(), 35 | }; 36 | 37 | public int SelectedIndex 38 | { 39 | get => _selectedIndex; 40 | set 41 | { 42 | _selectedIndex = value; 43 | OnPropertyChanged(nameof(SelectedIndex)); 44 | } 45 | } 46 | 47 | private int _selectedIndex; 48 | 49 | #endregion 50 | 51 | #region Commands 52 | 53 | public ICommand ThemeChangedCommand { get; private set; } 54 | 55 | #endregion 56 | 57 | #region Command logic 58 | 59 | #region Execute 60 | 61 | private void ExecuteThemeChangedCommand(object obj) 62 | { 63 | _configurator.Theme = (ThemeType)SelectedIndex; 64 | _recourceManager.SwitchTheme(_configurator.Theme); 65 | } 66 | 67 | #endregion 68 | 69 | #endregion 70 | 71 | #region Other logic 72 | 73 | private void InitializeCommands() 74 | { 75 | ThemeChangedCommand = new RelayCommand(executeAction: ExecuteThemeChangedCommand); 76 | } 77 | 78 | #endregion 79 | } 80 | -------------------------------------------------------------------------------- /Notebook/App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace Notebook; 2 | 3 | public partial class App : Application 4 | { 5 | public IServiceProvider ServiceProvider { get; private set; } 6 | private ApplicationConfiguratorService _configuratorService; 7 | 8 | public App() 9 | { 10 | _configuratorService = new(); 11 | } 12 | 13 | protected override void OnStartup(StartupEventArgs e) 14 | { 15 | var serviceCollection = new ServiceCollection(); 16 | 17 | serviceCollection.AddScoped(); 18 | 19 | ConfigureServices(services: serviceCollection); 20 | 21 | ConfigureViewModels(services: serviceCollection); 22 | 23 | ServiceProvider = serviceCollection.BuildServiceProvider(); 24 | 25 | ServiceProvider.GetService()?.Run(); 26 | 27 | var mainWindow = new LoginView 28 | { 29 | DataContext = ServiceProvider.GetService() 30 | }; 31 | 32 | mainWindow.Show(); 33 | } 34 | 35 | private void ConfigureServices(IServiceCollection services) 36 | { 37 | services.AddDbContext(options => 38 | { 39 | options.UseSqlite(_configuratorService.DataBaseConnection); 40 | }); 41 | 42 | services.AddSingleton(); 43 | services.AddTransient(); 44 | services.AddTransient(); 45 | 46 | services.AddSingleton(); 47 | services.AddSingleton(); 48 | services.AddSingleton(); 49 | 50 | services.AddSingleton(); 51 | services.AddTransient(); 52 | services.AddTransient(); 53 | services.AddTransient(); 54 | services.AddTransient(); 55 | } 56 | 57 | private void ConfigureViewModels(IServiceCollection services) 58 | { 59 | services.AddTransient(); 60 | services.AddTransient(); 61 | services.AddTransient(); 62 | services.AddTransient(); 63 | services.AddTransient(); 64 | services.AddTransient(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Notebook/ViewModels/UserControls/CreateNoteViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Notebook.ViewModels.UserControls; 2 | 3 | public class CreateNoteViewModel : BaseViewModel 4 | { 5 | private readonly INoteFacadeService _noteService; 6 | private readonly IActiveSessionService _activeSessionService; 7 | 8 | public CreateNoteViewModel(INoteFacadeService noteService, 9 | IActiveSessionService activeSessionService) 10 | { 11 | _noteService = noteService; 12 | _activeSessionService = activeSessionService; 13 | 14 | InitializeCommands(); 15 | } 16 | 17 | #region Properties 18 | 19 | public string Title 20 | { 21 | get => _title; 22 | set 23 | { 24 | _title = value; 25 | OnPropertyChanged(nameof(Title)); 26 | } 27 | } 28 | 29 | private string _title; 30 | 31 | public string Text 32 | { 33 | get => _text; 34 | set 35 | { 36 | _text = value; 37 | OnPropertyChanged(nameof(Text)); 38 | } 39 | } 40 | 41 | private string _text; 42 | 43 | #endregion 44 | 45 | #region Commands 46 | 47 | public ICommand CreateNoteCommand { get; private set; } 48 | 49 | public ICommand ClearTextCommand { get; private set; } 50 | 51 | #endregion 52 | 53 | #region Command Methods 54 | 55 | #region Execute 56 | 57 | private void ExecuteCreateNote(object obj) 58 | { 59 | var note = new Note(title: Title, 60 | text: Text, 61 | creator: _activeSessionService.GetUser()); 62 | 63 | _noteService.Write(noteItem: note); 64 | 65 | Text = Title = string.Empty; 66 | 67 | MessageBox.Show(messageBoxText: "Запись создана", caption: "Успех", 68 | button: MessageBoxButton.OK, icon: MessageBoxImage.Information); 69 | } 70 | 71 | private void ExecuteClearText(object obj) => 72 | Text = Title = string.Empty; 73 | 74 | #endregion 75 | 76 | #region CanExecute 77 | 78 | private bool CanExecuteCreateNote(object obj) => 79 | StringHelper.StrIsNotNullOrWhiteSpace(Text, Title); 80 | 81 | private bool CanExecuteClearText(object obj) => 82 | StringHelper.StrIsNotNullOrWhiteSpace(Text) || 83 | StringHelper.StrIsNotNullOrWhiteSpace(Title); 84 | 85 | #endregion 86 | 87 | #endregion 88 | 89 | #region Other logic 90 | 91 | private void InitializeCommands() 92 | { 93 | CreateNoteCommand = new RelayCommand(executeAction: ExecuteCreateNote, 94 | canExecuteFunc: CanExecuteCreateNote); 95 | 96 | ClearTextCommand = new RelayCommand(executeAction: ExecuteClearText, 97 | canExecuteFunc: CanExecuteClearText); 98 | } 99 | 100 | #endregion 101 | 102 | } 103 | -------------------------------------------------------------------------------- /Notebook/Views/UserControls/NoteView.xaml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 23 | 24 | 25 | 26 | 32 | 33 | 34 | 35 | 41 | 42 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Notebook/Notebook.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | net6.0-windows 6 | enable 7 | true 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Always 24 | 25 | 26 | Always 27 | 28 | 29 | Always 30 | 31 | 32 | PreserveNewest 33 | 34 | 35 | PreserveNewest 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Always 57 | 58 | 59 | Always 60 | 61 | 62 | 63 | 64 | 65 | PreserveNewest 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Services/ApplicationConfiguratorService.cs: -------------------------------------------------------------------------------- 1 | using Enums; 2 | using Models.Serialize; 3 | using Newtonsoft.Json; 4 | using Newtonsoft.Json.Converters; 5 | using System.IO; 6 | 7 | namespace Services; 8 | 9 | public class ApplicationConfiguratorService 10 | { 11 | public const string ConfigurationFilePath = @"ApplicationConfig.json"; 12 | 13 | public ThemeType Theme 14 | { 15 | get 16 | { 17 | if (File.Exists(path: ConfigurationFilePath)) 18 | { 19 | string json = File.ReadAllText(path: ConfigurationFilePath); 20 | 21 | ApplicationSettings? settings = new(); 22 | 23 | if (!string.IsNullOrWhiteSpace(json)) 24 | settings = JsonConvert.DeserializeObject(json); 25 | 26 | return settings.Theme; 27 | } 28 | else 29 | return ThemeType.Classic; 30 | } 31 | set 32 | { 33 | switch (value) 34 | { 35 | case ThemeType.Classic or ThemeType.Dark: 36 | 37 | var data = new ApplicationSettings() 38 | { 39 | Theme = value, 40 | DataBaseConnection = DataBaseConnection 41 | }; 42 | 43 | var serializer = new JsonSerializer(); 44 | serializer.Converters.Add(item: new JavaScriptDateTimeConverter()); 45 | serializer.NullValueHandling = NullValueHandling.Ignore; 46 | 47 | using (var stream = new StreamWriter(path: ConfigurationFilePath)) 48 | { 49 | using var writer = new JsonTextWriter(textWriter: stream); 50 | serializer.Serialize(jsonWriter: writer, value: data); 51 | } 52 | break; 53 | } 54 | } 55 | } 56 | 57 | public string DataBaseConnection 58 | { 59 | get 60 | { 61 | string configurationFilePath = ConfigurationFilePath; 62 | 63 | if (File.Exists(path: configurationFilePath)) 64 | { 65 | string json = File.ReadAllText(path: configurationFilePath); 66 | 67 | ApplicationSettings? settings = new(); 68 | 69 | if (!string.IsNullOrWhiteSpace(json)) 70 | settings = JsonConvert.DeserializeObject(json); 71 | 72 | return settings?.DataBaseConnection 73 | ?? throw new FileNotFoundException("Connection string is not founded"); 74 | } 75 | else 76 | throw new FileNotFoundException("Not found configuration file"); 77 | } 78 | set 79 | { 80 | ApplicationSettings data = new() 81 | { 82 | Theme = Theme, 83 | DataBaseConnection = value 84 | }; 85 | 86 | var serializer = new JsonSerializer(); 87 | serializer.Converters.Add(item: new JavaScriptDateTimeConverter()); 88 | serializer.NullValueHandling = NullValueHandling.Ignore; 89 | 90 | using StreamWriter stream = new(path: ConfigurationFilePath); 91 | using JsonTextWriter writer = new(textWriter: stream); 92 | serializer.Serialize(jsonWriter: writer, value: data); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Notebook.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32112.339 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notebook", "Notebook\Notebook.csproj", "{6552DB9D-FAA4-4A01-ADAA-4D2FC1EFC8B5}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{803BCC3C-865B-40B4-8A61-DD352B09CD88}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MVVM", "MVVM\MVVM.csproj", "{014B8DD2-2B4D-4082-A637-735280DD46B7}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{0049DB4A-0DE7-41C8-A8C7-A4394549C0E9}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{47893C07-3E46-492E-B796-0AB0D120E624}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{9D7AC3F7-F635-4242-B3FB-C36C3DB3DC36}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enums", "Enums\Enums.csproj", "{CDF89617-7130-481E-A06D-05A8E6AF5BA3}" 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {6552DB9D-FAA4-4A01-ADAA-4D2FC1EFC8B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {6552DB9D-FAA4-4A01-ADAA-4D2FC1EFC8B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {6552DB9D-FAA4-4A01-ADAA-4D2FC1EFC8B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {6552DB9D-FAA4-4A01-ADAA-4D2FC1EFC8B5}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {803BCC3C-865B-40B4-8A61-DD352B09CD88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {803BCC3C-865B-40B4-8A61-DD352B09CD88}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {803BCC3C-865B-40B4-8A61-DD352B09CD88}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {803BCC3C-865B-40B4-8A61-DD352B09CD88}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {014B8DD2-2B4D-4082-A637-735280DD46B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {014B8DD2-2B4D-4082-A637-735280DD46B7}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {014B8DD2-2B4D-4082-A637-735280DD46B7}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {014B8DD2-2B4D-4082-A637-735280DD46B7}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {0049DB4A-0DE7-41C8-A8C7-A4394549C0E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {0049DB4A-0DE7-41C8-A8C7-A4394549C0E9}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {0049DB4A-0DE7-41C8-A8C7-A4394549C0E9}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {0049DB4A-0DE7-41C8-A8C7-A4394549C0E9}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {47893C07-3E46-492E-B796-0AB0D120E624}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {47893C07-3E46-492E-B796-0AB0D120E624}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {47893C07-3E46-492E-B796-0AB0D120E624}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {47893C07-3E46-492E-B796-0AB0D120E624}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {9D7AC3F7-F635-4242-B3FB-C36C3DB3DC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {9D7AC3F7-F635-4242-B3FB-C36C3DB3DC36}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {9D7AC3F7-F635-4242-B3FB-C36C3DB3DC36}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {9D7AC3F7-F635-4242-B3FB-C36C3DB3DC36}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {CDF89617-7130-481E-A06D-05A8E6AF5BA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {CDF89617-7130-481E-A06D-05A8E6AF5BA3}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {CDF89617-7130-481E-A06D-05A8E6AF5BA3}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {CDF89617-7130-481E-A06D-05A8E6AF5BA3}.Release|Any CPU.Build.0 = Release|Any CPU 54 | EndGlobalSection 55 | GlobalSection(SolutionProperties) = preSolution 56 | HideSolutionNode = FALSE 57 | EndGlobalSection 58 | GlobalSection(ExtensibilityGlobals) = postSolution 59 | SolutionGuid = {2A34B6ED-3B1D-4D53-85A5-BF91632F15A8} 60 | EndGlobalSection 61 | EndGlobal 62 | -------------------------------------------------------------------------------- /Notebook/Views/UserControls/SettingsView.xaml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 59 | 60 | 61 | 62 | 73 | 74 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Notebook/Views/UserControls/DeleteNoteView.xaml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 63 | 64 | 75 | 76 | 85 | 86 | 87 | 100 | 101 | 102 | 103 |