2024-09-16 17:36:28 +03:30
|
|
|
|
using Azure;
|
|
|
|
|
using Back.Common;
|
2024-04-02 17:14:18 +03:30
|
|
|
|
using Back.Data.Contracts;
|
2024-03-30 15:10:36 +03:30
|
|
|
|
using Back.Data.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Shared.DTOs;
|
2024-04-05 21:03:40 +03:30
|
|
|
|
using System;
|
2024-04-05 01:05:32 +03:30
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Text;
|
2024-03-30 15:10:36 +03:30
|
|
|
|
|
|
|
|
|
namespace Back.Services
|
|
|
|
|
{
|
|
|
|
|
public class ServBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsyncRepository<Pricing> _repoPricing;
|
2024-03-31 01:33:17 +03:30
|
|
|
|
private readonly IAsyncRepository<Blog> _repoBlog;
|
2024-04-03 17:07:18 +03:30
|
|
|
|
private readonly IAsyncRepository<Question> _repoQuestion;
|
2024-04-05 01:05:32 +03:30
|
|
|
|
private readonly IAsyncRepository<SaleLead> _repoSaleLead;
|
2025-10-03 23:30:01 +03:30
|
|
|
|
// private readonly Service.Main _Taxtools;
|
2024-04-05 01:05:32 +03:30
|
|
|
|
public ServBase(IAsyncRepository<Pricing> repoPricing,
|
|
|
|
|
IAsyncRepository<Blog> repoBlog, IAsyncRepository<Question> repoQuestion
|
2025-10-03 23:30:01 +03:30
|
|
|
|
/* , Service.Main taxtools*/, IAsyncRepository<SaleLead> repoSaleLead)
|
2024-03-30 15:10:36 +03:30
|
|
|
|
{
|
|
|
|
|
_repoPricing = repoPricing;
|
2024-03-31 01:33:17 +03:30
|
|
|
|
_repoBlog = repoBlog;
|
2024-04-03 17:07:18 +03:30
|
|
|
|
_repoQuestion = repoQuestion;
|
2025-10-03 23:30:01 +03:30
|
|
|
|
// _Taxtools = taxtools;
|
2024-04-05 01:05:32 +03:30
|
|
|
|
_repoSaleLead = repoSaleLead;
|
2024-03-30 15:10:36 +03:30
|
|
|
|
}
|
|
|
|
|
public async Task<List<BasePriceDto>> GetBasePrice()
|
|
|
|
|
{
|
|
|
|
|
return await _repoPricing.GetAll().Select(x => new BasePriceDto
|
|
|
|
|
{
|
|
|
|
|
Price = x.Price,
|
2024-03-31 01:33:17 +03:30
|
|
|
|
CalculationType = x.CalculationTypeID == 1 && x.PermissionID == 16 ? "هر ارسال"
|
2025-01-15 19:35:51 +03:30
|
|
|
|
: x.CalculationTypeID == 1 && x.PermissionID == 18 ? "هر رسید"
|
|
|
|
|
: x.CalculationTypeID== 1 && x.PermissionID != 16 ? "واحدی"
|
2024-03-30 15:10:36 +03:30
|
|
|
|
: x.CalculationTypeID == 2 ? "نامحدود" : "روزانه",
|
|
|
|
|
PermissionID=x.PermissionID,
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
}
|
2024-09-18 23:52:48 +03:30
|
|
|
|
public async Task<PagingDto<BlogDto>> GetBlog(int PageIndex, int PageSize,string? Tag, string? ItemSearch)
|
2024-03-31 01:33:17 +03:30
|
|
|
|
{
|
2024-09-16 17:36:28 +03:30
|
|
|
|
var request = _repoBlog.Get(w => w.Status);
|
2024-09-18 23:52:48 +03:30
|
|
|
|
if (!string.IsNullOrEmpty(ItemSearch))
|
|
|
|
|
request = request.Where(x => x.Tags.Contains(ItemSearch) || x.Title.Contains(ItemSearch) || x.Text.Contains(ItemSearch));
|
2024-09-16 17:36:28 +03:30
|
|
|
|
if (!string.IsNullOrEmpty(Tag))
|
|
|
|
|
request = request.Where(x => x.Tags.Contains(Tag));
|
|
|
|
|
|
|
|
|
|
return await request.OrderByDescending(o=>o.ID)
|
2024-03-31 01:33:17 +03:30
|
|
|
|
.Select(s=>new BlogDto
|
|
|
|
|
{
|
|
|
|
|
Title = s.Title,
|
|
|
|
|
Date=s.Date,
|
|
|
|
|
ID=s.ID,
|
2024-04-03 14:36:33 +03:30
|
|
|
|
Photo=string.IsNullOrEmpty(s.Photo) ? "blog-SampleTitle.jpg" : s.Photo
|
2024-04-02 17:14:18 +03:30
|
|
|
|
}).Paging(PageIndex, PageSize); ;
|
2024-03-31 01:33:17 +03:30
|
|
|
|
}
|
2024-04-03 17:07:18 +03:30
|
|
|
|
public async Task<PagingDto<QuestionDto>> GetQuestion(int PageIndex, int PageSize)
|
|
|
|
|
{
|
|
|
|
|
return await _repoQuestion.Get(w => w.Status)
|
2024-09-11 16:39:44 +03:30
|
|
|
|
.Include(inc=>inc.questionCategory).OrderBy(o => o.ID)
|
2024-04-03 17:07:18 +03:30
|
|
|
|
.Select(s => new QuestionDto
|
|
|
|
|
{
|
|
|
|
|
Answer=s.Answer,
|
|
|
|
|
Category=s.questionCategory.Title,
|
|
|
|
|
Title=s.Title,
|
|
|
|
|
ID = s.ID
|
|
|
|
|
}).Paging(PageIndex, PageSize);
|
|
|
|
|
}
|
2024-04-03 14:36:33 +03:30
|
|
|
|
public async Task<BlogDtoFull?> GetBlogByID(int ID)
|
|
|
|
|
{
|
|
|
|
|
var result= await _repoBlog.Get(w => w.Status && w.ID==ID)
|
|
|
|
|
.Select(s => new BlogDtoFull
|
|
|
|
|
{
|
|
|
|
|
Title = s.Title,
|
|
|
|
|
Date = s.Date,
|
|
|
|
|
ID = s.ID,
|
|
|
|
|
Photo = string.IsNullOrEmpty(s.Photo) ? "blog-SampleTitle.jpg" : s.Photo,
|
|
|
|
|
Text=s.Text,
|
2024-09-16 17:36:28 +03:30
|
|
|
|
Time=s.Time,
|
|
|
|
|
Tags= s.Tags,
|
2024-11-16 15:08:18 +03:30
|
|
|
|
DescriptionTag=s.DescriptionTag,
|
2024-11-20 12:10:17 +03:30
|
|
|
|
keywordsTag=s.keywordsTag,
|
|
|
|
|
PageTitle=string.IsNullOrEmpty(s.PageTitle) ?s.Title : s.PageTitle,
|
2024-04-03 14:36:33 +03:30
|
|
|
|
}).FirstOrDefaultAsync();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2024-04-05 01:05:32 +03:30
|
|
|
|
public async Task<TaxToolsDTO?> CreateCsrAndPrivateKey(CsrPrivateKeyDto model)
|
|
|
|
|
{
|
|
|
|
|
TaxToolsDTO taxTools = null;
|
2025-10-03 23:30:01 +03:30
|
|
|
|
//List<Service.PrmValue> values = new List<Service.PrmValue>()
|
|
|
|
|
//{
|
|
|
|
|
// new Service.PrmValue(){Prm="CN",Value=model.cn},
|
|
|
|
|
// new Service.PrmValue(){Prm="serialNumber",Value=model.sn},
|
|
|
|
|
// new Service.PrmValue(){Prm="O",Value="Non-Governmental"},
|
|
|
|
|
// new Service.PrmValue(){Prm="3.OU",Value=model.company},
|
|
|
|
|
// new Service.PrmValue(){Prm="2.OU",Value=model.company},
|
|
|
|
|
// new Service.PrmValue(){Prm="1.OU",Value=model.company},
|
|
|
|
|
// new Service.PrmValue(){Prm="C",Value="IR"},
|
|
|
|
|
//};
|
|
|
|
|
//string msg = "";
|
|
|
|
|
//if (_Taxtools.CraeteCnfFile(values, ref msg))
|
|
|
|
|
//{
|
|
|
|
|
// if (_Taxtools.CreateCsrAndPrivateKey(model.cn, ref msg))
|
|
|
|
|
// {
|
|
|
|
|
// taxTools = new TaxToolsDTO();
|
|
|
|
|
// //خواندن
|
|
|
|
|
// Stream stream = File.Open($"C:\\OpenSSL\\bin\\{model.cn}.Csr", FileMode.Open);
|
|
|
|
|
// byte[] buffer = new byte[stream.Length];
|
|
|
|
|
// stream.Read(buffer, 0, (int)stream.Length);
|
|
|
|
|
// string csr = Encoding.UTF8.GetString(buffer);
|
|
|
|
|
// stream.Flush();
|
|
|
|
|
// stream.Close();
|
|
|
|
|
// taxTools.Base64csr = Convert.ToBase64String(buffer);
|
|
|
|
|
// taxTools.typecsr = "Csr";
|
|
|
|
|
// stream = File.Open($"C:\\OpenSSL\\bin\\{model.cn}.key", FileMode.Open);
|
|
|
|
|
// buffer = new byte[stream.Length];
|
|
|
|
|
// stream.Read(buffer, 0, (int)stream.Length);
|
|
|
|
|
// string key = Encoding.UTF8.GetString(buffer);
|
|
|
|
|
// taxTools.Base64key = Convert.ToBase64String(buffer);
|
|
|
|
|
// taxTools.typekey = "key";
|
|
|
|
|
// stream.Flush();
|
|
|
|
|
// stream.Close();
|
2024-04-05 01:05:32 +03:30
|
|
|
|
|
2025-10-03 23:30:01 +03:30
|
|
|
|
// //_contextMongodb.InsertItem(new SysLog()
|
|
|
|
|
// //{
|
|
|
|
|
// // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
|
|
|
|
// // Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
|
|
|
|
// // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/CreateCsrAndPrivateKey",
|
|
|
|
|
// // Value = JsonConvert.SerializeObject(model),
|
|
|
|
|
// // Route = _httpContextAccessor.HttpContext.Request.Path,
|
|
|
|
|
// // Type = "User"
|
|
|
|
|
// //});
|
|
|
|
|
// await _repoSaleLead.AddAsync(new SaleLead
|
|
|
|
|
// {
|
|
|
|
|
// cn = model.cn,
|
|
|
|
|
// company = model.company,
|
|
|
|
|
// csr = csr,
|
|
|
|
|
// Key = key,
|
|
|
|
|
// Mobile = model.Mobile,
|
|
|
|
|
// sn = model.sn
|
|
|
|
|
// });
|
|
|
|
|
// }
|
2024-04-03 14:36:33 +03:30
|
|
|
|
|
2025-10-03 23:30:01 +03:30
|
|
|
|
//}
|
2024-04-05 01:05:32 +03:30
|
|
|
|
|
2025-10-03 23:30:01 +03:30
|
|
|
|
// if (string.IsNullOrEmpty(msg))
|
2024-04-05 01:05:32 +03:30
|
|
|
|
{
|
|
|
|
|
//_contextMongodb.InsertItem(new SysLog()
|
|
|
|
|
//{
|
|
|
|
|
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
|
|
|
|
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
|
|
|
|
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/CreateCsrAndPrivateKey",
|
|
|
|
|
// Value = msg,
|
|
|
|
|
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
|
|
|
|
// Type = "ERROR"
|
|
|
|
|
//});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return taxTools;
|
|
|
|
|
}
|
2024-04-05 21:03:40 +03:30
|
|
|
|
public async Task<PublicKeyDTO?> ReadPublicKeyFromCER(string modelfromBase64)
|
2024-04-05 01:05:32 +03:30
|
|
|
|
{
|
2024-04-05 21:03:40 +03:30
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2024-04-05 01:05:32 +03:30
|
|
|
|
string name = $"{DateTime.Now.Year}{DateTime.Now.Month}{DateTime.Now.DayOfWeek}{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}";
|
|
|
|
|
string filePath = $"C:\\cer\\{name}.cer";
|
|
|
|
|
Stream stream = System.IO.File.Open(filePath, FileMode.Create);
|
|
|
|
|
var encoding = Convert.FromBase64String(modelfromBase64);
|
|
|
|
|
stream.Write(encoding, 0, encoding.Length);
|
|
|
|
|
stream.Flush();
|
|
|
|
|
stream.Close();
|
|
|
|
|
|
|
|
|
|
Process cmd = new Process();
|
|
|
|
|
cmd.StartInfo.WorkingDirectory = Environment.CurrentDirectory + "C\\OpenSSL\\bin";
|
|
|
|
|
cmd.StartInfo.FileName = "cmd.exe";
|
|
|
|
|
cmd.StartInfo.RedirectStandardInput = true;
|
|
|
|
|
cmd.StartInfo.RedirectStandardOutput = true;
|
|
|
|
|
cmd.StartInfo.CreateNoWindow = true;
|
|
|
|
|
cmd.StartInfo.UseShellExecute = false;
|
|
|
|
|
cmd.Start();
|
|
|
|
|
|
|
|
|
|
cmd.StandardInput.WriteLine($"openssl x509 -pubkey -noout -in {filePath}> {name}.txt");
|
|
|
|
|
cmd.StandardInput.Flush();
|
|
|
|
|
cmd.StandardInput.Close();
|
|
|
|
|
cmd.WaitForExit();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//خواندن
|
|
|
|
|
stream = System.IO.File.Open($"C\\OpenSSL\\bin\\{name}.txt", FileMode.Open);
|
|
|
|
|
byte[] buffer = new byte[stream.Length];
|
|
|
|
|
stream.Read(buffer, 0, (int)stream.Length);
|
|
|
|
|
string PublicKey = Encoding.UTF8.GetString(buffer);
|
|
|
|
|
stream.Flush();
|
|
|
|
|
stream.Close();
|
|
|
|
|
|
|
|
|
|
//_contextMongodb.InsertItem(new SysLog()
|
|
|
|
|
//{
|
|
|
|
|
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
|
|
|
|
|
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
|
|
|
|
|
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/ReadPublicKeyFromCER",
|
|
|
|
|
// Value = modelfromBase64,
|
|
|
|
|
// Route = _httpContextAccessor.HttpContext.Request.Path,
|
|
|
|
|
// Type = "User"
|
|
|
|
|
//});
|
|
|
|
|
return new PublicKeyDTO
|
|
|
|
|
{
|
|
|
|
|
PublicKeyBase64 = Convert.ToBase64String(buffer),
|
|
|
|
|
type = "txt"
|
|
|
|
|
};
|
2024-04-05 21:03:40 +03:30
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return new PublicKeyDTO
|
|
|
|
|
{
|
|
|
|
|
PublicKeyBase64 = "error",
|
|
|
|
|
type = "error"
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-04-05 01:05:32 +03:30
|
|
|
|
}
|
2024-03-30 15:10:36 +03:30
|
|
|
|
}
|
|
|
|
|
}
|