...
This commit is contained in:
35
Back/Services/ServValidatinMsg.cs
Normal file
35
Back/Services/ServValidatinMsg.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user