V 0.0.1 添加软件的基础配置
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using LMS.Common.Enum;
|
||||
using Newtonsoft.Json;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace LMS.Repository.DB;
|
||||
|
||||
public class Options
|
||||
{
|
||||
[Key]
|
||||
public required string Key { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Value of the option,这个值是一个json字符串
|
||||
/// </summary>
|
||||
public string? Value { get; set; } = string.Empty;
|
||||
|
||||
public OptionTypeEnum Type { get; set; } = OptionTypeEnum.String;
|
||||
|
||||
// 写一个字段,映射Value,判断是不是json字符串,是的话就解析成对象
|
||||
[NotMapped]
|
||||
public object? ValueObject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(Value))
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
if (Type == OptionTypeEnum.JSON)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(Value ?? "{}");
|
||||
}
|
||||
|
||||
if (Type == OptionTypeEnum.Number)
|
||||
{
|
||||
return Convert.ToDouble(Value);
|
||||
}
|
||||
|
||||
return Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
Value = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Type == OptionTypeEnum.JSON)
|
||||
{
|
||||
Value = JsonConvert.SerializeObject(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Value = value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using LMS.Common.Enum;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LMS.Repository.DTO;
|
||||
|
||||
public class OptionsDto
|
||||
{
|
||||
public required string Key { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Value of the option,这个值是一个json字符串
|
||||
/// </summary>
|
||||
public string? Value { get; set; }
|
||||
|
||||
public OptionTypeEnum Type { get; set; } = OptionTypeEnum.String;
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.8" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LMS.Repository.Options;
|
||||
|
||||
public class ModofyOptionsModel
|
||||
{
|
||||
[Required]
|
||||
public required string Key { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Value { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user