功能完善
This commit is contained in:
@@ -82,7 +82,7 @@ namespace Ewide.Core.Service
|
||||
/// <param name="input"></param>
|
||||
/// <remarks>默认用户名/密码:admin/admin</remarks>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/login")]
|
||||
[HttpPost("/gb/yjb/login")]
|
||||
[AllowAnonymous]
|
||||
[Op(LogOpType.GRANT)]
|
||||
public async Task<LoginOutput> LoginAsync([Required] LoginInput input)
|
||||
|
||||
58
20220330_Vote/Ewide.Core/Util/DEntityExtensions.cs
Normal file
58
20220330_Vote/Ewide.Core/Util/DEntityExtensions.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.LinqBuilder;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Util
|
||||
{
|
||||
public static class DEntityExtensions
|
||||
{
|
||||
public async static Task<TEntity> InsertOrUpdate<TEntity>(this TEntity entity) where TEntity : DEntityBase, IPrivateEntity, new()
|
||||
{
|
||||
if (entity.Id.IsNullOrEmpty())
|
||||
await entity.SetInsertDefaultValue().InsertAsync();
|
||||
else
|
||||
await entity.SetUpdateDefaultValue().UpdateExcludeAsync(new[] { nameof(entity.CreatedTime), nameof(entity.CreatedUserId), nameof(entity.CreatedUserName) });
|
||||
return entity;
|
||||
}
|
||||
public async static Task<TEntity> InsertOrUpdate<TEntity>(this TEntity entity, bool isInsert) where TEntity : DEntityBase, IPrivateEntity, new()
|
||||
{
|
||||
if (isInsert)
|
||||
await entity.SetInsertDefaultValue().InsertAsync();
|
||||
else
|
||||
await entity.SetUpdateDefaultValue().UpdateAsync();
|
||||
return entity;
|
||||
}
|
||||
public static TEntity SetInsertDefaultValue<TEntity>(this TEntity entity) where TEntity : DEntityBase
|
||||
{
|
||||
if (string.IsNullOrEmpty(entity.Id))
|
||||
entity.Id = Guid.NewGuid().ToString();
|
||||
if (!entity.CreatedTime.HasValue)
|
||||
entity.CreatedTime = DateTime.Now;
|
||||
//if (string.IsNullOrEmpty(entity.CreatedUserId))
|
||||
entity.CreatedUserId = GetUserId();
|
||||
if (string.IsNullOrEmpty(entity.CreatedUserName))
|
||||
entity.CreatedUserName = App.GetService<UserManager>().Name;
|
||||
return entity;
|
||||
}
|
||||
public static TEntity SetUpdateDefaultValue<TEntity>(this TEntity entity) where TEntity : DEntityBase
|
||||
{
|
||||
entity.UpdatedTime = DateTime.Now;
|
||||
entity.UpdatedUserId = GetUserId();
|
||||
entity.UpdatedUserName = App.GetService<UserManager>().Name;
|
||||
return entity;
|
||||
}
|
||||
private static string GetUserId()
|
||||
{
|
||||
var userid = App.GetService<UserManager>().UserId;
|
||||
//if (string.IsNullOrWhiteSpace(userid))
|
||||
// userid = App.GetService<UserManager>().WorkUSERID;
|
||||
return userid;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user