Merge branch 'master' into Feature/customize-checkout/pizza-amir

This commit is contained in:
2025-11-20 15:21:06 +03:30
171 changed files with 584331 additions and 3454 deletions

View File

@@ -1,13 +1,11 @@
using System;
using System.IO;
using AccountManagement.Domain.TaskAgg;
using ApkReader;
using Company.Domain.AndroidApkVersionAgg;
using CompanyManagment.App.Contracts.AndroidApkVersion;
using CompanyManagment.Application.Helpers;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.IO;
using System.Threading.Tasks;
using _0_Framework.Application;
@@ -24,7 +22,7 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
_taskRepository = taskRepository;
}
public async Task<OperationResult> CreateAndActive(IFormFile file)
public async Task<OperationResult> CreateAndActive(IFormFile file, ApkType apkType, string versionName, string versionCode, bool isForce = false)
{
OperationResult op = new OperationResult();
@@ -36,22 +34,26 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
if (Path.GetExtension(file.FileName).ToLower() != ".apk")
return op.Failed("لطفا فایلی با پسوند .apk وارد کنید");
if (string.IsNullOrWhiteSpace(versionName))
return op.Failed("لطفا نام ورژن را وارد کنید");
if (string.IsNullOrWhiteSpace(versionCode))
return op.Failed("لطفا کد ورژن را وارد کنید");
#endregion
var activeApks = _androidApkVersionRepository.GetActives();
var activeApks = _androidApkVersionRepository.GetActives(apkType);
await activeApks.ExecuteUpdateAsync(setter => setter.SetProperty(e => e.IsActive, IsActive.False));
_androidApkVersionRepository.SaveChanges();
var folderName = apkType == ApkType.WebView ? "GozreshgirWebView" : "GozreshgirFaceDetection";
var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage",
"Apk", "Android", "GozreshgirWebView");
"Apk", "Android", folderName);
Directory.CreateDirectory(path);
//var apk = new ApkReader.ApkReader().Read(file.OpenReadStream());
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}{Path.GetExtension(file.FileName)}";
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}.v{versionName}{Path.GetExtension(file.FileName)}";
string filepath = Path.Combine(path, uniqueFileName);
@@ -60,13 +62,13 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
await file.CopyToAsync(stream);
}
var entity = new AndroidApkVersion("0", "0", IsActive.True, filepath);
var entity = new AndroidApkVersion(versionName, versionCode, IsActive.True, filepath,apkType,isForce);
_androidApkVersionRepository.Create(entity);
_androidApkVersionRepository.SaveChanges();
return op.Succcedded();
}
public async Task<OperationResult> CreateAndDeActive(IFormFile file)
public async Task<OperationResult> CreateAndDeActive(IFormFile file, ApkType apkType, string versionName, string versionCode, bool isForce = false)
{
OperationResult op = new OperationResult();
@@ -78,18 +80,22 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
if (Path.GetExtension(file.FileName).ToLower() != ".apk")
return op.Failed("لطفا فایلی با پسوند .apk وارد کنید");
if (string.IsNullOrWhiteSpace(versionName))
return op.Failed("لطفا نام ورژن را وارد کنید");
if (string.IsNullOrWhiteSpace(versionCode))
return op.Failed("لطفا کد ورژن را وارد کنید");
#endregion
var folderName = apkType == ApkType.WebView ? "GozreshgirWebView" : "GozreshgirFaceDetection";
var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage",
"Apk", "Android", "GozreshgirWebView");
"Apk", "Android", folderName);
Directory.CreateDirectory(path);
var apk = new ApkReader.ApkReader().Read(file.OpenReadStream());
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}.v{apk.VersionName}{Path.GetExtension(file.FileName)}";
string uniqueFileName = $"{Path.GetFileNameWithoutExtension(file.FileName)}.v{versionName}{Path.GetExtension(file.FileName)}";
string filepath = Path.Combine(path, uniqueFileName);
@@ -98,14 +104,15 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
await file.CopyToAsync(stream);
}
var entity = new AndroidApkVersion(apk.VersionName, apk.VersionCode, IsActive.False, filepath);
var entity = new AndroidApkVersion(versionName, versionCode, IsActive.False, filepath,apkType);
_androidApkVersionRepository.Create(entity);
_androidApkVersionRepository.SaveChanges();
return op.Succcedded();
}
public async Task<string> GetLatestActiveVersionPath()
public async Task<string> GetLatestActiveVersionPath(ApkType apkType)
{
return await _androidApkVersionRepository.GetLatestActiveVersionPath();
return await _androidApkVersionRepository.GetLatestActiveVersionPath(apkType);
}
public OperationResult Remove(long id)
@@ -127,8 +134,22 @@ public class AndroidApkVersionApplication : IAndroidApkVersionApplication
return op.Succcedded();
}
public bool HasAndroidApkToDownload()
public bool HasAndroidApkToDownload(ApkType apkType)
{
return _androidApkVersionRepository.Exists(x => x.IsActive == IsActive.True);
return _androidApkVersionRepository.Exists(x => x.IsActive == IsActive.True && x.ApkType == apkType);
}
public Task<AndroidApkVersionInfo> GetLatestActiveInfo(ApkType apkType, int currentVersionCode)
{
var latest = _androidApkVersionRepository.GetLatestActive(apkType);
if (latest == null)
return Task.FromResult(new AndroidApkVersionInfo(0, "0", false, false, string.Empty, string.Empty));
// Return API endpoint for downloading APK file
var fileUrl = $"/api/android-apk/download?type={apkType}";
int latestCode = 0;
int.TryParse(latest.VersionCode, out latestCode);
var shouldUpdate = latestCode > currentVersionCode;
return Task.FromResult(new AndroidApkVersionInfo(latestCode, latest.VersionName, shouldUpdate, latest.IsForce, fileUrl, "Bug fixes and improvements"));
}
}

