Compare commits

...

1 Commits

Author SHA1 Message Date
Schedel Pascal
cd32786115 minor renames & updates 2024-07-05 11:56:55 +02:00
3 changed files with 44 additions and 25 deletions

View File

@@ -2,7 +2,7 @@
public static class DataManagerActions public static class DataManagerActions
{ {
public static DataManagerAction Get { get; } = new("create"); public static DataManagerAction Get { get; } = new("get");
public static DataManagerAction Save { get; } = new("save"); public static DataManagerAction Save { get; } = new("save");
public static DataManagerAction Delete { get; } = new("delete"); public static DataManagerAction Delete { get; } = new("delete");
public static DataManagerAction Associate { get; } = new("associate"); public static DataManagerAction Associate { get; } = new("associate");

View File

@@ -28,7 +28,7 @@ public class DefaultDataManager : IDataManager
if (e.IsHandled) if (e.IsHandled)
return new(true, e.Result); return new(true, e.Result);
if (HandleCreate(e) if (HandleGet(e)
|| HandleDelete(e) || HandleDelete(e)
|| HandleSave(e) || HandleSave(e)
|| HandleAssociation(e)) || HandleAssociation(e))
@@ -39,7 +39,7 @@ public class DefaultDataManager : IDataManager
return new(success, e.Result); return new(success, e.Result);
} }
protected virtual bool HandleCreate(OnActionEventArgs e) protected virtual bool HandleGet(OnActionEventArgs e)
{ {
if (e.Action != DataManagerActions.Get) if (e.Action != DataManagerActions.Get)
return false; return false;
@@ -47,42 +47,38 @@ public class DefaultDataManager : IDataManager
// Character // Character
if (e.Action == DataManagerActions.Getter.Character) if (e.Action == DataManagerActions.Getter.Character)
{ {
// Get
if (e.ActionType == DataManagerActionType.Set) if (e.ActionType == DataManagerActionType.Set)
{ {
if (e.Object is not Group group || e.Parameters.Length < 1 || e.Parameters[0] is not string name) if (e.Object is Group group && e.Parameters.GetAt(0, out string? name))
return false; return e.SetResult(CreateCharacter(e.CurrentUser, name, group));
e.Result = CreateCharacter(e.CurrentUser, name, group);
return e.Result != null;
} }
} }
// Group // Group
if (e.Action == DataManagerActions.Getter.Group) if (e.Action == DataManagerActions.Getter.Group)
{ {
// Get
if (e.ActionType == DataManagerActionType.Get) if (e.ActionType == DataManagerActionType.Get)
{ {
if (e.Parameters.Length < 1 || e.Parameters[0] is not string name) if (e.Parameters.GetAt(0, out string? name))
return false; return e.SetResult(CreateGroup(e.CurrentUser, name));
e.Result = CreateGroup(e.CurrentUser, name);
return e.Result != null;
} }
} }
// User // User
if (e.Action == DataManagerActions.Getter.UserAccount) if (e.Action == DataManagerActions.Getter.UserAccount)
{ {
// Get
if (e.ActionType == DataManagerActionType.Get) if (e.ActionType == DataManagerActionType.Get)
{ {
if (e.Parameters.Length < 2 || e.Parameters[0] is not string username || e.Parameters[1] is not string password) if (e.Parameters.GetAt(0, out string? username) && e.Parameters.GetAt(1, out string? password))
return false; return e.SetResult(CreateUserAccount(username, password));
e.Result = CreateUserAccount(username, password);
return e.Result != null;
} }
//else
//{ // Create
// e.Result = DataProvider.GetUserAccounts(); //else if (e.ActionType == DataManagerActionType.Set(
// return e.Result != null; // return e.SetResult(DataProvider.GetUserAccounts());
//}
} }
return false; return false;
@@ -130,8 +126,7 @@ public class DefaultDataManager : IDataManager
switch (e.ActionType) switch (e.ActionType)
{ {
case DataManagerActionType.Get: case DataManagerActionType.Get:
e.Result = DataProvider.GetOwner(group); return e.SetResultT(DataProvider.GetOwner(group));
return true;
case DataManagerActionType.Set: case DataManagerActionType.Set:
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile) if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
return DataProvider.SetOwner(group, profile); return DataProvider.SetOwner(group, profile);
@@ -144,8 +139,7 @@ public class DefaultDataManager : IDataManager
switch (e.ActionType) switch (e.ActionType)
{ {
case DataManagerActionType.Get: case DataManagerActionType.Get:
e.Result = DataProvider.GetOwner(character); return e.SetResultT(DataProvider.GetOwner(character));
return true;
case DataManagerActionType.Set: case DataManagerActionType.Set:
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile) if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
return DataProvider.SetOwner(character, profile); return DataProvider.SetOwner(character, profile);

View File

@@ -1,11 +1,36 @@
using OwnChar.Model; using OwnChar.Data;
using OwnChar.Model;
using System.Diagnostics.CodeAnalysis;
namespace OwnChar; namespace OwnChar;
public static class Extensions public static class Extensions
{ {
public static bool GetAt<T>(this object?[] @this, int index, [NotNullWhen(true)] out T? result)
{
if (@this.ElementAtOrDefault(index) is T obj)
{
result = obj;
return true;
}
result = default;
return false;
}
public static bool HasPermission(this UserAccount account, UserType permissions) public static bool HasPermission(this UserAccount account, UserType permissions)
{ {
return account.Type >= permissions; return account.Type >= permissions;
} }
public static bool SetResult(this OnActionEventArgs @this, object? data)
{
@this.Result = data;
return @this.Result != null;
}
public static bool SetResultT(this OnActionEventArgs @this, object? data)
{
@this.Result = data;
return true;
}
} }