implement some missing method content
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using OwnChar.Data.Providers.JsonFile.Model;
|
||||
using OwnChar.Model;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace OwnChar.Data.Providers.JsonFile
|
||||
{
|
||||
@@ -90,59 +91,131 @@ namespace OwnChar.Data.Providers.JsonFile
|
||||
return JsonFile.UserAccounts.Count != 0;
|
||||
}
|
||||
|
||||
bool IDataProvider.Delete<T>(T obj)
|
||||
public bool Delete<T>(T obj) where T : class, IOwnCharObject
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (obj is JsonCharacter character)
|
||||
{
|
||||
JsonFile.Groups.ForEach(n => n.Characters.Remove(character));
|
||||
return true;
|
||||
}
|
||||
else if (obj is JsonProp prop)
|
||||
{
|
||||
JsonFile.Characters.ForEach(n => n.Properties.Remove(prop));
|
||||
return true;
|
||||
}
|
||||
else if (obj is JsonPropCat propCat)
|
||||
{
|
||||
JsonFile.Characters.ForEach(n => n.Properties.ForEach(m =>
|
||||
{
|
||||
if (m.Category == propCat)
|
||||
m.Category = null;
|
||||
}));
|
||||
JsonFile.Characters.ForEach(n => n.PropertyCategories.Remove(propCat));
|
||||
return true;
|
||||
}
|
||||
else if (obj is JsonGroup group)
|
||||
{
|
||||
JsonFile.Groups.Remove(group);
|
||||
return true;
|
||||
}
|
||||
else if (obj is JsonUserAccount account)
|
||||
{
|
||||
JsonFile.UserAccounts.Remove(account);
|
||||
return true;
|
||||
}
|
||||
else if (obj is JsonUserProfile profile)
|
||||
{
|
||||
// We don't delete profiles at the moment!
|
||||
profile.Name = "Deleted user";
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetParent(UserProfile profile, UserAccount parent)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (parent is JsonUserAccount jaccount && profile is JsonUserProfile jprofile)
|
||||
{
|
||||
jaccount.Profile = jprofile;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetParent(Character character, Group parent)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (character is JsonCharacter jcharacter && parent is JsonGroup jgroup)
|
||||
{
|
||||
if (!jgroup.Characters.Contains(jcharacter))
|
||||
jgroup.Characters.Add(jcharacter);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetParent(Property property, Character character)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (property is JsonProp jprop && character is JsonCharacter jcharacter)
|
||||
{
|
||||
if (!jcharacter.Properties.Contains(jprop))
|
||||
jcharacter.Properties.Add(jprop);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetOwner(Group group, UserProfile owner)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (group is JsonGroup jgroup && owner is JsonUserProfile jprofile)
|
||||
{
|
||||
jgroup.Owner = jprofile;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetOwner(Character group, UserProfile owner)
|
||||
public bool SetOwner(Character character, UserProfile owner)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (character is JsonCharacter jcharacter && owner is JsonUserProfile jprofile)
|
||||
{
|
||||
jcharacter.Owner = jprofile;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public UserAccount? GetUserAccount(string username, string password)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(username, nameof(username));
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(password, nameof(password));
|
||||
return JsonFile.UserAccounts.FirstOrDefault(n => n.Username == username && n.Password == password);
|
||||
}
|
||||
|
||||
public UserProfile? GetUserProfile(string username)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return JsonFile.UserAccounts.FirstOrDefault(n => n.Username == username)?.Profile;
|
||||
}
|
||||
|
||||
public IEnumerable<UserProfile> GetGroupMembers(Group group)
|
||||
public IEnumerable<UserProfile>? GetGroupMembers(Group group)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (group is JsonGroup jgroup)
|
||||
return jgroup.Members;
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserProfile? GetOwner(Group group)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (group is JsonGroup jgroup)
|
||||
return jgroup.Owner;
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserProfile? GetOwner(Character character)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (character is JsonCharacter jcharacter)
|
||||
return jcharacter.Owner;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user