Files
moadiran/Back/Controllers/TicketController.cs
mmrbnjd 7b8127dc72 ...
2024-04-29 07:58:41 +03:30

56 lines
2.1 KiB
C#

using Back.Common.Enums;
using Back.Data.Models;
using Back.Services;
using Back.Validations;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using System.Security.Cryptography;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace Back.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class TicketController : ControllerBase
{
private readonly MobileValidation _mobilevalidation;
private readonly servTicket _servTicket;
private readonly ServValidatinMsg _servValidatinMsg;
private readonly servSendMsg _servSendMsg;
public TicketController(MobileValidation mobilevalidation, servTicket servTicket
, ServValidatinMsg servValidatinMsg, servSendMsg servSendMsg)
{
_mobilevalidation = mobilevalidation;
_servTicket = servTicket;
_servValidatinMsg = servValidatinMsg;
_servSendMsg = servSendMsg;
}
[HttpPost("NewTicketNoAuthentication")]
[AllowAnonymous]
public async Task<ActionResult<int>> NewTicketNoAuthentication(CTicketNoAuthenticationDto item)
{
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(item.Mobile,false));
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
var pid=await _servTicket.NewPepole(item.FullName,item.Mobile);
item.CompanyID = pid.Value.ToString();
var Ticket = await _servTicket.NewTicket(item, StatusTicket.unknownPerson);
var ID= await _servValidatinMsg.GenerateCode(new VerificationCode
{
prm = Ticket.ID.ToString(),
val = item.Mobile,
Type = "NewTicketNoAuthentication"
});
_servSendMsg.Authentication(item.Mobile, ID.ToString());
return Ticket == null ? BadRequest() : Ok(ID);
}
}
}