2024-04-16 12:23:29 +03:30
|
|
|
|
using Back.Common.Enums;
|
|
|
|
|
using Back.Data.Contracts;
|
2024-04-14 16:09:36 +03:30
|
|
|
|
using Back.Data.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace Back.Services
|
|
|
|
|
{
|
|
|
|
|
public class ServValidatinMsg
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsyncRepository<VerificationCode> _verificationCodeRepo;
|
2024-04-16 12:23:29 +03:30
|
|
|
|
private readonly IAsyncRepository<Ticket> _ticket;
|
|
|
|
|
public ServValidatinMsg(IAsyncRepository<VerificationCode> verificationCodeRepo, IAsyncRepository<Ticket> ticket)
|
2024-04-14 16:09:36 +03:30
|
|
|
|
{
|
|
|
|
|
_verificationCodeRepo = verificationCodeRepo;
|
2024-04-16 12:23:29 +03:30
|
|
|
|
_ticket = ticket;
|
2024-04-14 16:09:36 +03:30
|
|
|
|
}
|
|
|
|
|
public async Task<VerificationCode> GetCodeByPrm(string Prm)
|
|
|
|
|
{
|
|
|
|
|
return await _verificationCodeRepo.Get(w => w.prm == Prm).FirstOrDefaultAsync();
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-15 17:16:17 +03:30
|
|
|
|
public async Task<VerificationCode> GetVerificationCode(int ID)
|
2024-04-14 16:09:36 +03:30
|
|
|
|
{
|
|
|
|
|
return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync();
|
|
|
|
|
}
|
2024-04-16 12:23:29 +03:30
|
|
|
|
public async Task<bool> SubmittedTicket(VerificationCode code)
|
|
|
|
|
{
|
|
|
|
|
var ticket = await _ticket.Get(w => w.ID == Convert.ToInt32(code.prm)).FirstOrDefaultAsync();
|
|
|
|
|
if (ticket != null)
|
|
|
|
|
{
|
|
|
|
|
ticket.Status = StatusTicket.Awaitingreview;
|
|
|
|
|
return await _ticket.UpdateAsync(ticket);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-04-14 16:09:36 +03:30
|
|
|
|
public async Task<int> GenerateCode(VerificationCode code)
|
|
|
|
|
{
|
2024-04-14 22:19:39 +03:30
|
|
|
|
code.Code = Random.Shared.Next(1000, 9000);
|
2024-04-15 17:16:17 +03:30
|
|
|
|
while (await GetVerificationCode(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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|