1、在data裡面新建個Entity文件用於存放表映射,設計資料庫,執行如下語句 Scaffold-DbContext -Force "server=.;user=sunyong;password=1qaz!QAZ;database=hr;" Microsoft.EntityFrameworkCor ...
1、在data裡面新建個Entity文件用於存放表映射,設計資料庫,執行如下語句
Scaffold-DbContext -Force "server=.;user=sunyong;password=1qaz!QAZ;database=hr;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir /Entity
將在Entity文件下麵自動創建實體,可直接使用
創建個郵件類用於接收配置的郵件信息
public class email
{
public string token { get; set; }
public string sendname { get; set; }
public string sendmail { get; set; }
public string acceptmail { get; set; }
}
public class user
{
[Key]
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Nickname { get; set; }
public string Phone { get; set; }
public string Wchart { get; set; }
public string Email { get; set; }
public string Description { get; set; }
public int Createuser { get; set; }
public DateTime? Createtime { get; set; }
public int? Updateuser { get; set; }
public DateTime? Updatetime { get; set; }
public string State { get; set; }
}
(實體類太多,最後會放到git上面)
2、在service創建CurrrentUser/CurrentUsers類,簡單記錄登錄著信息
public class CurrentUsers
{
private static IHttpContextAccessor _httpContextAccessor;
private static ISession _session => _httpContextAccessor.HttpContext.Session;
public static void Configure(IHttpContextAccessor httpContextAccessor) {
_httpContextAccessor = httpContextAccessor;
}
/// <summary>
///用戶編號
/// </summary>
public static int UserId { get; set; }
/// <summary>
///用戶名
/// </summary>
public static string UserName { get; set; }
}
3、在service下新增Filters文件夾,Filters下麵創建AdminOnlyFilter,MustLoginFilter類
public class AdminOnlyFilter : IPageFilter, IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context) { }
public void OnActionExecuting(ActionExecutingContext context) { }
public void OnPageHandlerExecuted(PageHandlerExecutedContext context) { }
public void OnPageHandlerExecuting(PageHandlerExecutingContext context) { }
public void OnPageHandlerSelected(PageHandlerSelectedContext context) { }
}
public class MustLoginFilter : IPageFilter, IActionFilter
{
public void OnActionExecuted(ActionExecutedContext context) { }
public void OnActionExecuting(ActionExecutingContext context) { }
public void OnPageHandlerExecuted(PageHandlerExecutedContext context) { }
public void OnPageHandlerExecuting(PageHandlerExecutingContext context) { }
public void OnPageHandlerSelected(PageHandlerSelectedContext context) { }
}