diff --git a/OwnChar/Data/ClientServerDataProvider.cs b/OwnChar/Data/ClientServerDataProvider.cs index abb5733..d72181e 100644 --- a/OwnChar/Data/ClientServerDataProvider.cs +++ b/OwnChar/Data/ClientServerDataProvider.cs @@ -1,4 +1,5 @@ -using System; +using OwnChar.Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +9,44 @@ namespace OwnChar.Data { public class ClientServerDataProvider : IDataProvider { + public bool Save(Character character) + { + } + + public bool Save(UserProfile profile) + { + } + + public bool Save(UserAccount account) + { + } + + public bool Save(Group group) + { + } + + public bool Save(PropertyCategory category) + { + } + + public bool Delete(Character character) + { + } + + public bool Delete(UserProfile profile) + { + } + + public bool Delete(UserAccount account) + { + } + + public bool Delete(Group group) + { + } + + public bool Delete(PropertyCategory category) + { + } } } diff --git a/OwnChar/Manager/CharacterManager.cs b/OwnChar/Manager/CharacterManager.cs new file mode 100644 index 0000000..a745458 --- /dev/null +++ b/OwnChar/Manager/CharacterManager.cs @@ -0,0 +1,54 @@ +using OwnChar.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OwnChar.Manager +{ + public class CharacterManager(OwnCharManager manager) + { + public OwnCharManager Manager { get; } = manager; + + /// + /// Gets personal characters. + /// + /// + /// Returns a collection with personal characters. + public IEnumerable? GetCharacters() + { + if (!IsLoggedIn || UserProfile == null) + return null; + + return GetCharacters(UserProfile.Group); + } + + /// + /// Gets all public ore accessable (e.g. via shares) characters from the specified group. + /// + /// + /// Returns a collection with characters for the specified group. + public IEnumerable GetCharacters(Group group) + { + } + + /// + /// Saves a character. If it doesn't exists, it will be created. + /// + /// The caracter to save. + /// if success, otherwise . + public bool SaveCharacter(Character character) + { + } + + /// + /// Deletes a given character. If it doesn't exists, it will be ignored. + /// + /// + /// if the given character has been deleted successfully or doesn't exist, otherwise . + public bool DeleteCharacter(Character character) + { + } + } +} diff --git a/OwnChar/Manager/GroupsManager.cs b/OwnChar/Manager/GroupsManager.cs new file mode 100644 index 0000000..914f7ad --- /dev/null +++ b/OwnChar/Manager/GroupsManager.cs @@ -0,0 +1,50 @@ +using OwnChar.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OwnChar.Manager +{ + public class GroupsManager(OwnCharManager manager) + { + public OwnCharManager Manager { get; } = manager; + + public Group? GetGroup() + { + if (!IsLoggedIn || UserProfile == null) + return null; + + // ... + } + + public IEnumerable? GetGroups() + { + if (!IsLoggedIn || UserProfile == null) + return null; + + return GetGroups(UserProfile); + } + + public IEnumerable? GetGroups(UserProfile profile) + { + if (!IsLoggedIn) + return null; + + // ... + } + + public Group? CreateGroup(UserProfile owner) + { + } + + public bool SaveGroup(Group group) + { + } + + public bool DeleteGroup(Group group) + { + } + } +} diff --git a/OwnChar/Manager/OwnCharManager.cs b/OwnChar/Manager/OwnCharManager.cs index 9815578..043d1e8 100644 --- a/OwnChar/Manager/OwnCharManager.cs +++ b/OwnChar/Manager/OwnCharManager.cs @@ -1,13 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OwnChar.Data; +using OwnChar.Model; +using Pilz.Cryptography; namespace OwnChar.Manager { public class OwnCharManager { + // User + public bool IsLoggedIn { get; set; } + public UserAccount? CurrentUser { get; set; } + // Data Provider + public IDataProvider DataProvider { get; set; } + + // Manager + public UserManager Users { get; } + public GroupsManager Groups { get; } + public CharacterManager Characters { get; } + + public OwnCharManager(IDataProvider dataProvider) + { + DataProvider = dataProvider; + Users = new(this); + Groups = new(this); + Characters = new(this); + } + + /// + /// Tries to login on the server. + /// + /// Returns if the login was successfull and if not. + public bool Login(string username, SecureString password) + { + return IsLoggedIn = true; // TODO: Change `true` to the real check. + } } } diff --git a/OwnChar/Manager/UserManager.cs b/OwnChar/Manager/UserManager.cs new file mode 100644 index 0000000..780c03e --- /dev/null +++ b/OwnChar/Manager/UserManager.cs @@ -0,0 +1,52 @@ +using OwnChar.Model; +using Pilz.Cryptography; + +namespace OwnChar.Manager +{ + public class UserManager(OwnCharManager manager) + { + public OwnCharManager Manager { get; } = manager; + + public UserAccount? CreateAccount(string username, SecureString password, string email, string displayName) + { + // Create account + // ... + + // Create profile + // ... + } + + /// + /// Saves the current logged in user account. + /// + /// if success, otherwise . + public bool SaveAccount() + { + } + + public bool DeleteAccount() + { + } + + public UserProfile? CreateProfile() + { + // Create profile + // ... + + // Create pre-defined group + // ... + } + + /// + /// Saves the current logged in user profile. + /// + /// if success, otherwise . + public bool SaveProfile() + { + } + + public bool DeleteProfile() + { + } + } +} diff --git a/OwnChar/Model/Character.cs b/OwnChar/Model/Character.cs index 90b0642..a34aefb 100644 --- a/OwnChar/Model/Character.cs +++ b/OwnChar/Model/Character.cs @@ -1,8 +1,11 @@ namespace OwnChar.Model { - public class Character + public class Character(Group group, string name) { public ulong Id { get; set; } - public PropertyList Properties { get; set; } = []; + public string Name { get; set; } = name; + public Group Group { get; set; } = group; + public List Properties { get; set; } = []; + public List PropertyCategories { get; set; } = []; } } diff --git a/OwnChar/Model/Group.cs b/OwnChar/Model/Group.cs new file mode 100644 index 0000000..41f776e --- /dev/null +++ b/OwnChar/Model/Group.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OwnChar.Model +{ + public class Group(UserProfile owner) + { + public int Id { get; set; } + public UserProfile Owner { get; set; } = owner; + public List Members { get; set; } = []; + } +} diff --git a/OwnChar/Model/PropertyList.cs b/OwnChar/Model/PropertyList.cs deleted file mode 100644 index 08b1ee4..0000000 --- a/OwnChar/Model/PropertyList.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace OwnChar.Model -{ - public class PropertyList : List - { - } -} diff --git a/OwnChar/Model/UserAccount.cs b/OwnChar/Model/UserAccount.cs index a2f36d6..ff69c91 100644 --- a/OwnChar/Model/UserAccount.cs +++ b/OwnChar/Model/UserAccount.cs @@ -1,17 +1,17 @@ -using Pilz.Cryptography; - -namespace OwnChar.Model +namespace OwnChar.Model { - public class UserAccount(string email, string username, SecureString password, string? displayName) + public class UserAccount { public ulong Id { get; set; } - public UserProfile Profile { get; set; } = new(string.IsNullOrWhiteSpace(displayName) ? username : displayName); - public string Username { get; set; } = username; - public string Email { get; set; } = email; - public SecureString Password { get; set; } = password; + public string Username { get; set; } + public string Email { get; set; } + public string Password { get; set; } - public UserAccount(string email, string username, SecureString password) : this(email, username, password, username) + internal UserAccount(string email, string username, string password) { + Username = username; + Email = email; + Password = password; } } } diff --git a/OwnChar/Model/UserProfile.cs b/OwnChar/Model/UserProfile.cs index ea19eda..767b19f 100644 --- a/OwnChar/Model/UserProfile.cs +++ b/OwnChar/Model/UserProfile.cs @@ -4,5 +4,6 @@ { public ulong Id { get; set; } public string Name { get; set; } = name; + public UserAccount? Account { get; set; } } }