-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from GeeseCorp/61--migrate-from-ef-core-to-dapper
Fully replaced EF UserManager with Dapper UserProvider.
- Loading branch information
Showing
30 changed files
with
322 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
using Geesemon.DataAccess.Providers.UserProvider; | ||
using Geesemon.Model.Enums; | ||
using Geesemon.Model.Models; | ||
|
||
namespace Geesemon.DataAccess.Managers | ||
namespace Geesemon.DataAccess.Managers | ||
{ | ||
public class UserManager : UserProvider, IManager<User> | ||
{ | ||
public UserManager(AppDbContext appContext) | ||
: base(appContext) | ||
{ } | ||
} | ||
//public class UserManager : UserProvider, IManager<User> | ||
//{ | ||
// public UserManager(AppDbContext appContext) | ||
// : base(appContext) | ||
// { } | ||
//} | ||
} |
114 changes: 57 additions & 57 deletions
114
Geesemon.DataAccess/Providers/UserProvider/UserProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,67 @@ | ||
using Geesemon.Model.Models; | ||
//using Geesemon.Model.Models; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
//using Microsoft.EntityFrameworkCore; | ||
|
||
using System.Linq.Expressions; | ||
//using System.Linq.Expressions; | ||
|
||
namespace Geesemon.DataAccess.Providers.UserProvider | ||
{ | ||
public class UserProvider : ProviderBase<User> | ||
{ | ||
//namespace Geesemon.DataAccess.Providers.UserProvider | ||
//{ | ||
// public class UserProvider : ProviderBase<User> | ||
// { | ||
|
||
public UserProvider(AppDbContext appDbContext) | ||
: base(appDbContext) | ||
{ | ||
} | ||
// public UserProvider(AppDbContext appDbContext) | ||
// : base(appDbContext) | ||
// { | ||
// } | ||
|
||
public Task<List<User>> GetReadByAsync(Guid messageId, int skip, int take) | ||
{ | ||
return context.ReadMessages | ||
.Include(rm => rm.ReadBy) | ||
.Where(rm => rm.MessageId == messageId) | ||
.OrderByDescending(rm => rm.CreatedAt) | ||
.Skip(skip) | ||
.Take(take) | ||
.Select(rm => rm.ReadBy) | ||
.ToListAsync(); | ||
} | ||
// public Task<List<User>> GetReadByAsync(Guid messageId, int skip, int take) | ||
// { | ||
// return context.ReadMessages | ||
// .Include(rm => rm.ReadBy) | ||
// .Where(rm => rm.MessageId == messageId) | ||
// .OrderByDescending(rm => rm.CreatedAt) | ||
// .Skip(skip) | ||
// .Take(take) | ||
// .Select(rm => rm.ReadBy) | ||
// .ToListAsync(); | ||
// } | ||
|
||
public Task<int> GetReadByCountByAsync(Guid messageId) | ||
{ | ||
return context.ReadMessages | ||
.CountAsync(rm => rm.MessageId == messageId); | ||
} | ||
// public Task<int> GetReadByCountByAsync(Guid messageId) | ||
// { | ||
// return context.ReadMessages | ||
// .CountAsync(rm => rm.MessageId == messageId); | ||
// } | ||
|
||
public virtual Task<User?> GetByIdentifierAsync(string identifier, params Expression<Func<User, object>>[] includes) | ||
{ | ||
return includes.Aggregate(context.Users.AsQueryable(), | ||
(current, include) => current.Include(include)) | ||
.FirstOrDefaultAsync(e => e.Identifier == identifier); | ||
} | ||
// public virtual Task<User?> GetByIdentifierAsync(string identifier, params Expression<Func<User, object>>[] includes) | ||
// { | ||
// return includes.Aggregate(context.Users.AsQueryable(), | ||
// (current, include) => current.Include(include)) | ||
// .FirstOrDefaultAsync(e => e.Identifier == identifier); | ||
// } | ||
|
||
public virtual Task<User?> GetByEmailAsync(string email, params Expression<Func<User, object>>[] includes) | ||
{ | ||
return includes.Aggregate(context.Users.AsQueryable(), | ||
(current, include) => current.Include(include)) | ||
.FirstOrDefaultAsync(e => e.Email == email); | ||
} | ||
// public virtual Task<User?> GetByEmailAsync(string email, params Expression<Func<User, object>>[] includes) | ||
// { | ||
// return includes.Aggregate(context.Users.AsQueryable(), | ||
// (current, include) => current.Include(include)) | ||
// .FirstOrDefaultAsync(e => e.Email == email); | ||
// } | ||
|
||
public Task<List<User>> GetAsync(Guid chatId) | ||
{ | ||
return context.Users.Include(c => c.UserChats) | ||
.Where(c => c.UserChats.Any(uc => uc.ChatId == chatId)) | ||
.ToListAsync(); | ||
} | ||
// public Task<List<User>> GetAsync(Guid chatId) | ||
// { | ||
// return context.Users.Include(c => c.UserChats) | ||
// .Where(c => c.UserChats.Any(uc => uc.ChatId == chatId)) | ||
// .ToListAsync(); | ||
// } | ||
|
||
public Task<List<User>> GetAsync(int take, int skip, string q, Guid? currentUserId = null) | ||
{ | ||
return context.Users | ||
.Where(u => (u.Identifier.Contains(q) || (u.Email != null && u.Email.Contains(q))) && u.Id != currentUserId) | ||
.OrderBy(u => u.FirstName) | ||
.ThenBy(u => u.LastName) | ||
.Skip(skip) | ||
.Take(take) | ||
.ToListAsync(); | ||
} | ||
} | ||
} | ||
// public Task<List<User>> GetAsync(int take, int skip, string q, Guid? currentUserId = null) | ||
// { | ||
// return context.Users | ||
// .Where(u => (u.Identifier.Contains(q) || (u.Email != null && u.Email.Contains(q))) && u.Id != currentUserId) | ||
// .OrderBy(u => u.FirstName) | ||
// .ThenBy(u => u.LastName) | ||
// .Skip(skip) | ||
// .Take(take) | ||
// .ToListAsync(); | ||
// } | ||
// } | ||
//} |
Oops, something went wrong.