View File

@@ -5,7 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ApkReader" Version="2.0.1.1" />
<PackageReference Include="AndroidXml" Version="1.1.24" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -31,6 +31,7 @@ using Company.Domain.LeftWorkAgg;
using CompanyManagment.App.Contracts.Employee.DTO;
using Company.Domain.EmployeeAuthorizeTempAgg;
using Company.Domain.LeftWorkInsuranceAgg;
using _0_Framework.Application.FaceEmbedding;
namespace CompanyManagment.Application;
@@ -61,29 +62,31 @@ public class EmployeeAplication : RepositoryBase<long, Employee>, IEmployeeAppli
private readonly ICustomizeWorkshopGroupSettingsRepository _customizeWorkshopGroupSettingsRepository;
private readonly IEmployeeAuthorizeTempRepository _employeeAuthorizeTempRepository;
private readonly ILeftWorkInsuranceRepository _leftWorkInsuranceRepository;
private readonly IFaceEmbeddingService _faceEmbeddingService;
public EmployeeAplication(IEmployeeRepository employeeRepository, CompanyContext context, IWorkshopRepository workShopRepository, IWebHostEnvironment webHostEnvironment, IRollCallEmployeeStatusApplication rollCallEmployeeStatusApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, ICustomizeWorkshopSettingsApplication customizeWorkshopSettingsApplication, IEmployeeDocumentsApplication employeeDocumentsApplication, IEmployeeDocumentsRepository employeeDocumentsRepository, IEmployeeBankInformationApplication employeeBankInformationApplication, ILeftWorkTempRepository leftWorkTempRepository, IUidService uidService, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, IPersonnelCodeRepository personnelCodeRepository, IEmployeeClientTempRepository employeeClientTempRepository, ICustomizeWorkshopGroupSettingsRepository customizeWorkshopGroupSettingsRepository, ILeftWorkRepository leftWorkRepository, IEmployeeAuthorizeTempRepository employeeAuthorizeTempRepository, ILeftWorkInsuranceRepository leftWorkInsuranceRepository) : base(context)
{
_context = context;
_WorkShopRepository = workShopRepository;
_webHostEnvironment = webHostEnvironment;
_rollCallEmployeeStatusApplication = rollCallEmployeeStatusApplication;
_rollCallEmployeeRepository = rollCallEmployeeRepository;
_customizeWorkshopSettingsApplication = customizeWorkshopSettingsApplication;
_employeeDocumentsApplication = employeeDocumentsApplication;
_employeeBankInformationApplication = employeeBankInformationApplication;
_leftWorkTempRepository = leftWorkTempRepository;
_uidService = uidService;
_customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository;
_personnelCodeRepository = personnelCodeRepository;
_employeeClientTempRepository = employeeClientTempRepository;
_leftWorkRepository = leftWorkRepository;
_employeeAuthorizeTempRepository = employeeAuthorizeTempRepository;
_leftWorkInsuranceRepository = leftWorkInsuranceRepository;
_EmployeeRepository = employeeRepository;
}
public EmployeeAplication(IEmployeeRepository employeeRepository, CompanyContext context, IWorkshopRepository workShopRepository, IWebHostEnvironment webHostEnvironment, IRollCallEmployeeStatusApplication rollCallEmployeeStatusApplication, IRollCallEmployeeRepository rollCallEmployeeRepository, ICustomizeWorkshopSettingsApplication customizeWorkshopSettingsApplication, IEmployeeDocumentsApplication employeeDocumentsApplication, IEmployeeDocumentsRepository employeeDocumentsRepository, IEmployeeBankInformationApplication employeeBankInformationApplication, ILeftWorkTempRepository leftWorkTempRepository, IUidService uidService, ICustomizeWorkshopEmployeeSettingsRepository customizeWorkshopEmployeeSettingsRepository, IPersonnelCodeRepository personnelCodeRepository, IEmployeeClientTempRepository employeeClientTempRepository, ICustomizeWorkshopGroupSettingsRepository customizeWorkshopGroupSettingsRepository, ILeftWorkRepository leftWorkRepository, IEmployeeAuthorizeTempRepository employeeAuthorizeTempRepository, ILeftWorkInsuranceRepository leftWorkInsuranceRepository, IFaceEmbeddingService faceEmbeddingService) : base(context)
{
_context = context;
_WorkShopRepository = workShopRepository;
_webHostEnvironment = webHostEnvironment;
_rollCallEmployeeStatusApplication = rollCallEmployeeStatusApplication;
_rollCallEmployeeRepository = rollCallEmployeeRepository;
_customizeWorkshopSettingsApplication = customizeWorkshopSettingsApplication;
_employeeDocumentsApplication = employeeDocumentsApplication;
_employeeBankInformationApplication = employeeBankInformationApplication;
_leftWorkTempRepository = leftWorkTempRepository;
_uidService = uidService;
_customizeWorkshopEmployeeSettingsRepository = customizeWorkshopEmployeeSettingsRepository;
_personnelCodeRepository = personnelCodeRepository;
_employeeClientTempRepository = employeeClientTempRepository;
_leftWorkRepository = leftWorkRepository;
_employeeAuthorizeTempRepository = employeeAuthorizeTempRepository;
_leftWorkInsuranceRepository = leftWorkInsuranceRepository;
_EmployeeRepository = employeeRepository;
_faceEmbeddingService = faceEmbeddingService;
}
public OperationResult Create(CreateEmployee command)
public OperationResult Create(CreateEmployee command)
{
var opration = new OperationResult();
if (_EmployeeRepository.Exists(x =>
@@ -1122,6 +1125,12 @@ public class EmployeeAplication : RepositoryBase<long, Employee>, IEmployeeAppli
rollCallEmployee.HasImage();
_rollCallEmployeeRepository.Create(rollCallEmployee);
_rollCallEmployeeRepository.SaveChanges();
string employeeFullName = employee.FName + " " + employee.LName;
var res = _faceEmbeddingService.GenerateEmbeddingsAsync(employee.id,command.WorkshopId,employeeFullName, filePath1,filePath2).GetAwaiter().GetResult();
if (!res.IsSuccedded)
{
return op.Failed(res.Message);
}
}

View File

@@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Company.Domain.EmployeeFaceEmbeddingAgg;
using CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
namespace CompanyManagment.Application;
public class EmployeeFaceEmbeddingApplication : IEmployeeFaceEmbeddingApplication
{
private readonly IEmployeeFaceEmbeddingRepository _repository;
public EmployeeFaceEmbeddingApplication(IEmployeeFaceEmbeddingRepository repository)
{
_repository = repository;
}
public async Task<EmployeeFaceEmbeddingDto> GetByIdAsync(string id)
{
var entity = await _repository.GetByIdAsync(id);
return entity == null ? null : MapToDto(entity);
}
public async Task<EmployeeFaceEmbeddingDto> GetByEmployeeIdAsync(long employeeId)
{
var entity = await _repository.GetByEmployeeIdAsync(employeeId);
return entity == null ? null : MapToDto(entity);
}
public async Task<List<EmployeeFaceEmbeddingDto>> GetByWorkshopIdAsync(long workshopId)
{
var entities = await _repository.GetByWorkshopIdAsync(workshopId);
return entities.Select(MapToDto).ToList();
}
public async Task<List<EmployeeFaceEmbeddingDto>> GetByWorkshopIdsAsync(List<long> workshopIds)
{
var entities = await _repository.GetByWorkshopIdsAsync(workshopIds);
return entities.Select(MapToDto).ToList();
}
public async Task<string> SaveAsync(EmployeeFaceEmbeddingDto dto)
{
if (string.IsNullOrWhiteSpace(dto.Id))
{
// ایجاد جدید
var metadata = MapMetadataFromDto(dto.Metadata);
var entity = new EmployeeFaceEmbedding(
dto.EmployeeFullName,
dto.EmployeeId,
dto.WorkshopId,
dto.Embeddings,
metadata
);
await _repository.CreateAsync(entity);
return entity.Id;
}
else
{
// به‌روزرسانی
var entity = await _repository.GetByIdAsync(dto.Id);
if (entity == null)
throw new Exception($"EmployeeFaceEmbedding با شناسه {dto.Id} یافت نشد");
entity.UpdateEmployeeInfo(dto.EmployeeFullName, dto.WorkshopId);
entity.UpdateEmbedding(dto.Embeddings, 0, 0);
entity.UpdateMetadata(MapMetadataFromDto(dto.Metadata), 0, 0);
await _repository.UpdateAsync(entity);
return entity.Id;
}
}
public async Task DeleteAsync(string id)
{
await _repository.DeleteAsync(id);
}
#region Mapping Methods
private EmployeeFaceEmbeddingDto MapToDto(EmployeeFaceEmbedding entity)
{
return new EmployeeFaceEmbeddingDto
{
Id = entity.Id,
EmployeeFullName = entity.EmployeeFullName,
EmployeeId = entity.EmployeeId,
WorkshopId = entity.WorkshopId,
Embeddings = entity.Embeddings,
Metadata = MapMetadataToDto(entity.Metadata)
};
}
private EmployeeFaceEmbeddingMetadataDto MapMetadataToDto(EmployeeFaceEmbeddingMetadata metadata)
{
if (metadata == null) return null;
return new EmployeeFaceEmbeddingMetadataDto
{
AvgEyeDistanceNormalized = metadata.AvgEyeDistanceNormalized,
AvgEyeToFaceRatio = metadata.AvgEyeToFaceRatio,
AvgFaceAspectRatio = metadata.AvgFaceAspectRatio,
AvgDetectionConfidence = metadata.AvgDetectionConfidence,
AvgKeypointsNormalized = MapKeypointsToDto(metadata.AvgKeypointsNormalized),
PerImageMetadata = metadata.PerImageMetadata?.Select(x => new ImageMetadataDto
{
FaceAspectRatio = x.FaceAspectRatio,
EyeDistanceNormalized = x.EyeDistanceNormalized,
EyeToFaceRatio = x.EyeToFaceRatio,
DetectionConfidence = x.DetectionConfidence,
KeypointsNormalized = MapKeypointsToDto(x.KeypointsNormalized)
}).ToList()
};
}
private EmployeeFaceEmbeddingKeypointsDto MapKeypointsToDto(EmployeeFaceEmbeddingKeypoints keypoints)
{
if (keypoints == null) return null;
return new EmployeeFaceEmbeddingKeypointsDto
{
LeftEye = keypoints.LeftEye,
RightEye = keypoints.RightEye,
Nose = keypoints.Nose,
MouthLeft = keypoints.MouthLeft,
MouthRight = keypoints.MouthRight
};
}
private EmployeeFaceEmbeddingMetadata MapMetadataFromDto(EmployeeFaceEmbeddingMetadataDto dto)
{
if (dto == null) return null;
return new EmployeeFaceEmbeddingMetadata
{
AvgEyeDistanceNormalized = dto.AvgEyeDistanceNormalized,
AvgEyeToFaceRatio = dto.AvgEyeToFaceRatio,
AvgFaceAspectRatio = dto.AvgFaceAspectRatio,
AvgDetectionConfidence = dto.AvgDetectionConfidence,
AvgKeypointsNormalized = MapKeypointsFromDto(dto.AvgKeypointsNormalized),
PerImageMetadata = dto.PerImageMetadata?.Select(x => new ImageMetadata
{
FaceAspectRatio = x.FaceAspectRatio,
EyeDistanceNormalized = x.EyeDistanceNormalized,
EyeToFaceRatio = x.EyeToFaceRatio,
DetectionConfidence = x.DetectionConfidence,
KeypointsNormalized = MapKeypointsFromDto(x.KeypointsNormalized)
}).ToList()
};
}
private EmployeeFaceEmbeddingKeypoints MapKeypointsFromDto(EmployeeFaceEmbeddingKeypointsDto dto)
{
if (dto == null) return null;
return new EmployeeFaceEmbeddingKeypoints
{
LeftEye = dto.LeftEye,
RightEye = dto.RightEye,
Nose = dto.Nose,
MouthLeft = dto.MouthLeft,
MouthRight = dto.MouthRight
};
}
#endregion
}

View File

@@ -0,0 +1,214 @@
using System;
using System.Collections.Generic;
using System.Linq;
using _0_Framework.Application;
using _0_Framework.InfraStructure;
using Company.Domain.FinancialInvoiceAgg;
using CompanyManagment.App.Contracts.FinancialInvoice;
using CompanyManagment.EFCore;
namespace CompanyManagment.Application;
public class FinancialInvoiceApplication : RepositoryBase<long, FinancialInvoice>, IFinancialInvoiceApplication
{
private readonly IFinancialInvoiceRepository _financialInvoiceRepository;
private readonly CompanyContext _context;
public FinancialInvoiceApplication(IFinancialInvoiceRepository financialInvoiceRepository, CompanyContext context) : base(context)
{
_financialInvoiceRepository = financialInvoiceRepository;
_context = context;
}
public OperationResult Create(CreateFinancialInvoice command)
{
var operation = new OperationResult();
if (command.Amount <= 0)
return operation.Failed("مبلغ فاکتور باید بزرگتر از صفر باشد");
if (command.ContractingPartyId <= 0)
return operation.Failed("طرف قرارداد نامعتبر است");
if (string.IsNullOrWhiteSpace(command.Description))
return operation.Failed("توضیحات فاکتور الزامی است");
var financialInvoice = new FinancialInvoice(command.Amount, command.ContractingPartyId, command.Description);
if (command.Items != null && command.Items.Any())
{
foreach (var item in command.Items)
{
if (string.IsNullOrWhiteSpace(item.Description))
return operation.Failed("توضیحات آیتم الزامی است");
if (item.Amount <= 0)
return operation.Failed("مبلغ آیتم باید بزرگتر از صفر باشد");
var invoiceItem = new FinancialInvoiceItem(item.Description, item.Amount,
financialInvoice.id, item.Type, item.EntityId);
financialInvoice.AddItem(invoiceItem);
}
}
_financialInvoiceRepository.Create(financialInvoice);
_financialInvoiceRepository.SaveChanges();
return operation.Succcedded();
}
public OperationResult Edit(EditFinancialInvoice command)
{
var operation = new OperationResult();
var financialInvoice = _financialInvoiceRepository.Get(command.Id);
if (financialInvoice == null)
return operation.Failed("فاکتور مورد نظر یافت نشد");
if (financialInvoice.Status == FinancialInvoiceStatus.Paid)
return operation.Failed("امکان ویرایش فاکتور پرداخت شده وجود ندارد");
if (string.IsNullOrWhiteSpace(command.Description))
return operation.Failed("توضیحات فاکتور الزامی است");
// Update description
financialInvoice.Description = command.Description;
// Update items if provided
if (command.Items != null)
{
// Clear existing items
if (financialInvoice.Items != null)
{
financialInvoice.Items.Clear();
}
else
{
financialInvoice.SetItems([]);
}
// Add updated items
foreach (var item in command.Items)
{
if (string.IsNullOrWhiteSpace(item.Description))
return operation.Failed("توضیحات آیتم الزامی است");
if (item.Amount <= 0)
return operation.Failed("مبلغ آیتم باید بزرگتر از صفر باشد");
var invoiceItem = new FinancialInvoiceItem(item.Description, item.Amount,
financialInvoice.id, item.Type, item.EntityId);
financialInvoice.AddItem(invoiceItem);
}
}
_financialInvoiceRepository.SaveChanges();
return operation.Succcedded();
}
public OperationResult SetPaid(long id, DateTime paidAt)
{
var operation = new OperationResult();
var financialInvoice = _financialInvoiceRepository.Get(id);
if (financialInvoice == null)
return operation.Failed("فاکتور مورد نظر یافت نشد");
if (financialInvoice.Status == FinancialInvoiceStatus.Paid)
return operation.Failed("فاکتور قبلاً پرداخت شده است");
if (financialInvoice.Status == FinancialInvoiceStatus.Cancelled)
return operation.Failed("امکان پرداخت فاکتور لغو شده وجود ندارد");
financialInvoice.SetPaid(paidAt);
_financialInvoiceRepository.SaveChanges();
return operation.Succcedded();
}
public OperationResult SetUnpaid(long id)
{
var operation = new OperationResult();
var financialInvoice = _financialInvoiceRepository.Get(id);
if (financialInvoice == null)
return operation.Failed("فاکتور مورد نظر یافت نشد");
financialInvoice.SetUnpaid();
_financialInvoiceRepository.SaveChanges();
return operation.Succcedded();
}
public OperationResult SetCancelled(long id)
{
var operation = new OperationResult();
var financialInvoice = _financialInvoiceRepository.Get(id);
if (financialInvoice == null)
return operation.Failed("فاکتور مورد نظر یافت نشد");
if (financialInvoice.Status == FinancialInvoiceStatus.Paid)
return operation.Failed("امکان لغو فاکتور پرداخت شده وجود ندارد");
financialInvoice.SetCancelled();
_financialInvoiceRepository.SaveChanges();
return operation.Succcedded();
}
public OperationResult SetRefunded(long id)
{
var operation = new OperationResult();
var financialInvoice = _financialInvoiceRepository.Get(id);
if (financialInvoice == null)
return operation.Failed("فاکتور مورد نظر یافت نشد");
if (financialInvoice.Status != FinancialInvoiceStatus.Paid)
return operation.Failed("فقط فاکتورهای پرداخت شده قابل بازپرداخت هستند");
financialInvoice.SetRefunded();
_financialInvoiceRepository.SaveChanges();
return operation.Succcedded();
}
public EditFinancialInvoice GetDetails(long id)
{
return _financialInvoiceRepository.GetDetails(id);
}
public List<FinancialInvoiceViewModel> Search(FinancialInvoiceSearchModel searchModel)
{
return _financialInvoiceRepository.Search(searchModel);
}
//public OperationResult Remove(long id)
//{
// var operation = new OperationResult();
// try
// {
// var financialInvoice = _financialInvoiceRepository.Get(id);
// if (financialInvoice == null)
// return operation.Failed("فاکتور مورد نظر یافت نشد");
// if (financialInvoice.Status == FinancialInvoiceStatus.Paid)
// return operation.Failed("امکان حذف فاکتور پرداخت شده وجود ندارد");
// // Remove the entity using the context directly since Remove method might not be available
// _context.FinancialInvoiceSet.Remove(financialInvoice);
// _financialInvoiceRepository.SaveChanges();
// return operation.Succcedded();
// }
// catch (Exception ex)
// {
// return operation.Failed("خطا در حذف فاکتور");
// }
//}
}

View File

@@ -0,0 +1,132 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Text.RegularExpressions;
namespace CompanyManagment.Application.Helpers
{
public class ApkInfo
{
public string VersionName { get; set; } = string.Empty;
public string VersionCode { get; set; } = string.Empty;
public string PackageName { get; set; } = string.Empty;
public string ApplicationLabel { get; set; } = string.Empty;
}
public static class ApkHelper
{
public static ApkInfo ReadApkInfo(Stream apkStream)
{
var apkInfo = new ApkInfo();
try
{
using var archive = new ZipArchive(apkStream, ZipArchiveMode.Read, true);
var manifestEntry = archive.GetEntry("AndroidManifest.xml");
if (manifestEntry == null)
{
throw new InvalidOperationException("AndroidManifest.xml not found in APK file");
}
using var manifestStream = manifestEntry.Open();
using var memoryStream = new MemoryStream();
manifestStream.CopyTo(memoryStream);
var manifestBytes = memoryStream.ToArray();
// Parse the binary AndroidManifest.xml
apkInfo = ParseBinaryManifest(manifestBytes);
// Validate that we found at least version information
if (string.IsNullOrEmpty(apkInfo.VersionCode) && string.IsNullOrEmpty(apkInfo.VersionName))
{
throw new InvalidOperationException("Could not extract version information from APK");
}
return apkInfo;
}
catch (Exception ex)
{
throw new InvalidOperationException($"Error reading APK file: {ex.Message}", ex);
}
}
private static ApkInfo ParseBinaryManifest(byte[] manifestBytes)
{
var apkInfo = new ApkInfo();
try
{
// Convert bytes to string for regex parsing
var text = System.Text.Encoding.UTF8.GetString(manifestBytes);
// Extract package name
var packageMatch = Regex.Match(text, @"package[^a-zA-Z]+([a-zA-Z][a-zA-Z0-9_]*(?:\.[a-zA-Z][a-zA-Z0-9_]*)+)", RegexOptions.IgnoreCase);
if (packageMatch.Success)
{
apkInfo.PackageName = packageMatch.Groups[1].Value;
}
// Extract version code - look for numeric values that could be version codes
var versionCodeMatch = Regex.Match(text, @"versionCode[^\d]*(\d+)", RegexOptions.IgnoreCase);
if (versionCodeMatch.Success)
{
apkInfo.VersionCode = versionCodeMatch.Groups[1].Value;
}
else
{
// Fallback: try to find reasonable numeric values
var numbers = Regex.Matches(text, @"\b(\d{1,8})\b");
foreach (Match numMatch in numbers)
{
if (int.TryParse(numMatch.Groups[1].Value, out int num) && num > 0 && num < 99999999)
{
apkInfo.VersionCode = num.ToString();
break;
}
}
}
// Extract version name
var versionNameMatch = Regex.Match(text, @"versionName[^\d]*(\d+(?:\.\d+)*(?:\.\d+)*)", RegexOptions.IgnoreCase);
if (versionNameMatch.Success)
{
apkInfo.VersionName = versionNameMatch.Groups[1].Value;
}
else
{
// Fallback: look for version-like patterns
var versionMatch = Regex.Match(text, @"\b(\d+\.\d+(?:\.\d+)*)\b");
if (versionMatch.Success)
{
apkInfo.VersionName = versionMatch.Groups[1].Value;
}
}
// Set defaults if nothing found
if (string.IsNullOrEmpty(apkInfo.VersionCode))
apkInfo.VersionCode = "1";
if (string.IsNullOrEmpty(apkInfo.VersionName))
apkInfo.VersionName = "1.0";
if (string.IsNullOrEmpty(apkInfo.PackageName))
apkInfo.PackageName = "unknown.package";
return apkInfo;
}
catch (Exception)
{
// Return default values if parsing fails
return new ApkInfo
{
VersionCode = "1",
VersionName = "1.0",
PackageName = "unknown.package"
};
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -50,7 +50,7 @@ public class PaymentTransactionApplication : IPaymentTransactionApplication
command.ContractingPartyId,
command.Amount,
contractingPartyName,
command.CallBackUrl);
command.CallBackUrl,command.Gateway);
await _paymentTransactionRepository.CreateAsync(entity);
await _paymentTransactionRepository.SaveChangesAsync();
@@ -87,7 +87,7 @@ public class PaymentTransactionApplication : IPaymentTransactionApplication
return op.Succcedded();
}
public OperationResult SetSuccess(long paymentTransactionId,string cardNumber, string bankName)
public OperationResult SetSuccess(long paymentTransactionId,string cardNumber, string bankName, string rrn, string digitalReceipt)
{
var op = new OperationResult();
@@ -97,7 +97,7 @@ public class PaymentTransactionApplication : IPaymentTransactionApplication
{
return op.Failed("تراکنش مورد نظر یافت نشد");
}
paymentTransaction.SetPaid(cardNumber, bankName);
paymentTransaction.SetPaid(cardNumber, bankName,rrn, digitalReceipt);
_paymentTransactionRepository.SaveChanges();
return op.Succcedded();

View File

@@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using _0_Framework.Application;
using _0_Framework.Application.Enums;
using Company.Domain.InstitutionContractAgg;
using Company.Domain.SmsResultAgg;
using CompanyManagment.App.Contracts.InstitutionContract;
using CompanyManagment.App.Contracts.SmsResult;
namespace CompanyManagment.Application;
public class SmsSettingApplication : ISmsSettingApplication
{
private readonly ISmsSettingsRepository _smsSettingsRepository;
private readonly IInstitutionContractRepository _institutionContractRepository;
public SmsSettingApplication(ISmsSettingsRepository smsSettingsRepository, IInstitutionContractRepository institutionContractRepository)
{
_smsSettingsRepository = smsSettingsRepository;
_institutionContractRepository = institutionContractRepository;
}
public async Task<SmsSettingViewModel> GetSmsSettingsByType(TypeOfSmsSetting typeOfSmsSetting)
{
return await _smsSettingsRepository.GetSmsSettingsByType(typeOfSmsSetting);
}
/// <summary>
/// ایجاد تنظیمات پیامک یادآور
/// </summary>
/// <param name="dayOfMonth"></param>
/// <param name="timeOfDay"></param>
/// <param name="typeOfSmsSetting"></param>
/// <returns></returns>
public async Task<OperationResult> CreateSmsSetting(int dayOfMonth, string timeOfDay,
TypeOfSmsSetting typeOfSmsSetting)
{
var op = new OperationResult();
var timeSpan = new TimeSpan();
if (string.IsNullOrWhiteSpace(timeOfDay))
return op.Failed("ساعت وارد نشده است");
try
{
timeSpan = TimeSpan.ParseExact(timeOfDay, @"hh\:mm", null);
}
catch (Exception e)
{
return op.Failed("فرمت ساعت اشتباه است");
}
if (dayOfMonth < 1 || dayOfMonth > 31)
{
return op.Failed("عدد روز می بایست بین 1 تا 31 باشد");
}
if (_smsSettingsRepository.Exists(x => x.DayOfMonth == dayOfMonth && x.TimeOfDay == timeSpan && x.TypeOfSmsSetting == typeOfSmsSetting))
return op.Failed("رکورد ایجاد شده تکراری است");
var create = new SmsSetting(typeOfSmsSetting, dayOfMonth, timeSpan);
await _smsSettingsRepository.CreateAsync(create);
await _smsSettingsRepository.SaveChangesAsync();
return op.Succcedded();
}
public async Task<EditSmsSetting> GetSmsSettingToEdit(long id)
{
return await _smsSettingsRepository.GetSmsSettingToEdit(id);
}
public async Task<OperationResult> EditeSmsSetting(EditSmsSetting command)
{
var op = new OperationResult();
var timeSpan = new TimeSpan();
if (string.IsNullOrWhiteSpace(command.TimeOfDayDisplay))
return op.Failed("ساعت وارد نشده است");
try
{
timeSpan = TimeSpan.ParseExact(command.TimeOfDayDisplay, @"hh\:mm", null);
}
catch (Exception e)
{
return op.Failed("فرمت ساعت اشتباه است");
}
if (command.DayOfMonth < 1 || command.DayOfMonth > 31)
{
return op.Failed("عدد روز می بایست بین 1 تا 31 باشد");
}
if (_smsSettingsRepository.Exists(x => x.DayOfMonth == command.DayOfMonth && x.TimeOfDay == timeSpan && x.TypeOfSmsSetting == command.TypeOfSmsSetting && x.id != command.Id))
return op.Failed("رکورد ایجاد شده تکراری است");
var editSmsSetting = _smsSettingsRepository.Get(command.Id);
editSmsSetting.Edit(command.DayOfMonth, timeSpan);
await _smsSettingsRepository.SaveChangesAsync();
return op.Succcedded();
}
public async Task RemoveSetting(long id)
{
await _smsSettingsRepository.RemoveItem(id);
}
public async Task<List<SmsListData>> GetSmsListData(TypeOfSmsSetting typeOfSmsSetting)
{
return await _institutionContractRepository.GetSmsListData(DateTime.Now, typeOfSmsSetting);
}
public async Task<List<BlockSmsListData>> GetBlockSmsListData(TypeOfSmsSetting typeOfSmsSetting)
{
return await _institutionContractRepository.GetBlockListData(DateTime.Now);
}
public async Task<OperationResult> InstantSendReminderSms(List<SmsListData> command)
{
var op = new OperationResult();
string typeOfSms = "یادآور بدهی ماهانه";
string sendMessStart = "شروع یادآور آنی";
string sendMessEnd = "پایان یادآور آنی";
if (command.Any())
{
await _institutionContractRepository.SendReminderSmsToContractingParties(command, typeOfSms, sendMessStart, sendMessEnd);
return op.Succcedded();
}
else
{
return op.Failed("موردی انتخاب نشده است");
}
}
public async Task<OperationResult> InstantSendBlockSms(List<BlockSmsListData> command)
{
var op = new OperationResult();
string typeOfSms = "اعلام مسدودی طرف حساب";
string sendMessStart = "شروع مسدودی آنی";
string sendMessEnd = "پایان مسدودی آنی ";
if (command.Any())
{
await _institutionContractRepository.SendBlockSmsToContractingParties(command, typeOfSms, sendMessStart,
sendMessEnd);
return op.Succcedded();
}
else
{
return op.Failed("موردی انتخاب نشده است");
}
}
}

View File

@@ -209,6 +209,11 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
if (apiRespons.ResponseContext.Status.Code == 14)
throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد");
if (apiRespons.ResponseContext.Status.Code == 2)
{
throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد");
}
if (apiRespons.ResponseContext.Status.Code != 0)
return op.Failed($"{apiRespons.ResponseContext.Status.Message}");