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, IUsersRepository { private readonly BRDbContext context; public UsersRepository(BRDbContext context) : base(context) { this.context = context; } public async Task> GetAllByFilter(UsersFilter queryObj) { var result = new PagedCollection(); 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>>() { ["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); } } }