You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UsersRepository.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Linq.Expressions;
  2. using BlackRock.Reporting.API.Core.Interfaces;
  3. using BlackRock.Reporting.API.Core.Extensions;
  4. using BlackRock.Reporting.API.Core.Models;
  5. using Microsoft.EntityFrameworkCore;
  6. namespace BlackRock.Reporting.API.Persistence.Repositories
  7. {
  8. public class UsersRepository : EFRepository<User>, IUsersRepository
  9. {
  10. private readonly BRDbContext context;
  11. public UsersRepository(BRDbContext context) : base(context)
  12. {
  13. this.context = context;
  14. }
  15. public async Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj)
  16. {
  17. var result = new PagedCollection<User>();
  18. var queryResult = await context.Users.ToListAsync();
  19. var query = queryResult.AsQueryable();
  20. // filtering
  21. if (!string.IsNullOrWhiteSpace(queryObj.EmailDomain))
  22. query = query.Where(q => q.Email.EndsWith(queryObj.EmailDomain.ToLower()));
  23. // sorting
  24. var columnsMap = new Dictionary<string, Expression<Func<User, object>>>()
  25. {
  26. ["name"] = u => u.Name,
  27. ["email"] = u => u.Email
  28. };
  29. query = query.ApplyOrdering(queryObj, columnsMap).ApplyPagging(queryObj);
  30. // pagging
  31. // query = query.ApplyPagging(queryObj);
  32. foreach (var item in query)
  33. {
  34. result.Add(item);
  35. }
  36. return result;
  37. }
  38. public void UpdateEmail(User user, string email)
  39. {
  40. user.Email = email;
  41. this.Update(user);
  42. }
  43. }
  44. }