public async Task <OdissUser> FindByNameAsync(string userName)
 {
     using (var db = new MainDatabase().Get)
     {
         return(await db.QueryFirstOrDefaultAsync <OdissUser>("SELECT * FROM [dbo].[Users] WHERE UserName = @userName", new { userName }));
     }
 }
 public async Task <OdissUser> FindByIdAsync(Guid userId)
 {
     using (var db = new MainDatabase().Get)
     {
         return(await db.QueryFirstOrDefaultAsync <OdissUser>("SELECT * FROM [dbo].[Users] WHERE ID = @userId", new { userId }));
     }
 }
 public async Task <OdissUser> FindByEmailAsync(string email)
 {
     using (var db = new MainDatabase().Get)
     {
         return(await db.QueryFirstOrDefaultAsync <OdissUser>("SELECT * FROM [dbo].[Users] WHERE Email = @email", new { email }));
     }
 }
Esempio n. 4
0
        public async Task <UserSession <Guid, Guid> > GetByUserIdAsync(Guid userId)
        {
            using (var db = new MainDatabase().Get)
            {
                return(await db.QueryFirstOrDefaultAsync <UserSession <Guid, Guid> >(@"
SELECT TOP 1 ID AS SessionId, IDUser AS UserId, Expire AS ExpiryDate, Data, Created AS CreatedAt, LastAction AS LastActionAt 
FROM [dbo].[Sessions] 
WHERE IDUser = @userId 
ORDER BY LastAction DESC", new { userId }));
            }
        }
Esempio n. 5
0
        public async Task <bool> RemoveByUserIdAsync(Guid userId)
        {
            using (var db = new MainDatabase().Get)
            {
                var deletedId = await db.QueryFirstOrDefaultAsync <Guid>(@"
DELETE FROM [dbo].[Sessions] 
OUTPUT DELETED.IDUser
WHERE IDUser = @userId", new { userId });

                return(deletedId == userId);
            }
        }
Esempio n. 6
0
        public async Task <bool> UpdateAsync(UserSession <Guid, Guid> session)
        {
            using (var db = new MainDatabase().Get)
            {
                var updatedId = await db.QueryFirstOrDefaultAsync <Guid>(@"
UPDATE [dbo].[Sessions] 
SET Expire = @ExpiryDate, 
Data = @Data, 
LastAction = @LastActionAt
OUTPUT INSERTED.ID
WHERE ID = @SessionId", session);

                return(updatedId == session.SessionId);
            }
        }