Files
moadiran/Back/Services/ServValidatinMsg.cs

85 lines
3.3 KiB
C#
Raw Normal View History

2024-05-01 15:42:21 +03:30
using Shared.DTOs;
2024-04-16 12:23:29 +03:30
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;
2024-04-17 15:49:34 +03:30
private readonly IAsyncRepository<User> _UserRepo;
private readonly IAsyncRepository<Company> _CompanyRepo;
private readonly servSendMsg _servSendMsg;
public ServValidatinMsg(IAsyncRepository<VerificationCode> verificationCodeRepo
, IAsyncRepository<Ticket> ticket, IAsyncRepository<User> UserRepo
, IAsyncRepository<Company> CompanyRepo, servSendMsg servSendMsg)
2024-04-14 16:09:36 +03:30
{
_verificationCodeRepo = verificationCodeRepo;
2024-04-16 12:23:29 +03:30
_ticket = ticket;
2024-04-17 15:49:34 +03:30
_UserRepo = UserRepo;
_CompanyRepo = CompanyRepo;
_servSendMsg = servSendMsg;
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-29 18:15:46 +03:30
{
return await _verificationCodeRepo.Get(w => w.Code == ID).FirstOrDefaultAsync();
}
public async Task<VerificationCode> GetVerificationCodeByID(int ID)
2024-04-14 16:09:36 +03:30
{
return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync();
}
2024-04-16 22:56:02 +03:30
public async Task<bool> Delete(VerificationCode model)
{
return await _verificationCodeRepo.DeleteAsync(model);
}
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();
2024-04-16 22:56:02 +03:30
if (ticket != null && ticket.Status== StatusTicket.unknownPerson)
2024-04-16 12:23:29 +03:30
{
ticket.Status = StatusTicket.Awaitingreview;
return await _ticket.UpdateAsync(ticket);
}
return false;
}
2024-04-17 15:49:34 +03:30
public async Task<bool> SubmittedCompanyRegistration(VerificationCode code)
{
var user = await _UserRepo.Get(w => w.ID == Convert.ToInt32(code.val) && !w.IsActive).FirstOrDefaultAsync();
var company = await _CompanyRepo.Get(w => w.ID == Convert.ToInt32(code.prm) && !w.IsActive).FirstOrDefaultAsync();
if (user != null && company != null)
{
user.IsActive = true;
if (await _UserRepo.UpdateAsync(user) != null)
{
company.IsActive = true;
if (await _CompanyRepo.UpdateAsync(company))
{
_servSendMsg.SuccessfulRegistration(user.Mobile, $"{user.Mobile};{user.Mobile}");
return true;
}
}
}
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-29 18:15:46 +03:30
while (await GetVerificationCode(code.Code) != 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
}
}
}