using Back.Data.Contracts; using Back.Data.Models; using Microsoft.EntityFrameworkCore; namespace Back.Services { public class ServValidatinMsg { private readonly IAsyncRepository _verificationCodeRepo; public ServValidatinMsg(IAsyncRepository verificationCodeRepo) { _verificationCodeRepo = verificationCodeRepo; } public async Task GetCodeByPrm(string Prm) { return await _verificationCodeRepo.Get(w => w.prm == Prm).FirstOrDefaultAsync(); } public async Task GetVerificationCode(int ID) { return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync(); } public async Task GenerateCode(VerificationCode code) { code.Code = Random.Shared.Next(1000, 9000); while (await GetVerificationCode(code.ID) != null) code.Code = Random.Shared.Next(1000, 9000); var indb= await _verificationCodeRepo.AddAsync(code); return indb.ID; } } }