From f7e3f3b02a66d2466e18008a015d0aaf26e2dc30 Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sun, 14 Apr 2024 16:09:36 +0330 Subject: [PATCH] ... --- Back/Controllers/TicketController.cs | 35 +++++++- Back/Program.cs | 2 + Back/Services/ServValidatinMsg.cs | 35 ++++++++ Back/Services/servTicket.cs | 104 ++++++++++++++++++++++ Shared/DTOs/CTicketDto.cs | 2 +- Shared/DTOs/CTicketNoAuthenticationDto.cs | 2 + Shared/DTOs/VerificationCodeDto.cs | 15 ++++ TaxPayerFull/Layout/Contact.razor | 97 +++++++++++++------- TaxPayerFull/Pages/Verification.razor | 12 ++- 9 files changed, 266 insertions(+), 38 deletions(-) create mode 100644 Back/Services/ServValidatinMsg.cs create mode 100644 Back/Services/servTicket.cs create mode 100644 Shared/DTOs/VerificationCodeDto.cs diff --git a/Back/Controllers/TicketController.cs b/Back/Controllers/TicketController.cs index b13d4e0..7f26338 100644 --- a/Back/Controllers/TicketController.cs +++ b/Back/Controllers/TicketController.cs @@ -1,9 +1,12 @@ using Back.Common.Enums; 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; +using System.Security.Cryptography; namespace Back.Controllers { @@ -12,12 +15,42 @@ namespace Back.Controllers [ApiController] public class TicketController : ControllerBase { + private readonly MobileValidation _mobilevalidation; + private readonly servTicket _servTicket; + private readonly ServValidatinMsg _servValidatinMsg; + public TicketController(MobileValidation mobilevalidation, servTicket servTicket, ServValidatinMsg servValidatinMsg) + { + _mobilevalidation = mobilevalidation; + _servTicket = servTicket; + _servValidatinMsg = servValidatinMsg; + } [HttpPost("NewTicketNoAuthentication")] [AllowAnonymous] public async Task> NewTicketNoAuthentication(CTicketNoAuthenticationDto item) { - return Ok(); + var resultValidationmodel = await _mobilevalidation.ValidateAsync(item.Mobile); + 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 code= await _servValidatinMsg.GenerateCode(new VerificationCode + { + ID = 0, + prm = Ticket.ID.ToString(), + val = item.Mobile, + Type = "NewTicketNoAuthentication" + }); + + return Ticket == null ? BadRequest() : Ok(new VerificationCodeDto + { + prm = Ticket.ID.ToString(), + val = item.Mobile, + Type = "NewTicketNoAuthentication" + }); } } } diff --git a/Back/Program.cs b/Back/Program.cs index a262e78..bd44c01 100644 --- a/Back/Program.cs +++ b/Back/Program.cs @@ -21,6 +21,8 @@ builder.Services.AddScoped(typeof(IAsyncRepository<>), typeof(RepositoryBase<>)) builder.Services.AddScoped(); builder.Services.AddScoped (); builder.Services.AddScoped(); +builder.Services.AddScoped (); +builder.Services.AddScoped < ServValidatinMsg>(); string origins = "OriginTaxPayer"; builder.Services.AddCors(options => { diff --git a/Back/Services/ServValidatinMsg.cs b/Back/Services/ServValidatinMsg.cs new file mode 100644 index 0000000..41e57fc --- /dev/null +++ b/Back/Services/ServValidatinMsg.cs @@ -0,0 +1,35 @@ +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 GetRegistrationCode(int ID) + { + return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync(); + } + public async Task GenerateCode(VerificationCode code) + { + code.ID = Random.Shared.Next(1000, 9000); + while (await GetRegistrationCode(code.ID) != null) + code.ID = Random.Shared.Next(1000, 9000); + + + await _verificationCodeRepo.AddAsync(code); + + return code.ID; + } + } +} diff --git a/Back/Services/servTicket.cs b/Back/Services/servTicket.cs new file mode 100644 index 0000000..017ab63 --- /dev/null +++ b/Back/Services/servTicket.cs @@ -0,0 +1,104 @@ +using Back.Common; +using Back.Common.Enums; +using Back.Data.Contracts; +using Back.Data.Models; +using Shared.DTOs; + +namespace Back.Services +{ + public class servTicket + { + private readonly IAsyncRepository _ticketUnknownPeopleRepo; + private readonly IAsyncRepository _ticketRepo; + private readonly IAsyncRepository _subticketRepo; + public servTicket(IAsyncRepository ticketUnknownPeopleRepo + ,IAsyncRepository ticketRepo + ,IAsyncRepository subticketRepo + ) + { + _ticketUnknownPeopleRepo = ticketUnknownPeopleRepo; + _ticketRepo = ticketRepo; + _subticketRepo = subticketRepo; + } + public async Task NewPepole(string FullName, string Mobile) + { + try + { + var item=await _ticketUnknownPeopleRepo.AddAsync(new TiceketUnknownPeople + { + FullName = FullName, + Mobile = Mobile + }); + //_contextMongodb.InsertItem(new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewPepole", + // Value = JsonConvert.SerializeObject(item), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}); + return item.ID; + } + catch (Exception ex) + { + //_contextMongodb.InsertItem(new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewPepole", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + //}); + return 0; + } + + } + public async Task NewTicket(CTicketDto item, StatusTicket status = StatusTicket.Awaitingreview) + { + try + { + var ticket=await _ticketRepo.AddAsync(new Ticket + { + CompanyIDOrMobile = item.CompanyID, + CreateDate = DateTime.Now.ConvertMiladiToShamsi(), + CreateTime = DateTime.Now.ToString("hh:mm tt"), + Title = item.Title, + Status = status + }); + await _subticketRepo.AddAsync(new SubTicket + { + Date = DateTime.Now.ConvertMiladiToShamsi(), + Time = DateTime.Now.ToString("hh:mm tt"), + TicketID = ticket.ID, + Text = item.Text, + Type = SideType.Customer + }); + //_contextMongodb.InsertItem(new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewTicket", + // Value = JsonConvert.SerializeObject(item), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}); + return ticket; + } + catch (Exception ex) + { + //_contextMongodb.InsertItem(new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewTicket", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + //}); + return null; + } + } + } +} diff --git a/Shared/DTOs/CTicketDto.cs b/Shared/DTOs/CTicketDto.cs index ff808ca..1e3b37c 100644 --- a/Shared/DTOs/CTicketDto.cs +++ b/Shared/DTOs/CTicketDto.cs @@ -9,7 +9,7 @@ namespace Shared.DTOs { public class CTicketDto { - public string CompanyID { get; set; } + public string? CompanyID { get; set; } [Required] public string Title { get; set; } [Required] diff --git a/Shared/DTOs/CTicketNoAuthenticationDto.cs b/Shared/DTOs/CTicketNoAuthenticationDto.cs index 2c119c7..21bf623 100644 --- a/Shared/DTOs/CTicketNoAuthenticationDto.cs +++ b/Shared/DTOs/CTicketNoAuthenticationDto.cs @@ -10,8 +10,10 @@ namespace Shared.DTOs public class CTicketNoAuthenticationDto:CTicketDto { [Required] + [StringLength(11)] public string Mobile { get; set; } [Required] + [StringLength(5)] public string FullName { get; set; } } } diff --git a/Shared/DTOs/VerificationCodeDto.cs b/Shared/DTOs/VerificationCodeDto.cs new file mode 100644 index 0000000..b6376d2 --- /dev/null +++ b/Shared/DTOs/VerificationCodeDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs +{ + public class VerificationCodeDto + { + public string prm { get; set; } + public string val { get; set; } + public string Type { get; set; } + } +} diff --git a/TaxPayerFull/Layout/Contact.razor b/TaxPayerFull/Layout/Contact.razor index 33dec41..14f6b48 100644 --- a/TaxPayerFull/Layout/Contact.razor +++ b/TaxPayerFull/Layout/Contact.razor @@ -1,4 +1,8 @@ -
+@using Front.Pages +@using Shared.DTOs +@inject HttpClient _hc + +
@@ -27,62 +31,46 @@
-
+ + +
+ + + + +
- + نام شما
-
- - ایمیل شما +
+ + موبایل
- - شماره تماس -
-
-
-
- -
- موضوع -
    -
  • موضوع
  • -
  • موضوع 1
  • -
  • موضوع 2
  • -
  • موضوع 3
  • -
  • موضوع 4
  • -
  • موضوع 5
  • -
-
+ + عنوان
- + پیام شما ...
- +
- +
@@ -91,5 +79,46 @@
@code { + string type = "NewTicketNoAuthentication"; + private EditContext? editContext; + [SupplyParameterFromForm] + private CTicketNoAuthenticationDto? model { get; set; } = new CTicketNoAuthenticationDto(); + private ValidationMessageStore? messageStore; + + protected override void OnInitialized() + { + // modelTaxTools ??= new(); + // editContext = new(modelTaxTools); + // editContext.OnValidationRequested += HandleValidationRequested; + // messageStore = new(editContext); + + editContext = new EditContext(model); + messageStore = new(editContext); + } +} +@functions{ + private async Task newTicket(){ + + // var request = await _hc.PostAsJsonAsync("Ticket/NewTicketNoAuthentication", model); + // if (request.IsSuccessStatusCode) + // { + // messageStore?.Clear(); + // var res = await request.Content.ReadFromJsonAsync(); + Verification pa = new Verification(); + pa.model = new VerificationCodeDto + { + prm =" Ticket.ID.ToString()", + val = "item.Mobile", + Type = "NewTicketNoAuthentication" + }; + await Task.Run(()=>pa); + // } + // else + // { + // var error = await request.Content.ReadFromJsonAsync>(); + // messageStore?.Add(() => model.Mobile, error); + + // } + } } diff --git a/TaxPayerFull/Pages/Verification.razor b/TaxPayerFull/Pages/Verification.razor index 0475c61..cd02456 100644 --- a/TaxPayerFull/Pages/Verification.razor +++ b/TaxPayerFull/Pages/Verification.razor @@ -1,5 +1,13 @@ -

Verification

+@using Shared.DTOs +@page "/Verification/{model}" +

Verification

@code { - + [Parameter] + public VerificationCodeDto? model { get; set; } + protected override async Task OnParametersSetAsync() + { + var dfsf = model; + await base.OnParametersSetAsync(); + } }