Files
moadiran/Back/Services/ServValidatinMsg.cs

36 lines
1.1 KiB
C#
Raw Normal View History

2024-04-14 16:09:36 +03:30
using Back.Data.Contracts;
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;
namespace Back.Services
{
public class ServValidatinMsg
{
private readonly IAsyncRepository<VerificationCode> _verificationCodeRepo;
public ServValidatinMsg(IAsyncRepository<VerificationCode> verificationCodeRepo)
{
_verificationCodeRepo = verificationCodeRepo;
}
public async Task<VerificationCode> GetCodeByPrm(string Prm)
{
return await _verificationCodeRepo.Get(w => w.prm == Prm).FirstOrDefaultAsync();
}
public async Task<VerificationCode> GetRegistrationCode(int ID)
{
return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync();
}
public async Task<int> GenerateCode(VerificationCode code)
{
code.ID = Random.Shared.Next(1000, 9000);
while (await GetRegistrationCode(code.ID) != null)
code.ID = Random.Shared.Next(1000, 9000);
await _verificationCodeRepo.AddAsync(code);
return code.ID;
}
}
}