From 3f0a37a08bfe82d5a620b15a6ecd7ef61c4d46cf Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Wed, 17 Apr 2024 15:49:34 +0330 Subject: [PATCH] ... --- Back/Back.csproj | 3 +- Back/Controllers/BaseController.cs | 133 +++++++- Back/Controllers/TicketController.cs | 10 +- Back/Controllers/UserController.cs | 38 +++ Back/Controllers/VerificationController.cs | 35 ++- Back/Data/Contracts/IAsyncRepository.cs | 2 + .../Repository/RepositoryBase.cs | 30 ++ Back/FixedValues.cs | 12 + Back/Program.cs | 9 +- Back/Services/CheckPermission.cs | 239 +++++++++++++++ Back/Services/ServValidatinMsg.cs | 30 +- Back/Services/servCompany.cs | 112 +++++++ Back/Services/servNotification.cs | 20 ++ Back/Services/servPermission.cs | 117 +++++++ Back/Services/servSendMsg.cs | 14 + Back/Services/servUser.cs | 286 ++++++++++++++++++ .../CompanyRegistrationValidation.cs | 21 ++ Shared/DTOs/Authentication.cs | 8 + Shared/DTOs/CompanyAuthenticationDTO.cs | 12 + Shared/DTOs/CompanyDTO.cs | 17 ++ Shared/DTOs/CompanyRegistrationDTO.cs | 13 + Shared/DTOs/DashBoardDTO.cs | 28 ++ Shared/DTOs/PermissionAuthenticationDTO.cs | 11 + Shared/DTOs/UserAuthenticationDTO.cs | 14 + TaxPayerFull/Layout/Contact.razor | 5 +- TaxPayerFull/Pages/Register.razor | 109 ++++--- TaxPayerFull/Program.cs | 4 +- 27 files changed, 1253 insertions(+), 79 deletions(-) create mode 100644 Back/Controllers/UserController.cs create mode 100644 Back/FixedValues.cs create mode 100644 Back/Services/CheckPermission.cs create mode 100644 Back/Services/servCompany.cs create mode 100644 Back/Services/servNotification.cs create mode 100644 Back/Services/servPermission.cs create mode 100644 Back/Services/servSendMsg.cs create mode 100644 Back/Services/servUser.cs create mode 100644 Back/Validations/CompanyRegistrationValidation.cs create mode 100644 Shared/DTOs/Authentication.cs create mode 100644 Shared/DTOs/CompanyAuthenticationDTO.cs create mode 100644 Shared/DTOs/CompanyDTO.cs create mode 100644 Shared/DTOs/CompanyRegistrationDTO.cs create mode 100644 Shared/DTOs/DashBoardDTO.cs create mode 100644 Shared/DTOs/PermissionAuthenticationDTO.cs create mode 100644 Shared/DTOs/UserAuthenticationDTO.cs diff --git a/Back/Back.csproj b/Back/Back.csproj index ac6c0cd..2ec34d7 100644 --- a/Back/Back.csproj +++ b/Back/Back.csproj @@ -7,6 +7,7 @@ + @@ -34,7 +35,7 @@ - ..\..\Dlls\Service.dll + ..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll diff --git a/Back/Controllers/BaseController.cs b/Back/Controllers/BaseController.cs index 0670116..e61cb5b 100644 --- a/Back/Controllers/BaseController.cs +++ b/Back/Controllers/BaseController.cs @@ -1,5 +1,9 @@ -using Back.Services; +using Back.Common; +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; @@ -12,10 +16,25 @@ namespace Back.Controllers { private readonly ServBase _sBase; private readonly MobileValidation _mobilevalidation; - public BaseController(ServBase sBase, MobileValidation mobilevalidation) + private readonly servCompany _servCompany; + private readonly servUser _servUser; + private readonly servPermission _servPermission; + private readonly ServValidatinMsg _servValidatinMsg; + private readonly servSendMsg _servSendMsg; + private readonly CompanyRegistrationValidation _companyRegistrationValidation; + public BaseController(ServBase sBase, MobileValidation mobilevalidation + , servCompany servCompany, servUser servUser + , servPermission servPermission, ServValidatinMsg servValidatinMsg + , servSendMsg servSendMsg, CompanyRegistrationValidation companyRegistrationValidation) { _sBase = sBase; _mobilevalidation = mobilevalidation; + _servCompany = servCompany; + _servUser = servUser; + _servPermission = servPermission; + _servValidatinMsg = servValidatinMsg; + _servSendMsg = servSendMsg; + _companyRegistrationValidation = companyRegistrationValidation; } [HttpGet("Pricing")] public async Task>> Pricing() @@ -24,14 +43,14 @@ namespace Back.Controllers public async Task> DateTimeServer() => Ok(DateTime.Now); [HttpGet("LastBlog")] - public async Task>> LastBlog(int PageIndex,int PageSize) - => Ok(await _sBase.GetBlog(PageIndex,PageSize)); + public async Task>> LastBlog(int PageIndex, int PageSize) + => Ok(await _sBase.GetBlog(PageIndex, PageSize)); [HttpGet("GetBlogByID/{ID}")] public async Task> GetBlogByID(int ID) { var result = await _sBase.GetBlogByID(ID); if (result == null) - return NotFound(); + return NotFound(); return Ok(result); } [HttpGet("LastQuestion")] @@ -42,18 +61,112 @@ namespace Back.Controllers { var resultValidationmodel = await _mobilevalidation.ValidateAsync(model.Mobile); if (!resultValidationmodel.IsValid) - return BadRequest(resultValidationmodel.Errors.Select(s=>s.ErrorMessage ).ToList()); + return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList()); return Ok(await _sBase.CreateCsrAndPrivateKey(model)); } [HttpPost("ReadPublicKeyFromCER")] public async Task> ReadPublicKeyFromCER(string modelfromBase64) { var result = await _sBase.ReadPublicKeyFromCER(modelfromBase64); - if (result.type== "error") + if (result.type == "error") return BadRequest(); - - return Ok(result); + + return Ok(result); } - + [HttpPost("CompanyRegistration")] + [AllowAnonymous] + public async Task> CompanyRegistration([FromBody] CompanyRegistrationDTO item) + { + + var resultValidationmodel = await _companyRegistrationValidation.ValidateAsync(item); + if (!resultValidationmodel.IsValid) + return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList()); + + + try + { + var user = new User() + { + Fullname = item.FullnameUser, + Mobile = item.Mobile, + Username = item.Username, + Password = item.Mobile.encrypted(), + IsActive = false + + }; + user = await _servUser.AddUser(user); + + var company =await _servCompany.GetCompanyOrgByMobileAndCompanynotActive(item.Mobile); + if (company==null) + { + company = new Company() + { + Name = item.CompanyName, + Mobile = item.Mobile, + RegisterDate = DateTime.Now.ConvertMiladiToShamsi(), + IsActive = false + + }; + + } + else + { + company.Name = item.CompanyName; + company.RegisterDate = DateTime.Now.ConvertMiladiToShamsi(); + company.IsActive = false; + } + + company = await _servCompany.AddORUpdateCompany(company); + + var allper = await _servPermission.GetPermissions(); + + var roluser = new RolUser() + { + CompanyID = company.ID, + UserID = user.ID, + IsAdmin = true + }; + roluser = await _servPermission.AddRolUser(roluser); + + await _servPermission.AddRangePermissionPeriodByCompany(new List() + { + new PermissionPeriod(){CompanyID=company.ID,PermissionID=2,CalculationTypeID=2,RemainingAmount=0,TotalAmount=0}, + new PermissionPeriod(){CompanyID=company.ID,PermissionID=3,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5}, + new PermissionPeriod(){CompanyID=company.ID,PermissionID=4,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5}, + new PermissionPeriod(){CompanyID=company.ID,PermissionID=5,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5}, + new PermissionPeriod(){CompanyID=company.ID,PermissionID=16,CalculationTypeID=1,RemainingAmount=5,TotalAmount=5}, + new PermissionPeriod(){CompanyID=company.ID,PermissionID=6,CalculationTypeID=2,RemainingAmount=0,TotalAmount=0} + + }); + + await _servPermission.AddPermissionUser(roluser.ID, allper.Select(s => s.ID).ToArray()); + + var ID = await _servValidatinMsg.GenerateCode(new VerificationCode + { + prm = company.ID.ToString(), + val = user.ID.ToString(), + Type = "CompanyRegistration" + }); + + _servSendMsg.Authentication(company.Mobile, ID.ToString()); + return Ok(ID); + } + catch (Exception ex) + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = HttpContext.Request.Method, + // Value = ex.Message, + // Route = HttpContext.Request.Path, + // Type = "catch" + //}; + //_contextMongodb.InsertItem(log); + return BadRequest("خطای سیستمی رخ داده"); + } + + } + } } diff --git a/Back/Controllers/TicketController.cs b/Back/Controllers/TicketController.cs index 6abbd71..853d7e4 100644 --- a/Back/Controllers/TicketController.cs +++ b/Back/Controllers/TicketController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Shared.DTOs; using System.Security.Cryptography; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace Back.Controllers { @@ -18,11 +19,14 @@ namespace Back.Controllers private readonly MobileValidation _mobilevalidation; private readonly servTicket _servTicket; private readonly ServValidatinMsg _servValidatinMsg; - public TicketController(MobileValidation mobilevalidation, servTicket servTicket, 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")] @@ -41,9 +45,9 @@ namespace Back.Controllers { prm = Ticket.ID.ToString(), val = item.Mobile, - Type = "NewTicketNoAuthentication" + Type = "NewTicketNoAuthentication" }); - + _servSendMsg.Authentication(item.Mobile, ID.ToString()); return Ticket == null ? BadRequest() : Ok(ID); } } diff --git a/Back/Controllers/UserController.cs b/Back/Controllers/UserController.cs new file mode 100644 index 0000000..9aa7c38 --- /dev/null +++ b/Back/Controllers/UserController.cs @@ -0,0 +1,38 @@ +using Back.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Shared.DTOs; + +namespace Back.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class UserController : ControllerBase + { + private readonly servUser _servUser; + public UserController(servUser servUser) + { + + _servUser = servUser; + + } + [HttpPost("authenticate")] + [AllowAnonymous] + public async Task> Login(Authentication model) + { + if (!ModelState.IsValid) return BadRequest(model); + var result = await _servUser.UserAuthentication(model.Username, model.Password); + if (result != null) return Ok(result); + + + + + + else return NotFound("کاربری با این مشخصات یافت نشد"); + + + + } + } +} diff --git a/Back/Controllers/VerificationController.cs b/Back/Controllers/VerificationController.cs index dd9c8ab..44c1d21 100644 --- a/Back/Controllers/VerificationController.cs +++ b/Back/Controllers/VerificationController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Shared.DTOs; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace Back.Controllers { @@ -14,11 +15,14 @@ namespace Back.Controllers { private readonly ServValidatinMsg _servValidatinMsg; private readonly GetVerificationValidation _getVerificationValidation; - public VerificationController(ServValidatinMsg servValidatinMsg, GetVerificationValidation getVerificationValidation) + private readonly servSendMsg _servSendMsg; + private readonly servCompany _servCompany; + public VerificationController(ServValidatinMsg servValidatinMsg, GetVerificationValidation getVerificationValidation + , servCompany servCompany) { _servValidatinMsg = servValidatinMsg; _getVerificationValidation = getVerificationValidation; - + _servCompany = servCompany; } [HttpGet("GetVerification/{ID}")] [AllowAnonymous] @@ -44,6 +48,22 @@ namespace Back.Controllers if (!resultValidationmodel.IsValid) return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList()); // _getVerificationValidation.verificationCode + + switch (_getVerificationValidation.verificationCode.Type) + { + case "NewTicketNoAuthentication": + _servSendMsg.Authentication(_getVerificationValidation.verificationCode.val, ID.ToString()); + break; + + case "CompanyRegistration": + var company=await _servCompany.GetCompanyOrg(Convert.ToInt32(_getVerificationValidation.verificationCode.prm),false); + _servSendMsg.Authentication(company.Mobile, ID.ToString()); + break; + + default: + return BadRequest("این نوع احراز تعریف نشده"); + } + return NoContent(); } [HttpPost("Submit")] @@ -64,12 +84,21 @@ namespace Back.Controllers case "NewTicketNoAuthentication": Sucstatus = await _servValidatinMsg.SubmittedTicket(VerificationCode); break; + + case "CompanyRegistration": + //string UserID = VerificationCode.val; + Sucstatus = await _servValidatinMsg.SubmittedCompanyRegistration(VerificationCode); + // return Ok(await _servUser.UserAuthentication(UserID)); + //else return BadRequest(); + break; + default: return BadRequest("این نوع احراز تعریف نشده"); } + if (Sucstatus) await _servValidatinMsg.Delete(VerificationCode); - + return Ok(Sucstatus); } else return BadRequest("اطلاعات شما منطبق با سامانه نیست"); diff --git a/Back/Data/Contracts/IAsyncRepository.cs b/Back/Data/Contracts/IAsyncRepository.cs index 1d82436..522823c 100644 --- a/Back/Data/Contracts/IAsyncRepository.cs +++ b/Back/Data/Contracts/IAsyncRepository.cs @@ -28,6 +28,8 @@ namespace Back.Data.Contracts bool AddBoolResult(T entity); Task UpdateAsync(T entity); bool Update(T entity); + Task UpdateByObjAsync(T entity); + T? UpdateByObj(T entity); Task UpdateRangeAsync(ICollection entites); bool UpdateRange(ICollection entites); bool Delete(T entity); diff --git a/Back/Data/Infrastructure/Repository/RepositoryBase.cs b/Back/Data/Infrastructure/Repository/RepositoryBase.cs index 4776475..7f8d859 100644 --- a/Back/Data/Infrastructure/Repository/RepositoryBase.cs +++ b/Back/Data/Infrastructure/Repository/RepositoryBase.cs @@ -134,6 +134,36 @@ namespace Back.Data.Infrastructure.Repository return false; } + } + public async Task UpdateByObjAsync(T entity) + { + try + { + + _dbContext.Entry(entity).State = EntityState.Modified; + await _dbContext.SaveChangesAsync(); + return entity; + } + catch (Exception) + { + return null; + throw; + } + + } + public T? UpdateByObj(T entity) + { + try + { + _dbContext.Update(entity); + var result = _dbContext.SaveChanges(); + return entity; + } + catch (Exception) + { + return null; + } + } public async Task DeleteAsync(T entity) { diff --git a/Back/FixedValues.cs b/Back/FixedValues.cs new file mode 100644 index 0000000..fc4a4dd --- /dev/null +++ b/Back/FixedValues.cs @@ -0,0 +1,12 @@ +namespace Back +{ + public static class Fixedvalues + { + //public static string ConnectionString = "Data Source=195.88.208.142;Initial Catalog=TaxPayer020713;User ID=sa;Password=M439610m@;TrustServerCertificate=True"; + public static string SecretForKey = "thisisthesecretforgeneratingakey(mustbeatleast32bitlong)mmrbnjd"; + public static string Issuer = "http://mmrbnjd.com"; + public static string Audience = "TaxPayer"; + //public static string MongoServer = "mongodb://localhost:27017"; + //public static string Mongodb = "TaxPayerLog"; + } +} diff --git a/Back/Program.cs b/Back/Program.cs index 01e7e56..0d0ec22 100644 --- a/Back/Program.cs +++ b/Back/Program.cs @@ -25,7 +25,14 @@ builder.Services.AddScoped (); builder.Services.AddScoped < ServValidatinMsg>(); builder.Services.AddScoped (); builder.Services.AddScoped(); - +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2")); string origins = "OriginTaxPayer"; builder.Services.AddCors(options => diff --git a/Back/Services/CheckPermission.cs b/Back/Services/CheckPermission.cs new file mode 100644 index 0000000..3c1355c --- /dev/null +++ b/Back/Services/CheckPermission.cs @@ -0,0 +1,239 @@ +using Back.Common; +using Back.Data.Contracts; +using Back.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace Back.Services +{ + public class CheckPermission + { + private readonly IAsyncRepository _repoPermissionPeriod; + private readonly IAsyncRepository _repoPermissionUser; + public CheckPermission(IAsyncRepository repoPermissionPeriod + ,IAsyncRepository repoPermissionUser) + { + _repoPermissionPeriod = repoPermissionPeriod; + _repoPermissionUser = repoPermissionUser; + } + private async Task AllowPermissionInCompany(int CompanyID,int PermissionID,int Allowednumber = 1) + { + + PermissionPeriod? permissionPeriod = _repoPermissionPeriod + .Get(w => w.CompanyID == CompanyID && w.PermissionID == PermissionID && (!w.IsLocked.HasValue || !w.IsLocked.Value)) + .FirstOrDefault(); + + if (permissionPeriod == null) + return false; + + //تعداد + if (permissionPeriod.CalculationTypeID == 1) + { + if (permissionPeriod.RemainingAmount < Allowednumber) + return false; + + //permissionPeriod.RemainingAmount -= 1; + + } + //تا تاریخ + else if (permissionPeriod.CalculationTypeID == 3) + { + + string date = $"{permissionPeriod.RemainingAmount.ToString().Substring(0, 4)}/{permissionPeriod.RemainingAmount.ToString().Substring(4, 2)}/{permissionPeriod.RemainingAmount.ToString().Substring(6, 2)}"; + DateTime dateTime = date.ToMiladi(); + if (DateTime.Now > dateTime) + return false; + + } + return await _repoPermissionPeriod.UpdateAsync(permissionPeriod); + + } + public async Task AllowPermission(int UserID,int CompanyID, int PermissionID) + { + + return await _repoPermissionUser + .Get(w => w.RolUser.UserID == UserID && w.RolUser.CompanyID == CompanyID && w.PermissionID==PermissionID) + .AnyAsync(); + + + + } + public async Task ExtensionofAccess(int CompanyID, int PermissionID, string value) + { + PermissionPeriod? permissionPeriod = _repoPermissionPeriod + .Get(w => w.CompanyID == CompanyID && w.PermissionID == PermissionID + && (!w.IsLocked.HasValue || !w.IsLocked.Value)) + .FirstOrDefault(); + + + //تعداد + if (permissionPeriod.CalculationTypeID == 1) + { + if (permissionPeriod.RemainingAmount < 0) + permissionPeriod.RemainingAmount = Convert.ToInt32(value); + + permissionPeriod.RemainingAmount += Convert.ToInt32(value); + + } + try + { + + return await _repoPermissionPeriod.UpdateAsync(permissionPeriod); + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/ExtensionofAccess", + // Value = $"{permissionPeriod.RemainingAmount - Convert.ToInt32(value)}+({value})={permissionPeriod.RemainingAmount}", + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}; + //_contextMongodb.InsertItem(log); + } + catch (Exception ex) + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/ExtensionofAccess", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + //}; + //_contextMongodb.InsertItem(log); + return false; + } + + } + + //--------Customer--------- + #region Customer + public async Task AllowAddCustomerInCompany(int CompanyID, int Allowednumber = 1) + { + //مشتری + int PermissionID = 5; + return await AllowPermissionInCompany(CompanyID, PermissionID,Allowednumber); + + } + public async Task AllowSYSGetCustomer(int UserID, int CompanyID) + { + //مشتری + int PermissionID = 5; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSAddCustomer(int UserID, int CompanyID) + { + //مشتری + int PermissionID = 7; + return await AllowPermission(UserID,CompanyID, PermissionID); + + } + public async Task AllowSYSDeleteCustomer(int UserID, int CompanyID) + { + //مشتری + int PermissionID = 9; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSUpdateCustomer(int UserID, int CompanyID) + { + //مشتری + int PermissionID = 8; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + #endregion + //-----------COD----------- + #region COD + public async Task AllowAddCODInCompany(int CompanyID,int Allowednumber=1) + { + //کالا + int PermissionID = 4; + return await AllowPermissionInCompany(CompanyID, PermissionID,Allowednumber); + + } + public async Task AllowSYSGetCOD(int UserID, int CompanyID) + { + //کالا + int PermissionID = 4; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSAddCOD(int UserID, int CompanyID) + { + //کالا + int PermissionID = 10; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSDeleteCOD(int UserID, int CompanyID) + { + //کالا + int PermissionID = 12; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSUpdateCOD(int UserID, int CompanyID) + { + //کالا + int PermissionID = 11; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + #endregion + //--------Invoice--------- + #region Invoice + public async Task AllowAddInvoiceInCompany(int CompanyID, int Allowednumber = 1) + { + int PermissionID = 3; + return await AllowPermissionInCompany(CompanyID, PermissionID, Allowednumber); + + } + public async Task AllowSYSGetInvoice(int UserID, int CompanyID) + { + int PermissionID = 3; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSAddInvoice(int UserID, int CompanyID) + { + int PermissionID = 13; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSDeleteInvoice(int UserID, int CompanyID) + { + int PermissionID = 15; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSUpdateInvoice(int UserID, int CompanyID) + { + int PermissionID = 14; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + #endregion + #region TaxPayer + public async Task AllowSendTaxPayerInCompany(int CompanyID) + { + int PermissionID = 16; + return await AllowPermissionInCompany(CompanyID, PermissionID); + + } + public async Task AllowSYSGetTaxPayer(int UserID, int CompanyID) + { + int PermissionID = 16; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + public async Task AllowSYSSendTaxPayer(int UserID, int CompanyID) + { + int PermissionID = 16; + return await AllowPermission(UserID, CompanyID, PermissionID); + + } + #endregion + } +} diff --git a/Back/Services/ServValidatinMsg.cs b/Back/Services/ServValidatinMsg.cs index 3451948..bf4c5bf 100644 --- a/Back/Services/ServValidatinMsg.cs +++ b/Back/Services/ServValidatinMsg.cs @@ -9,10 +9,18 @@ namespace Back.Services { private readonly IAsyncRepository _verificationCodeRepo; private readonly IAsyncRepository _ticket; - public ServValidatinMsg(IAsyncRepository verificationCodeRepo, IAsyncRepository ticket) + private readonly IAsyncRepository _UserRepo; + private readonly IAsyncRepository _CompanyRepo; + private readonly servSendMsg _servSendMsg; + public ServValidatinMsg(IAsyncRepository verificationCodeRepo + , IAsyncRepository ticket, IAsyncRepository UserRepo + , IAsyncRepository CompanyRepo, servSendMsg servSendMsg) { _verificationCodeRepo = verificationCodeRepo; _ticket = ticket; + _UserRepo = UserRepo; + _CompanyRepo = CompanyRepo; + _servSendMsg = servSendMsg; } public async Task GetCodeByPrm(string Prm) { @@ -37,6 +45,26 @@ namespace Back.Services } return false; } + public async Task 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; + } public async Task GenerateCode(VerificationCode code) { code.Code = Random.Shared.Next(1000, 9000); diff --git a/Back/Services/servCompany.cs b/Back/Services/servCompany.cs new file mode 100644 index 0000000..c4be416 --- /dev/null +++ b/Back/Services/servCompany.cs @@ -0,0 +1,112 @@ +using Back.Common; +using Back.Data.Contracts; +using Back.Data.Models; +using Microsoft.EntityFrameworkCore; +using Shared.DTOs; + + +namespace Back.Services +{ + public class servCompany + { + private readonly IAsyncRepository _repoRolUser; + private readonly IAsyncRepository _repoCompany; + + //private readonly servSendMsg _servSendMsg; + public servCompany(IAsyncRepository repoRolUser, IAsyncRepository repoCompany) + { + _repoCompany = repoCompany; + _repoRolUser = repoRolUser; + } + public async Task ExsistCompanyByComoanyIDandUserID(int ComoanyID, int UserID,bool InAdmin=false) + { + var res= _repoRolUser.Get(w => w.CompanyID == ComoanyID && w.UserID == UserID && w.Company.IsActive); + if (InAdmin) + res = res.Where( w=> w.IsAdmin); + + return await res.AnyAsync(); + } + public async Task GetCompany(int ComoanyID) + { + return await _repoCompany.Get(w => w.ID == ComoanyID && w.IsActive) + .Select(s=>new CompanyDTO() + { + BranchID = s.BranchID, + EconomicCode = s.EconomicCode, + ID = s.ID, + Email = s.Email, + Logo= s.Logo==null ?null: System.Text.Encoding.UTF8.GetString(s.Logo) , + Mobile = s.Mobile, + Name = s.Name, + Phone = s.Phone, + PrivateKey= s.PrivateKey, + UniqeMemory = s.UniqeMemory + }).FirstOrDefaultAsync(); + } + public async Task GetCompanyOrg(int ComoanyID,bool IsActive=true) + { + var inv = _repoCompany.Get(w => w.ID == ComoanyID); + if (IsActive) + inv= inv.Where(w=>w.IsActive); + + return await inv.FirstOrDefaultAsync(); + } + public async Task GetCompanyOrgByMobileAndCompanynotActive(string Mobile) + { + var inv = _repoCompany.Get(w => w.Mobile == Mobile && !w.IsActive); + return await inv.FirstOrDefaultAsync(); + } + public async Task AddORUpdateCompany(Company item) + { + + try + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCompany", + // Value = "*" + JsonConvert.SerializeObject(item), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}; + //_contextMongodb.InsertItem(log); + + if (item.ID == null || item.ID ==0) + { + return await _repoCompany.AddAsync(item); + } + else + { + return await _repoCompany.UpdateByObjAsync(item); + } + + + + } + catch (Exception ex) + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCompany", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + //}; + //_contextMongodb.InsertItem(log); + return null; + + } + } + public async Task ExistMobileAndCompanyIsActive(string mobile) + { + return await _repoCompany.GetAll().AnyAsync(w => w.Mobile == mobile && w.IsActive); + } + + + + + } +} diff --git a/Back/Services/servNotification.cs b/Back/Services/servNotification.cs new file mode 100644 index 0000000..901adbd --- /dev/null +++ b/Back/Services/servNotification.cs @@ -0,0 +1,20 @@ +using Back.Data.Contracts; +using Back.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace Back.Services +{ + public class servNotification + { + private readonly IAsyncRepository _NotificationRepo; + + public servNotification(IAsyncRepository NotificationRepo) + { + _NotificationRepo = NotificationRepo; + } + public async Task> GetNotifications() + { + return await _NotificationRepo.Get(w=>w.Status).ToListAsync(); + } + } +} diff --git a/Back/Services/servPermission.cs b/Back/Services/servPermission.cs new file mode 100644 index 0000000..ce8f62b --- /dev/null +++ b/Back/Services/servPermission.cs @@ -0,0 +1,117 @@ +using Back.Data.Contracts; +using Back.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace Back.Services +{ + public class servPermission + { + private readonly IAsyncRepository _repoPermission; + private readonly IAsyncRepository _repoPermissionPeriod; + private readonly IAsyncRepository _repoRolUser; + private readonly IAsyncRepository _repoPermissionUser; + public servPermission(IAsyncRepository repoPermission, IAsyncRepository repoPermissionPeriod + , IAsyncRepository repoRolUser, IAsyncRepository repoPermissionUser) + { + _repoPermission = repoPermission; + _repoPermissionPeriod = repoPermissionPeriod; + _repoPermissionUser = repoPermissionUser; + _repoRolUser= repoRolUser; + } + public async Task> GetChildPermission(int PermissionID) + { + return await _repoPermission.Get(w => w.ParentID == PermissionID).ToListAsync(); + } + public async Task> GetPermissions() + { + return await _repoPermission.GetAll().ToListAsync(); + } + public async Task AddRolUser(RolUser rolUser) + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddRolUser", + // Value = "*" + JsonConvert.SerializeObject(rolUser), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}; + //_contextMongodb.InsertItem(log); + return await _repoRolUser.AddAsync(rolUser); + } + public async Task AddRangePermissionPeriodByCompany(IEnumerable permissions) + { + try + { + return await _repoPermissionPeriod.AddRangeAsync(permissions.ToList())/*.Wait()*/; + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddRangePermissionPeriodByCompany", + // Value = JsonConvert.SerializeObject(permissions), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}; + //_contextMongodb.InsertItem(log); + + + } + catch (Exception ex) + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddRangePermissionPeriodByCompany", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + //}; + //_contextMongodb.InsertItem(log); + return false; + + } + } + public async Task AddPermissionUser(int RolUserID, int[] PermissionIDs) + { + try + { + List permissionUsers = new List(); + foreach (int permissionID in PermissionIDs) + permissionUsers.Add(new PermissionUser() { PermissionID=permissionID,RolUserID= RolUserID }); + + return await _repoPermissionUser.AddRangeAsync(permissionUsers); + + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddPermissionUser", + // Value = RolUserID+" "+JsonConvert.SerializeObject(PermissionIDs), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}; + //_contextMongodb.InsertItem(log); + + } + catch (Exception ex) + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddPermissionUser", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + //}; + //_contextMongodb.InsertItem(log); + return false; + + } + + } + } +} diff --git a/Back/Services/servSendMsg.cs b/Back/Services/servSendMsg.cs new file mode 100644 index 0000000..202c546 --- /dev/null +++ b/Back/Services/servSendMsg.cs @@ -0,0 +1,14 @@ +namespace Back.Services +{ + public class servSendMsg + { + private readonly mpNuget.RestClient _restClient; + public servSendMsg(mpNuget.RestClient restClient)=> _restClient = restClient; + private void SendMsgByPatern(string Text, string To, int bodyID) {/*_restClient.SendByBaseNumber(Text, To, bodyID);*/ } + private void SendMsg(string Text, string To)=> _restClient.Send(To, "50004001660045", Text, false); + public void Authentication(string to,string code) => SendMsgByPatern(code, to, 0); + public void SuccessfulRegistration(string to, string code) => SendMsgByPatern(code, to, 1); + public void SuccessfulPayment(string to, string code) => SendMsgByPatern(code, to, 2); + // public void firstEntry(string to, string code) => SendMsgByPatern(code, to, 3); + } +} diff --git a/Back/Services/servUser.cs b/Back/Services/servUser.cs new file mode 100644 index 0000000..a2bd3b8 --- /dev/null +++ b/Back/Services/servUser.cs @@ -0,0 +1,286 @@ +using Back.Common; +using Back.Data.Contracts; +using Back.Data.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; +using Shared.DTOs; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; + +namespace Back.Services +{ + public class servUser + { + private readonly IConfiguration _configuration; + private readonly CheckPermission _checkPermission; + private readonly servPermission _servPermission; + private readonly servNotification _servNotification; + private readonly IAsyncRepository _RepoUser; + private readonly IAsyncRepository _RepoPermissionPeriod; + public servUser(IConfiguration configuration, + CheckPermission checkPermission, servPermission servPermission + , servNotification servNotification, IAsyncRepository RepoUser, IAsyncRepository RepoPermissionPeriod) + { + _configuration = configuration; + _checkPermission = checkPermission; + _servPermission = servPermission; + _servNotification = servNotification; + _RepoUser = RepoUser; + _RepoPermissionPeriod = RepoPermissionPeriod; + } + public async Task GetUserByUserNameAndPassword(string UserName, string Password) + { + return await _RepoUser.Get(w => w.Username == UserName && w.Password == Password.encrypted() && w.IsActive) + .Include(i => i.RolUsers) + .ThenInclude(ti => ti.rolePermissions) + .Include(i => i.RolUsers) + .ThenInclude(ti=>ti.Company) + .ThenInclude(ti => ti.PermissionPeriods) + .ThenInclude(ti => ti.Permission) + .Include(ti=>ti.RolUsers) + .ThenInclude(ti => ti.Company) + .ThenInclude(ti => ti.PermissionPeriods) + .ThenInclude(ti => ti.CalculationType) + .FirstOrDefaultAsync(); + } + public async Task UserAuthentication(string UserNameORUserID, string Password="") + { + UserAuthenticationDTO ret = new UserAuthenticationDTO(); + User? user = null; + + if (string.IsNullOrEmpty(Password) && int.TryParse(UserNameORUserID,out int UserID)) + user = await GetUserByUserID(UserID); + else + user =await GetUserByUserNameAndPassword(UserNameORUserID, Password); + + if (user == null) + return null; + ret.Token =await CerateToken(user.ID, user.Username); + ret.FullName = user.Fullname; + ret.Photo = user.Photo==null ? null : Convert.ToBase64String(user.Photo); + foreach (var rol in user.RolUsers) + { + if (!rol.Company.IsActive) + continue; + + List permissions = new List(); + foreach (var per in rol.Company.PermissionPeriods) + { + bool _accessibility = await _checkPermission.AllowPermission(user.ID, rol.CompanyID, per.Permission.ID); + + #region Child + + List Chidpermissions = _accessibility ? await _servPermission.GetChildPermission(per.Permission.ID):new List(); + List ChildpermissionAuthenticationDTOs = new List(); + foreach (Permission childper in Chidpermissions) + { + bool _childaccessibility = await _checkPermission.AllowPermission(user.ID, rol.CompanyID, childper.ID); + PermissionAuthenticationDTO ChildpermissionAuthenticationDTO = new PermissionAuthenticationDTO + { + ID = childper.ID, + ParentID = childper.ParentID, + Title = childper.Title, + accessibility = _childaccessibility, + //TODO + ChildPermissions = null + }; + ChildpermissionAuthenticationDTOs.Add(ChildpermissionAuthenticationDTO); + } + #endregion + + PermissionAuthenticationDTO permissionAuthenticationDTO = new PermissionAuthenticationDTO + { + ID = per.Permission.ID, + ParentID = per.Permission.ParentID, + Title = per.Permission.Title, + accessibility = _accessibility, + //TODO + ChildPermissions = ChildpermissionAuthenticationDTOs + + //Period=new PeriodDTO() + //{ + // CalculationTypeID = rol.Company.PermissionPeriods.Where(w => w.PermissionID == per.ID).Select(s => s.CalculationType.ID).FirstOrDefault(), + // CalculationTypeTitle = rol.Company.PermissionPeriods.Where(w => w.PermissionID == per.ID).Select(s => s.CalculationType.Title).FirstOrDefault(), + // RemainingAmount = rol.Company.PermissionPeriods.Where(w => w.PermissionID == per.ID).Select(s => s.RemainingAmount).FirstOrDefault(), + // TotalAmount = rol.Company.PermissionPeriods.Where(w => w.PermissionID == per.ID).Select(s => s.TotalAmount).FirstOrDefault() + //} + + }; + permissions.Add(permissionAuthenticationDTO); + } + + ret.Companies.Add(new CompanyAuthenticationDTO + { + ID = rol.CompanyID, + Name = rol.Company.Name, + IsAdmin = rol.IsAdmin, + Logo= rol.Company.Logo == null ? null : Convert.ToBase64String(rol.Company.Logo) + + /*, permissions = permissions*/ + }); + + } + + return ret; + } + public async Task AddUser(User item) + { + //_contextMongodb.InsertItem(new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddUser", + // Value = JsonConvert.SerializeObject(item), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}); + return await _RepoUser.AddAsync(item); + } + public async Task ExistUser(string UserName) + { + + return await _RepoUser.GetAll().AnyAsync(w=>w.Username==UserName); + + } + public async Task GetUserByUsername(string UserName) + { + return await _RepoUser.Get(w => w.Username == UserName).FirstOrDefaultAsync(); + } + public async Task GetUserByUserID(int UserID) + { + return await _RepoUser.Get(w => w.ID == UserID).FirstOrDefaultAsync(); + } + public async void SetTokenAndDateLogininDB(int UserID,string Token) + { + var user = await GetUserByUserID(UserID); + if (user != null) + { + user.Token = Token; + user.DateLastLogin=DateTime.Now.ConvertMiladiToShamsi(); + await _RepoUser.UpdateAsync(user); + } + } + + public async Task GetDashBoard(int CompanyID,int UserID) + { + DashBoardDTO request=new DashBoardDTO(); + var period=await _RepoPermissionPeriod + .Get(w=>w.CompanyID==CompanyID && (!w.IsLocked.HasValue || !w.IsLocked.Value)).ToListAsync(); + foreach (var item in period) + { + request.AlistofServices.Add(new ServiceInDashBoardDTO + { + PermissionID= item.PermissionID, + PermissionName = item.Permission.Title, + CalTypeID= item.CalculationTypeID, + CalTypeTitle = item.CalculationType.Title, + Total = item.CalculationTypeID == 1 ? item.TotalAmount.ToString() :"", + Remaining = item.CalculationTypeID == 1 ? item.RemainingAmount.ToString() + : item.CalculationTypeID== 2 ? "" : item.RemainingAmount.ToString().ShamciToFormatShamci() + }); + } + request.LastLoginDate= _RepoUser.Get(w=>w.ID==UserID).Select(s=>s.DateLastLogin).FirstOrDefault(); + if(!string.IsNullOrEmpty(request.LastLoginDate)) + request.LastLoginDate.ShamciToFormatShamci(); + + var user = await GetUserByUserID(UserID); + if (user.Mobile == user.Username) + request.Warning.Add(new AlertDTO { Status=0,Message= "موبایل و نام کاربری بهتر است شبیه هم نباشند" }); + if (user.Mobile.encrypted() == user.Password) + request.Warning.Add(new AlertDTO { Status = 0, Message = "موبایل و کلمه عبور بهتر است شبیه هم نباشند" }); + var Company = user.RolUsers.Where(w=>w.CompanyID== CompanyID).Select(s=>s.Company).FirstOrDefault(); + if (Company!=null) + { + if (string.IsNullOrEmpty(Company.Email) || string.IsNullOrEmpty(Company.Phone) + || string.IsNullOrEmpty(Company.EconomicCode) || string.IsNullOrEmpty(Company.UniqeMemory) + || string.IsNullOrEmpty(Company.PrivateKey)) + { + request.Warning.Add(new AlertDTO { Status = 0, Message = "بهتر است اطلاعات شرکت بروزرسانی شود" }); + } + } + var nots= await _servNotification.GetNotifications(); + if (nots.Any()) + request.Notifications= nots.Select(s=>new AlertDTO + { + Message=s.Message, + Status=s.Type, + Path=s.Path, + ViewSize=s.ViewSize + }).ToList(); + return request; + } + public async Task UpdateUser(User user) + { + //_contextMongodb.InsertItem(new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/UpdateUser", + // Value = JsonConvert.SerializeObject(user), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}); + return await _RepoUser.UpdateByObjAsync(user); + } + //--------internal + private async Task CerateToken(int UserId, string UserName) + { + string Jwt_Lifetime_Minutes = ""; + try + { + Jwt_Lifetime_Minutes = _configuration["Fixedvalues:Jwt_Lifetime_Minutes"].ToString(); + if (string.IsNullOrEmpty(Jwt_Lifetime_Minutes)) + Jwt_Lifetime_Minutes = "60"; + } + catch (Exception ex) + { + //SysLog log = new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/CerateToken", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + //}; + //_contextMongodb.InsertItem(log); + Jwt_Lifetime_Minutes = "60"; + //To DO + } + + #region CreateToken + var securityKey = new SymmetricSecurityKey( + Encoding.ASCII.GetBytes(Fixedvalues.SecretForKey) + ); + var signingCredentials = new SigningCredentials( + securityKey, SecurityAlgorithms.HmacSha256 + ); + var claimsForToken = new List(); + claimsForToken.Add(new Claim("UserID", UserId.ToString())); + claimsForToken.Add(new Claim(ClaimTypes.NameIdentifier, UserName)); + + var jwtSecurityToke = new JwtSecurityToken( + Fixedvalues.Issuer, Fixedvalues.Audience, claimsForToken, + DateTime.Now, DateTime.Now.AddMinutes(Convert.ToInt32(Jwt_Lifetime_Minutes)), signingCredentials); + + + string Token = new JwtSecurityTokenHandler() + .WriteToken(jwtSecurityToke); + SetTokenAndDateLogininDB(UserId, Token); + //_contextMongodb.InsertItem(new SysLog() + //{ + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/CerateToken", + // Value = UserId + " " + UserName+"=> "+Token, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + //}); + return Token; + #endregion + + } + + } +} diff --git a/Back/Validations/CompanyRegistrationValidation.cs b/Back/Validations/CompanyRegistrationValidation.cs new file mode 100644 index 0000000..a515607 --- /dev/null +++ b/Back/Validations/CompanyRegistrationValidation.cs @@ -0,0 +1,21 @@ +using Back.Services; +using FluentValidation; +using Shared.DTOs; + +namespace Back.Validations +{ + public class CompanyRegistrationValidation : AbstractValidator + { + public CompanyRegistrationValidation(servCompany servCompany) + { + CascadeMode = CascadeMode.Stop; + RuleFor(m => m.Mobile) + .NotEmpty().WithMessage("موبایل نمی تواند باشد") + .NotNull().WithMessage("موبایل نمی تواند باشد") + .Length(11).WithMessage("فرمت موبایل صحیح نمی باشد") + .Must(m => m.StartsWith("09")).WithMessage("فرمت موبایل صحیح نمی باشد") + .Must(mo=> !servCompany.ExistMobileAndCompanyIsActive(mo).Result) + .WithMessage("این موبایل قبلا ثبت شده"); + } + } +} diff --git a/Shared/DTOs/Authentication.cs b/Shared/DTOs/Authentication.cs new file mode 100644 index 0000000..1a921dc --- /dev/null +++ b/Shared/DTOs/Authentication.cs @@ -0,0 +1,8 @@ +namespace Shared.DTOs +{ + public class Authentication + { + public string Username { get; set; } + public string Password { get; set; } + } +} diff --git a/Shared/DTOs/CompanyAuthenticationDTO.cs b/Shared/DTOs/CompanyAuthenticationDTO.cs new file mode 100644 index 0000000..426ef64 --- /dev/null +++ b/Shared/DTOs/CompanyAuthenticationDTO.cs @@ -0,0 +1,12 @@ +namespace Shared.DTOs +{ + public class CompanyAuthenticationDTO + { + public int ID { get; set; } + public string Name { get; set; } + public string? Logo { get; set; } + public bool IsAdmin { get; set; } + // public ICollection permissions { get; set; } = new List(); + + } +} diff --git a/Shared/DTOs/CompanyDTO.cs b/Shared/DTOs/CompanyDTO.cs new file mode 100644 index 0000000..c9da859 --- /dev/null +++ b/Shared/DTOs/CompanyDTO.cs @@ -0,0 +1,17 @@ +namespace Shared.DTOs +{ + public class CompanyDTO + { + public int ID { get; set; } + public string Name { get; set; } + public string? Email { get; set; } + public string? Phone { get; set; } + public string Mobile { get; set; } + public string BranchID { get; set; } + public string? EconomicCode { get; set; } + public string? UniqeMemory { get; set; } + public string? PrivateKey { get; set; } + public string? Logo { get; set; } + + } +} diff --git a/Shared/DTOs/CompanyRegistrationDTO.cs b/Shared/DTOs/CompanyRegistrationDTO.cs new file mode 100644 index 0000000..d3d212c --- /dev/null +++ b/Shared/DTOs/CompanyRegistrationDTO.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; + +namespace Shared.DTOs +{ + public class CompanyRegistrationDTO + { + [MinLength(5)] + public string CompanyName { get; set; } + public string FullnameUser { get { return CompanyName; } } + public string Mobile { get; set; } + public string Username { get { return Mobile; } } + } +} diff --git a/Shared/DTOs/DashBoardDTO.cs b/Shared/DTOs/DashBoardDTO.cs new file mode 100644 index 0000000..65136f9 --- /dev/null +++ b/Shared/DTOs/DashBoardDTO.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +namespace Shared.DTOs +{ + public class AlertDTO + { + public int Status { get; set; } + public string Message { get; set; } + public string? Path { get; set; } + public string? ViewSize { get; set; } + } + public class DashBoardDTO + { + public string? LastLoginDate { get; set; } + public List AlistofServices { get; set; }=new List(); + public List Warning { get; set; } = new List(); + public List Notifications { get; set; } = new List(); + } + public class ServiceInDashBoardDTO + { + public int PermissionID { get; set; } + public string PermissionName { get; set; } + public int CalTypeID { get; set; } + public string CalTypeTitle { get; set; } + public string Total { get; set; } + public string Remaining { get; set; } + } +} diff --git a/Shared/DTOs/PermissionAuthenticationDTO.cs b/Shared/DTOs/PermissionAuthenticationDTO.cs new file mode 100644 index 0000000..c196a1a --- /dev/null +++ b/Shared/DTOs/PermissionAuthenticationDTO.cs @@ -0,0 +1,11 @@ +namespace Shared.DTOs +{ + public class PermissionAuthenticationDTO + { + public int ID { get; set; } + public int ParentID { get; set; } + public string Title { get; set; } + public bool accessibility { get; set; } + public List ChildPermissions { get; set; } + } +} diff --git a/Shared/DTOs/UserAuthenticationDTO.cs b/Shared/DTOs/UserAuthenticationDTO.cs new file mode 100644 index 0000000..e2c7865 --- /dev/null +++ b/Shared/DTOs/UserAuthenticationDTO.cs @@ -0,0 +1,14 @@ +using System.Security.Principal; + +namespace Shared.DTOs +{ + public class UserAuthenticationDTO + { + + public string FullName { get; set; } + public string Token { get; set; } + public string Photo { get; set; } + public ICollection Companies { get; set; } = new List(); + + } +} diff --git a/TaxPayerFull/Layout/Contact.razor b/TaxPayerFull/Layout/Contact.razor index d745f0f..c07751e 100644 --- a/TaxPayerFull/Layout/Contact.razor +++ b/TaxPayerFull/Layout/Contact.razor @@ -42,13 +42,13 @@
- + نام شما
- + موبایل
@@ -103,6 +103,7 @@ } } @functions{ + private async Task OnClearmessageStore() => messageStore?.Clear(); private async Task newTicket(){ var request = await _hc.PostAsJsonAsync("Ticket/NewTicketNoAuthentication", model); diff --git a/TaxPayerFull/Pages/Register.razor b/TaxPayerFull/Pages/Register.razor index ba26682..e520c62 100644 --- a/TaxPayerFull/Pages/Register.razor +++ b/TaxPayerFull/Pages/Register.razor @@ -1,4 +1,7 @@ @page "/Register" +@using Shared.DTOs +@inject HttpClient _hc +@inject NavigationManager nav ثبت نام
@@ -10,9 +13,9 @@