Generator Changes at 9/27/2025 11:07:17 PM

This commit is contained in:
MeysamMoghaddam
2025-09-27 23:48:41 +03:30
parent 447e580a8a
commit a1b6e28d35
45 changed files with 1320 additions and 18 deletions

View File

@@ -0,0 +1,38 @@
using System.Security.Cryptography;
namespace CMSMicroservice.Application.Common.Extensions;
public static class UtilExtensions
{
public static string NormalizeIranMobile(this string input)
{
if (string.IsNullOrWhiteSpace(input)) throw new ArgumentException("mobile is empty");
var m = new string(input.Where(char.IsDigit).ToArray());
if (m.StartsWith("0098")) m = m[4..];
else if (m.StartsWith("098")) m = m[3..];
else if (m.StartsWith("98")) m = m[2..];
if (!m.StartsWith("0")) m = "0" + m;
if (m.Length != 11 || !m.StartsWith("09"))
throw new ArgumentException("شماره موبایل نامعتبر است.");
return m;
}
public static string Generate(int digits = 10, bool firstDigitNonZero = false)
{
if (digits <= 0) throw new ArgumentOutOfRangeException(nameof(digits));
var chars = new char[digits];
// رقم اول
if (firstDigitNonZero)
chars[0] = (char)('0' + RandomNumberGenerator.GetInt32(1, 10)); // 1..9
else
chars[0] = (char)('0' + RandomNumberGenerator.GetInt32(10)); // 0..9
// بقیه ارقام
for (int i = 1; i < digits; i++)
chars[i] = (char)('0' + RandomNumberGenerator.GetInt32(10));
return new string(chars);
}
}

View File

@@ -2,11 +2,12 @@ namespace CMSMicroservice.Application.Common.Interfaces;
public interface IApplicationDbContext
{
DbSet<User> Users { get; }
DbSet<UserAddress> UserAddresss { get; }
DbSet<Package> Packages { get; }
DbSet<UserOrder> UserOrders { get; }
DbSet<Role> Roles { get; }
DbSet<UserRole> UserRoles { get; }
DbSet<User> Users { get; }
DbSet<OtpToken> OtpTokens { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.Application.Common.Mappings;
public class OtpTokenProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
}
}