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)
|
|
|
|
|
{
|
2024-04-14 22:19:39 +03:30
|
|
|
|
code.Code = Random.Shared.Next(1000, 9000);
|
2024-04-14 16:09:36 +03:30
|
|
|
|
while (await GetRegistrationCode(code.ID) != null)
|
2024-04-14 22:19:39 +03:30
|
|
|
|
code.Code = Random.Shared.Next(1000, 9000);
|
2024-04-14 16:09:36 +03:30
|
|
|
|
|
|
|
|
|
|
2024-04-14 22:19:39 +03:30
|
|
|
|
var indb= await _verificationCodeRepo.AddAsync(code);
|
2024-04-14 16:09:36 +03:30
|
|
|
|
|
2024-04-14 22:19:39 +03:30
|
|
|
|
return indb.ID;
|
2024-04-14 16:09:36 +03:30
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|