1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/izory-ZrAdminNetCore

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
EntityExtension.cs 2.5 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
不做码农 Отправлено 3 лет назад acc10fd
using Microsoft.AspNetCore.Http;
using Snowflake.Core;
using System;
namespace ZR.Admin.WebApi.Extensions
{
public static class EntityExtension
{
public static TSource ToCreate<TSource>(this TSource source, HttpContext context = null)
{
var types = source.GetType();
//var worker = new IdWorker(1, 1);
//if (types.GetProperty("ID") != null)
//{
// long id = worker.NextId();
// types.GetProperty("ID").SetValue(source, id.ToString(), null);
//}
if (types.GetProperty("CreateTime") != null)
{
types.GetProperty("CreateTime").SetValue(source, DateTime.Now, null);
}
if (types.GetProperty("AddTime") != null)
{
types.GetProperty("AddTime").SetValue(source, DateTime.Now, null);
}
if (types.GetProperty("UpdateTime") != null)
{
types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null);
}
if (types.GetProperty("Create_by") != null && context != null)
{
types.GetProperty("Create_by").SetValue(source, context.GetName(), null);
}
if (types.GetProperty("UserId") != null && context != null)
{
types.GetProperty("UserId").SetValue(source, context.GetUId(), null);
}
return source;
}
public static TSource ToUpdate<TSource>(this TSource source, HttpContext context = null)
{
var types = source.GetType();
if (types.GetProperty("UpdateTime") != null)
{
types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null);
}
if (types.GetProperty("Update_time") != null)
{
types.GetProperty("Update_time").SetValue(source, DateTime.Now, null);
}
//if (types.GetProperty("UpdateID") != null)
//{
// types.GetProperty("UpdateID").SetValue(source, userSession.UserID, null);
//}
if (types.GetProperty("UpdateBy") != null)
{
types.GetProperty("UpdateBy").SetValue(source,context.GetName(), null);
}
if (types.GetProperty("Update_by") != null)
{
types.GetProperty("Update_by").SetValue(source, context.GetName(), null);
}
return source;
}
}
}

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/izory-ZrAdminNetCore.git
git@gitlife.ru:oschina-mirror/izory-ZrAdminNetCore.git
oschina-mirror
izory-ZrAdminNetCore
izory-ZrAdminNetCore
v3.7.8