| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System.Linq.Expressions;
- using BlackRock.Reporting.API.Core.Interfaces;
- using BlackRock.Reporting.API.Core.Extensions;
- using BlackRock.Reporting.API.Core.Models;
- using Microsoft.EntityFrameworkCore;
-
- namespace BlackRock.Reporting.API.Persistence.Repositories
- {
- public class UsersRepository : EFRepository<User>, IUsersRepository
- {
- private readonly BRDbContext context;
- public UsersRepository(BRDbContext context) : base(context)
- {
- this.context = context;
- }
- public async Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj)
- {
- var result = new PagedCollection<User>();
-
- var queryResult = await context.Users.ToListAsync();
- var query = queryResult.AsQueryable();
-
- // filtering
- if (!string.IsNullOrWhiteSpace(queryObj.EmailDomain))
- query = query.Where(q => q.Email.EndsWith(queryObj.EmailDomain.ToLower()));
-
- // sorting
- var columnsMap = new Dictionary<string, Expression<Func<User, object>>>()
- {
- ["name"] = u => u.Name,
- ["email"] = u => u.Email
- };
-
- query = query.ApplyOrdering(queryObj, columnsMap).ApplyPagging(queryObj);
-
- // pagging
- // query = query.ApplyPagging(queryObj);
-
- foreach (var item in query)
- {
- result.Add(item);
- }
- return result;
-
- }
- public void UpdateEmail(User user, string email)
- {
- user.Email = email;
- this.Update(user);
- }
- }
- }
|