123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Linq.Expressions;
- using Luticate2.Auth.DataAccess.Models;
- using Luticate2.Auth.Dbo.Tokens;
- using Luticate2.Utils.DataAccess;
- using Luticate2.Utils.Dbo.Filter;
- using Luticate2.Utils.Utils;
- using Microsoft.EntityFrameworkCore;
- using Newtonsoft.Json;
-
- namespace Luticate2.Auth.DataAccess
- {
- public class LuTokensDataAccess : LuEfCrudDataAccess<lu_tokens, LuTokensAddDbo, LuTokensDbo, LuTokensEditDbo, LuAuthDatabaseContext, string>
- {
- public LuTokensDataAccess(IServiceProvider serviceProvider) : base(serviceProvider)
- {
- }
-
- protected override object GetId(string id)
- {
- return id;
- }
-
- protected override DbSet<lu_tokens> GetTable(LuAuthDatabaseContext db)
- {
- return db.lu_tokens;
- }
-
- protected override Expression<Func<lu_tokens, bool>> GetFilterExpression(LuFilterDbo filter)
- {
- var userId = filter.GetFilterString("userId", null);
- return tokens => (userId == null || tokens.user_id.ToString() == userId);
- }
-
- protected override lu_tokens GetModelFromTCreate(LuTokensAddDbo obj)
- {
- return new lu_tokens
- {
- data = JsonConvert.SerializeObject(obj.Data),
- id = obj.Id,
- notAfter = obj.NotAfter,
- notBefore = obj.NotBefore,
- user_id = obj.UserId.ToGuid()
- };
- }
-
- protected override void EditModelFromTUpdate(LuTokensEditDbo obj, lu_tokens model)
- {
- throw new NotImplementedException();
- }
-
- protected override LuTokensDbo GetDboFromModel(lu_tokens model)
- {
- return model.ToDbo();
- }
- }
- }
|