2024-04-15 17:16:17 +03:30
using Back.Data.Models ;
using Back.Services ;
using Back.Validations ;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Mvc ;
using Shared.DTOs ;
2024-04-17 15:49:34 +03:30
using static Microsoft . EntityFrameworkCore . DbLoggerCategory . Database ;
2024-04-15 17:16:17 +03:30
namespace Back.Controllers
{
[Route("api/[controller] ")]
[ApiController]
public class VerificationController : ControllerBase
{
2024-04-16 12:23:29 +03:30
private readonly ServValidatinMsg _servValidatinMsg ;
2024-04-15 17:16:17 +03:30
private readonly GetVerificationValidation _getVerificationValidation ;
2024-04-17 15:49:34 +03:30
private readonly servSendMsg _servSendMsg ;
private readonly servCompany _servCompany ;
2024-04-29 07:58:41 +03:30
private readonly servUser _servUser ;
2024-04-17 15:49:34 +03:30
public VerificationController ( ServValidatinMsg servValidatinMsg , GetVerificationValidation getVerificationValidation
2024-04-29 07:58:41 +03:30
, servCompany servCompany , servSendMsg servSendMsg , servUser servUser )
2024-04-15 17:16:17 +03:30
{
2024-04-16 12:23:29 +03:30
_servValidatinMsg = servValidatinMsg ;
2024-04-15 17:16:17 +03:30
_getVerificationValidation = getVerificationValidation ;
2024-04-17 15:49:34 +03:30
_servCompany = servCompany ;
2024-04-19 03:23:30 +03:30
_servSendMsg = servSendMsg ;
2024-04-29 07:58:41 +03:30
_servUser = servUser ;
2024-04-15 17:16:17 +03:30
}
[HttpGet("GetVerification/{ID}")]
2024-06-24 11:48:53 +03:30
2024-04-15 17:16:17 +03:30
public async Task < ActionResult < VerificationCode > > GetVerification ( int ID )
{
var resultValidationmodel = await _getVerificationValidation . ValidateAsync ( ID ) ;
if ( ! resultValidationmodel . IsValid )
return BadRequest ( resultValidationmodel . Errors . Select ( s = > s . ErrorMessage ) . ToList ( ) ) ;
return Ok ( new VerificationCodeDto {
2024-04-15 23:09:11 +03:30
ID = ID ,
2024-04-15 23:31:24 +03:30
Code = 0 ,
2024-04-15 17:16:17 +03:30
prm = _getVerificationValidation . verificationCode . prm ,
Type = _getVerificationValidation . verificationCode . Type ,
val = _getVerificationValidation . verificationCode . val
2024-04-15 23:09:11 +03:30
} ) ; ;
}
2024-04-16 22:56:02 +03:30
[HttpGet("ReSend/{ID}")]
2024-06-24 11:48:53 +03:30
2024-04-16 22:56:02 +03:30
public async Task < ActionResult > ReSend ( int ID )
{
var resultValidationmodel = await _getVerificationValidation . ValidateAsync ( ID ) ;
if ( ! resultValidationmodel . IsValid )
return BadRequest ( resultValidationmodel . Errors . Select ( s = > s . ErrorMessage ) . ToList ( ) ) ;
// _getVerificationValidation.verificationCode
2024-04-17 15:49:34 +03:30
switch ( _getVerificationValidation . verificationCode . Type )
{
case "NewTicketNoAuthentication" :
2024-06-24 11:48:53 +03:30
_servSendMsg . toContinue ( _getVerificationValidation . verificationCode . Code . ToString ( ) , _getVerificationValidation . verificationCode . val , "ثبت نظر" ) ;
2024-04-17 15:49:34 +03:30
break ;
case "CompanyRegistration" :
var company = await _servCompany . GetCompanyOrg ( Convert . ToInt32 ( _getVerificationValidation . verificationCode . prm ) , false ) ;
2024-06-24 11:48:53 +03:30
_servSendMsg . toContinue ( _getVerificationValidation . verificationCode . Code . ToString ( ) , company . Mobile , "ثبت نام" ) ;
2024-04-17 15:49:34 +03:30
break ;
2024-04-29 07:58:41 +03:30
case "ForgetPassword" :
2024-06-24 11:48:53 +03:30
// var user = await _servUser.ChangePasswordByMobile(_getVerificationValidation.verificationCode.prm, _getVerificationValidation.verificationCode.val);
_servSendMsg . toContinue ( _getVerificationValidation . verificationCode . Code . ToString ( ) , _getVerificationValidation . verificationCode . prm , "فراموشی کلمه عبور" ) ;
2024-04-29 07:58:41 +03:30
break ;
2024-04-29 18:15:46 +03:30
case "ChangeUserName" :
2024-06-24 11:48:53 +03:30
_servSendMsg . toContinue ( _getVerificationValidation . verificationCode . Code . ToString ( ) , _getVerificationValidation . verificationCode . val , "تغییر نام کاربری" ) ;
2024-04-29 18:15:46 +03:30
break ;
2024-04-17 15:49:34 +03:30
default :
2024-04-29 18:15:46 +03:30
return BadRequest ( new List < string > { "این نوع احراز تعریف نشده" } ) ;
2024-04-17 15:49:34 +03:30
}
2024-04-16 22:56:02 +03:30
return NoContent ( ) ;
}
2024-04-15 23:09:11 +03:30
[HttpPost("Submit")]
2024-06-24 11:48:53 +03:30
2024-04-15 23:09:11 +03:30
public async Task < ActionResult < bool > > Submit ( VerificationCodeDto item )
{
2024-04-29 18:15:46 +03:30
var VerificationCode = await _servValidatinMsg . GetVerificationCodeByID ( item . ID ) ;
2024-04-16 12:23:29 +03:30
if ( VerificationCode = = null )
return NotFound ( "آیتمی یافت نشد" ) ;
if ( VerificationCode . Code = = item . Code )
{
if ( VerificationCode . prm = = item . prm & & VerificationCode . val = = item . val & & VerificationCode . Type = = item . Type )
{
2024-04-16 22:56:02 +03:30
bool Sucstatus = false ;
2024-04-16 12:23:29 +03:30
switch ( VerificationCode . Type )
{
case "NewTicketNoAuthentication" :
2024-04-16 22:56:02 +03:30
Sucstatus = await _servValidatinMsg . SubmittedTicket ( VerificationCode ) ;
2024-10-14 15:56:45 +03:30
if ( Sucstatus ) _servSendMsg . SuccessfulSubmitTicket ( VerificationCode . val , VerificationCode . prm ) ;
2024-04-16 22:56:02 +03:30
break ;
2024-04-17 15:49:34 +03:30
case "CompanyRegistration" :
//string UserID = VerificationCode.val;
Sucstatus = await _servValidatinMsg . SubmittedCompanyRegistration ( VerificationCode ) ;
// return Ok(await _servUser.UserAuthentication(UserID));
//else return BadRequest();
break ;
2024-06-24 11:48:53 +03:30
case "ForgetPassword" :
Sucstatus = await _servUser . ChangePasswordByMobile ( VerificationCode . prm , VerificationCode . val ) ;
break ;
2024-04-29 18:15:46 +03:30
case "ChangeUserName" :
Sucstatus = await _servUser . ChangeUserName ( VerificationCode . val , Convert . ToInt32 ( VerificationCode . prm ) ) ;
break ;
2024-04-16 12:23:29 +03:30
default :
2024-04-29 18:15:46 +03:30
return BadRequest ( new List < string > { "این نوع احراز تعریف نشده" } ) ;
2024-04-16 12:23:29 +03:30
}
2024-04-17 15:49:34 +03:30
2024-04-16 22:56:02 +03:30
if ( Sucstatus )
await _servValidatinMsg . Delete ( VerificationCode ) ;
2024-04-17 15:49:34 +03:30
2024-04-16 22:56:02 +03:30
return Ok ( Sucstatus ) ;
2024-04-16 12:23:29 +03:30
}
2024-04-29 18:15:46 +03:30
else return BadRequest ( new List < string > { "اطلاعات شما منطبق با سامانه نیست" } ) ;
2024-04-16 12:23:29 +03:30
}
2024-04-29 18:15:46 +03:30
else return BadRequest ( new List < string > { "کد احراز صحیح نمی باشد" } ) ;
2024-04-16 12:23:29 +03:30
2024-04-15 17:16:17 +03:30
}
2024-04-16 22:56:02 +03:30
[HttpDelete("Remove/{ID}")]
2024-06-24 11:48:53 +03:30
2024-04-16 22:56:02 +03:30
public async Task < ActionResult < bool > > Remove ( int ID )
{
2024-04-29 18:15:46 +03:30
var VerificationCode = await _servValidatinMsg . GetVerificationCodeByID ( ID ) ;
2024-04-16 22:56:02 +03:30
await _servValidatinMsg . Delete ( VerificationCode ) ;
return NoContent ( ) ;
}
2024-04-15 17:16:17 +03:30
}
}