minor renames & updates
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
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 Delete { get; } = new("delete");
|
||||
public static DataManagerAction Associate { get; } = new("associate");
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DefaultDataManager : IDataManager
|
||||
if (e.IsHandled)
|
||||
return new(true, e.Result);
|
||||
|
||||
if (HandleCreate(e)
|
||||
if (HandleGet(e)
|
||||
|| HandleDelete(e)
|
||||
|| HandleSave(e)
|
||||
|| HandleAssociation(e))
|
||||
@@ -39,7 +39,7 @@ public class DefaultDataManager : IDataManager
|
||||
return new(success, e.Result);
|
||||
}
|
||||
|
||||
protected virtual bool HandleCreate(OnActionEventArgs e)
|
||||
protected virtual bool HandleGet(OnActionEventArgs e)
|
||||
{
|
||||
if (e.Action != DataManagerActions.Get)
|
||||
return false;
|
||||
@@ -47,42 +47,38 @@ public class DefaultDataManager : IDataManager
|
||||
// Character
|
||||
if (e.Action == DataManagerActions.Getter.Character)
|
||||
{
|
||||
// Get
|
||||
if (e.ActionType == DataManagerActionType.Set)
|
||||
{
|
||||
if (e.Object is not Group group || e.Parameters.Length < 1 || e.Parameters[0] is not string name)
|
||||
return false;
|
||||
e.Result = CreateCharacter(e.CurrentUser, name, group);
|
||||
return e.Result != null;
|
||||
if (e.Object is Group group && e.Parameters.GetAt(0, out string? name))
|
||||
return e.SetResult(CreateCharacter(e.CurrentUser, name, group));
|
||||
}
|
||||
}
|
||||
|
||||
// Group
|
||||
if (e.Action == DataManagerActions.Getter.Group)
|
||||
{
|
||||
// Get
|
||||
if (e.ActionType == DataManagerActionType.Get)
|
||||
{
|
||||
if (e.Parameters.Length < 1 || e.Parameters[0] is not string name)
|
||||
return false;
|
||||
e.Result = CreateGroup(e.CurrentUser, name);
|
||||
return e.Result != null;
|
||||
if (e.Parameters.GetAt(0, out string? name))
|
||||
return e.SetResult(CreateGroup(e.CurrentUser, name));
|
||||
}
|
||||
}
|
||||
|
||||
// User
|
||||
if (e.Action == DataManagerActions.Getter.UserAccount)
|
||||
{
|
||||
// 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)
|
||||
return false;
|
||||
e.Result = CreateUserAccount(username, password);
|
||||
return e.Result != null;
|
||||
if (e.Parameters.GetAt(0, out string? username) && e.Parameters.GetAt(1, out string? password))
|
||||
return e.SetResult(CreateUserAccount(username, password));
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// e.Result = DataProvider.GetUserAccounts();
|
||||
// return e.Result != null;
|
||||
//}
|
||||
|
||||
// Create
|
||||
//else if (e.ActionType == DataManagerActionType.Set(
|
||||
// return e.SetResult(DataProvider.GetUserAccounts());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -130,8 +126,7 @@ public class DefaultDataManager : IDataManager
|
||||
switch (e.ActionType)
|
||||
{
|
||||
case DataManagerActionType.Get:
|
||||
e.Result = DataProvider.GetOwner(group);
|
||||
return true;
|
||||
return e.SetResultT(DataProvider.GetOwner(group));
|
||||
case DataManagerActionType.Set:
|
||||
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
|
||||
return DataProvider.SetOwner(group, profile);
|
||||
@@ -144,8 +139,7 @@ public class DefaultDataManager : IDataManager
|
||||
switch (e.ActionType)
|
||||
{
|
||||
case DataManagerActionType.Get:
|
||||
e.Result = DataProvider.GetOwner(character);
|
||||
return true;
|
||||
return e.SetResultT(DataProvider.GetOwner(character));
|
||||
case DataManagerActionType.Set:
|
||||
if (e.Parameters.Length >= 1 && e.Parameters[0] is UserProfile profile)
|
||||
return DataProvider.SetOwner(character, profile);
|
||||
|
||||
@@ -1,11 +1,36 @@
|
||||
using OwnChar.Model;
|
||||
using OwnChar.Data;
|
||||
using OwnChar.Model;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace OwnChar;
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user