LoginOTPRepository.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Microsoft.AspNetCore.Identity;
  2. using Microsoft.EntityFrameworkCore;
  3. using MTWorkHR.Core.Entities;
  4. using MTWorkHR.Core.IRepositories;
  5. using MTWorkHR.Infrastructure.DBContext;
  6. using Org.BouncyCastle.Math.EC.Rfc7748;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Linq.Dynamic.Core;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace MTWorkHR.Infrastructure.Repositories
  14. {
  15. public class LoginOTPRepository : Repository<LoginOTP>, ILoginOTPRepository
  16. {
  17. private readonly DbSet<LoginOTP> dbSet;
  18. public LoginOTPRepository(HRDataContext context) : base(context)
  19. {
  20. dbSet = context.Set<LoginOTP>();
  21. }
  22. public async Task<bool> VerifyOTP(string userId, string oTP)
  23. {
  24. bool result = false;
  25. var loginOTP = await dbSet.AsQueryable().OrderByDescending(x => x.CreateDate).FirstOrDefaultAsync(x => x.UserId == userId && x.ExpireDate >= DateTime.Now);
  26. if (loginOTP.OTP == oTP)
  27. result = true;
  28. return result;
  29. }
  30. public async Task<string> LastOpt()
  31. {
  32. var res= await dbSet.OrderByDescending(x=>x.CreateDate).FirstOrDefaultAsync();
  33. return res.OTP;
  34. }
  35. }
  36. }