Files
Backend-Api/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs
2025-07-16 11:59:02 +03:30

761 lines
33 KiB
C#

using _0_Framework.Application;
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
using AccountManagement.Domain.AccountLeftWorkAgg;
using AccountMangement.Infrastructure.EFCore;
using Company.Domain.CustomizeCheckoutAgg.ValueObjects;
using Company.Domain.CustomizeCheckoutTempAgg.ValueObjects;
using Company.Domain.RewardAgg;
using Company.Domain.RollCallAgg.DomainService;
using CompanyManagment.App.Contracts.AndroidApkVersion;
using CompanyManagment.EFCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using System.Net.Http;
using System.Text.Json.Serialization;
using _0_Framework.Application.PaymentGateway;
using Microsoft.Extensions.Options;
using static ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk.IndexModel2;
namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
{
[Authorize]
public class IndexModel : PageModel
{
private readonly IAndroidApkVersionApplication _application;
private readonly IRollCallDomainService _rollCallDomainService;
private readonly CompanyContext _context;
private readonly AccountContext _accountContext;
private readonly IPaymentGateway _paymentGateway;
[BindProperty]
public IFormFile File { get; set; }
public IndexModel(IAndroidApkVersionApplication application, IRollCallDomainService rollCallDomainService, CompanyContext context, AccountContext accountContext, IHttpClientFactory httpClientFactory,IOptions<AppSettingConfiguration> appSetting)
{
_application = application;
_rollCallDomainService = rollCallDomainService;
_context = context;
_accountContext = accountContext;
_paymentGateway = new AqayePardakhtPaymentGateway(httpClientFactory, appSetting);
}
public void OnGet()
{
}
public async Task<IActionResult> OnPostUpload()
{
var result = await _application.CreateAndActive(File);
ViewData["message"] = result.Message;
return Page();
}
public IActionResult OnPostShiftDate()
{
//var startRollCall = new DateTime(2025, 2, 19);
//var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall);
//var endedRollCalls = rollCalls.Where(x => x.EndDate != null).ToList();
//var notEndedRollCalls = rollCalls.Where(x => x.EndDate == null).ToList();
//RefactorAllTheRollCallsOnEsfand(endedRollCalls, notEndedRollCalls);
//CreateRewardForKebabMahdi().GetAwaiter().GetResult();
SetEntityIdForCheckoutValues();
SetEntityIdForCheckoutValuesTemp();
ViewData["message"] = "ایجاد شد";
return Page();
}
public IActionResult OnPostShiftDateNew()
{
var startRollCall = new DateTime(2025, 4, 21);
//var employees = _context.CustomizeWorkshopEmployeeSettings
// .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList();
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList();
var r1 = rollCalls.ToList();
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("endStep 1 ============");
SetBreakTime(r1);
ViewData["message"] = "تومام یک";
return Page();
}
public async Task<IActionResult> OnPostShiftDateNew2()
{
//var startRollCall = new DateTime(2025, 3, 21);
//var rollCalls = _context.RollCalls.Where(x => x.StartDate >= startRollCall && x.EndDate != null ).ToList();
//var r1 = rollCalls.Skip(10000).Take(10000).ToList();
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine("endStep 1 ============");
//SetRollCall(r1);
await ChangeFridayWorkToWeeklyDayOfWeek();
ViewData["message"] = "تومام دو";
return Page();
}
public async Task<IActionResult> OnPostPaymentGateWay(CancellationToken cancellationToken)
{
var command = new CreatePaymentGatewayRequest()
{
Amount = 1000,
Email = "mahanch83@gmail.com",
CallBackUrl = Url.Page("/CallBack/Index", null, null, Request.Scheme, Request.Host.Value),
InvoiceId = "{C771E841-B810-413D-9D4C-9F659575B8CC}",
};
var createResponse = await _paymentGateway.Create(command, cancellationToken);
if (createResponse.Status == "success")
{
return Redirect(_paymentGateway.GetStartPayUrl(createResponse.TransactionId));
}
//TranslateCode(result?.ErrorCode);
return Page();
}
public async System.Threading.Tasks.Task OnGetCallback(string? transid, string? cardnumber, string? tracking_number, string status)
{
if (string.IsNullOrEmpty(cardnumber) || string.IsNullOrEmpty(tracking_number))
{
ViewData["message"] = "پرداخت ناموفق بوده است";
return;
}
else if (status == "1")
{
ViewData["message"] = "پرداخت موفق بوده است";
return;
}
//var client = _httpClientFactory.CreateClient();
//var response = await client.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/verify", new
//{
// pin = "aqayepardakht",
// amount = 100,
// transid = transid,
//});
//var result = await response.Content.ReadFromJsonAsync<TokenResponse>();
}
private async System.Threading.Tasks.Task SetWorkshopRoleSubAccount()
{
var subAccountRoles = _accountContext.SubAccountRoles.Include(x => x.SubAccounts).ToList();
subAccountRoles.ForEach(role =>
{
var getSubAccount = role.SubAccounts.FirstOrDefault();
if (getSubAccount != null)
{
var subAccount = getSubAccount.id;
var workshopIds = _context.WorkshopSubAccounts.Where(x => x.SubAccountId == subAccount).Select(x => x.WorkshopId).ToList();
role.Edit(role.Title, role.RolePermissions.Select(x => x.PermissionCode).ToList(), workshopIds);
}
});
await _accountContext.SaveChangesAsync();
}
private void SetEntityIdForCheckoutValuesTemp()
{
var customizeCheckouts = _context.CustomizeCheckoutTemps.ToList();
foreach (var customizeCheckout in customizeCheckouts)
{
var newRewards = new List<CustomizeCheckoutTempReward>();
foreach (var customizeCheckoutReward in customizeCheckout.CustomizeCheckoutRewards)
{
var reward = _context.Rewards.FirstOrDefault(x => x.GrantDate == customizeCheckoutReward.GrantDate && x.Title == customizeCheckoutReward.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (reward != null)
{
newRewards.Add(new CustomizeCheckoutTempReward(reward.Amount.ToMoney(), reward.Description, reward.GrantDate, reward.GrantDate.ToFarsi(), reward.IsActive, reward.Title, reward.id));
}
}
var newSalary = new List<CustomizeCheckoutTempSalaryAid>();
foreach (var customizeCheckoutSalaryAid in customizeCheckout.CustomizeCheckoutSalaryAids)
{
var salary = _context.SalaryAids.FirstOrDefault(x => x.SalaryAidDateTime == customizeCheckoutSalaryAid.SalaryAidDateTime &&
x.Amount == customizeCheckoutSalaryAid.Amount.MoneyToDouble() &&
x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (salary != null)
{
newSalary.Add(new CustomizeCheckoutTempSalaryAid(salary.Amount.ToMoney(), salary.SalaryAidDateTime,
salary.SalaryAidDateTime.ToFarsi(), salary.CalculationDate, salary.CalculationDate.ToFarsi(), salary.id));
}
}
var newFines = new List<CustomizeCheckoutTempFine>();
foreach (var checkoutFine in customizeCheckout.CheckoutFines)
{
var fines = _context.Fines.FirstOrDefault(x => x.Amount == checkoutFine.Amount.MoneyToDouble() && x.FineDate == checkoutFine.FineDateGr &&
x.Title == checkoutFine.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (fines != null)
{
newFines.Add(new CustomizeCheckoutTempFine(fines.Title, fines.Amount.ToMoney(), fines.FineDate.ToFarsi(), fines.FineDate, fines.IsActive, fines.CreationDate, fines.id));
}
}
var newInstallments = new List<CustomizeCheckoutTempLoanInstallments>();
foreach (var customizeCheckoutLoanInstallment in customizeCheckout.CustomizeCheckoutLoanInstallments)
{
var installments = _context.Loans.SelectMany(x => x.LoanInstallments).AsNoTracking().Where(x => x.Month == customizeCheckoutLoanInstallment.Month && x.Year == customizeCheckoutLoanInstallment.Year && x.AmountForMonth == customizeCheckoutLoanInstallment.AmountForMonth.MoneyToDouble()).ToList();
var loans = _context.Loans
.Where(x => x.Amount == customizeCheckoutLoanInstallment.LoanAmount.MoneyToDouble() && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId).ToList();
var installment = installments.First(x => loans.Any(l => l.id == x.LoanId));
if (installment != null)
{
newInstallments.Add(new CustomizeCheckoutTempLoanInstallments(installment.AmountForMonth.ToMoney(),
installment.Month, installment.Year, installment.IsActive,
customizeCheckoutLoanInstallment.LoanRemaining, customizeCheckoutLoanInstallment.LoanAmount,
installment.Id));
}
}
customizeCheckout.SetValueObjects(newFines, newInstallments, newSalary, newRewards);
_context.SaveChanges();
}
}
private void SetEntityIdForCheckoutValues()
{
var customizeCheckouts = _context.CustomizeCheckouts.ToList();
foreach (var customizeCheckout in customizeCheckouts)
{
var newRewards = new List<CustomizeCheckoutReward>();
foreach (var customizeCheckoutReward in customizeCheckout.CustomizeCheckoutRewards)
{
var reward = _context.Rewards.FirstOrDefault(x => x.GrantDate == customizeCheckoutReward.GrantDate && x.Title == customizeCheckoutReward.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (reward != null)
{
newRewards.Add(new CustomizeCheckoutReward(reward.Amount.ToMoney(), reward.Description, reward.GrantDate, reward.GrantDate.ToFarsi(), reward.IsActive, reward.Title, reward.id));
}
}
var newSalary = new List<CustomizeCheckoutSalaryAid>();
foreach (var customizeCheckoutSalaryAid in customizeCheckout.CustomizeCheckoutSalaryAids)
{
var salary = _context.SalaryAids.FirstOrDefault(x => x.SalaryAidDateTime == customizeCheckoutSalaryAid.SalaryAidDateTime &&
x.Amount == customizeCheckoutSalaryAid.Amount.MoneyToDouble() &&
x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (salary != null)
{
newSalary.Add(new CustomizeCheckoutSalaryAid(salary.Amount.ToMoney(), salary.SalaryAidDateTime,
salary.SalaryAidDateTime.ToFarsi(), salary.CalculationDate, salary.CalculationDate.ToFarsi(), salary.id));
}
}
var newFines = new List<CustomizeCheckoutFine>();
foreach (var checkoutFine in customizeCheckout.CheckoutFines)
{
var fines = _context.Fines.FirstOrDefault(x => x.Amount == checkoutFine.Amount.MoneyToDouble() && x.FineDate == checkoutFine.FineDateGr &&
x.Title == checkoutFine.Title && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId);
if (fines != null)
{
newFines.Add(new CustomizeCheckoutFine(fines.Title, fines.Amount.ToMoney(), fines.FineDate.ToFarsi(), fines.FineDate, fines.IsActive, fines.CreationDate, fines.id));
}
}
var newInstallments = new List<CustomizeCheckoutLoanInstallments>();
foreach (var customizeCheckoutLoanInstallment in customizeCheckout.CustomizeCheckoutLoanInstallments)
{
var installments = _context.Loans.SelectMany(x => x.LoanInstallments).AsNoTracking().Where(x => x.Month == customizeCheckoutLoanInstallment.Month && x.Year == customizeCheckoutLoanInstallment.Year && x.AmountForMonth == customizeCheckoutLoanInstallment.AmountForMonth.MoneyToDouble()).ToList();
var loans = _context.Loans
.Where(x => x.Amount == customizeCheckoutLoanInstallment.LoanAmount.MoneyToDouble() && x.EmployeeId == customizeCheckout.EmployeeId && x.WorkshopId == customizeCheckout.WorkshopId).ToList();
var installment = installments.First(x => loans.Any(l => l.id == x.LoanId));
if (installment != null)
{
newInstallments.Add(new CustomizeCheckoutLoanInstallments(installment.AmountForMonth.ToMoney(),
installment.Month, installment.Year, installment.IsActive,
customizeCheckoutLoanInstallment.LoanRemaining, customizeCheckoutLoanInstallment.LoanAmount,
installment.Id));
}
}
customizeCheckout.SetValueObjects(newFines, newInstallments, newSalary, newRewards);
_context.SaveChanges();
}
}
private async System.Threading.Tasks.Task SetCalculationDateInSalaryAid()
{
var salaryAids = await _context.SalaryAids.ToListAsync();
foreach (var salaryAid in salaryAids)
{
var calculationDate = salaryAid.SalaryAidDateTime;
var calculationMonth = Convert.ToInt32(calculationDate.ToFarsiMonth());
var calculationYear = Convert.ToInt32(calculationDate.ToFarsiYear());
salaryAid.Edit(salaryAid.Amount, salaryAid.SalaryAidDateTime, 0, UserType.Anonymous, calculationMonth, calculationYear);
}
await _context.SaveChangesAsync();
}
private async System.Threading.Tasks.Task RemoveEmployeeClientTemps()
{
var employeeDocuments = _context.EmployeeDocuments
.Include(x => x.EmployeeDocumentItemCollection)
.Where(x => x.IsConfirmed);
var employeeClientTemps = await _context.EmployeeClientTemps.Where(x => employeeDocuments.Any(a => a.WorkshopId == x.WorkshopId && a.EmployeeId == x.EmployeeId)).ToListAsync();
foreach (var employeeClientTemp in employeeClientTemps)
{
_context.EmployeeClientTemps.Remove(employeeClientTemp);
}
await _context.SaveChangesAsync();
}
private async System.Threading.Tasks.Task ChangeIsConfirmed()
{
var employeeDocuments = await _context.EmployeeDocuments.Include(x => x.EmployeeDocumentItemCollection).ToListAsync();
foreach (var employeeDocument in employeeDocuments)
{
employeeDocument.UpdateRequiredItemsSubmittedByClient();
employeeDocument.UpdateHasRejectedItems();
employeeDocument.UpdateIsSentToChecker();
employeeDocument.UpdateIsConfirmed();
}
await _context.SaveChangesAsync();
}
public async System.Threading.Tasks.Task RefactorEmployeeDocumentItem()
{
var employeeDocumentItems = await _context.EmployeeDocumentItems.Where(x => x.UploaderType == UserType.Admin).ToListAsync();
foreach (var employeeDocumentItem in employeeDocumentItems)
{
var roleId = _accountContext.Accounts.FirstOrDefault(x => x.id == employeeDocumentItem.UploaderId)?.RoleId ?? 0;
employeeDocumentItem.SetRoleId(roleId);
}
await _context.SaveChangesAsync();
}
#region Create reward for kebab mahdi
public async System.Threading.Tasks.Task CreateRewardForKebabMahdi()
{
//var esfandCustomizeCheckouts = _context.CustomizeCheckouts
// .Where(x => x.WorkshopId == 170 && x.MonthInt == 12 && x.YearInt == 1403);
//var sinzdahBedarDate = new DateTime(2025, 04, 2);
//var chahardah = sinzdahBedarDate.AddDays(1);
//var workingEmp = _context.LeftWorkList.Where(x => x.WorkshopId == 170 && x.StartWorkDate <= sinzdahBedarDate && x.LeftWorkDate >= sinzdahBedarDate)
// .GroupBy(x => x.EmployeeId).Select(x=>x.Key);
//var employeesHaveRollCall = _context.RollCallEmployees
// .Where(x => workingEmp.Contains(x.EmployeeId) && x.WorkshopId == 170)
// .Include(x => x.EmployeesStatus)
// .Where(x => x.EmployeesStatus.Any(s => s.StartDate <= sinzdahBedarDate && s.EndDate >= sinzdahBedarDate)).Select(x=>x.EmployeeId);
//var employeeSettings = _context.CustomizeWorkshopEmployeeSettings
// .Where(x => x.WorkshopId == 170 &&
// employeesHaveRollCall.Any(c => c == x.EmployeeId));
//var absentEmployeesInSinzdah = employeeSettings.Where(x => !_context.RollCalls
// .Any(a => a.EmployeeId == x.EmployeeId && a.ShiftDate == sinzdahBedarDate))
// .ToList();
//var absentEmployeesInChahardah = employeeSettings.Where(x => !_context.RollCalls
// .Any(a => a.EmployeeId == x.EmployeeId && a.ShiftDate == chahardah))
// .ToList();
//foreach (var employeeSetting in absentEmployeesInSinzdah)
//{
// var amount = (int)employeeSetting.Salary / 30;
// var reward = new Reward(employeeSetting.EmployeeId, 170, amount, "", 0, sinzdahBedarDate,
// "بابت تعطیلی روز 13 فروردین");
// _context.Rewards.Add(reward);
//}
//foreach (var employeeSetting in absentEmployeesInChahardah)
//{
// var amount = (int)employeeSetting.Salary / 30;
// var reward = new Reward(employeeSetting.EmployeeId, 170, amount, "", 0, sinzdahBedarDate.AddDays(1),
// "بابت تعطیلی روز 14 فروردین");
// _context.Rewards.Add(reward);
//}
//await _context.SaveChangesAsync();
}
#endregion
#region AccountLeftwork
private void AddToAccountLeftWork()
{
List<long> roleIds = [3, 5, 7, 8, 23, 24];
var accounts = _accountContext.Accounts
.Where(x => roleIds.Contains(x.RoleId)).Where(x => x.AdminAreaPermission == "true");
var accountsIds = accounts.Select(x => x.id).ToList();
var workshopAccount = _context.WorkshopAccounts
.Where(x => accountsIds.Contains(x.AccountId))
.GroupBy(x => x.AccountId);
List<long> oldAccountleftworkActiveNow = [300, 332, 333, 334, 18, 25, 14];
List<long> oldAccountleftworkDeActivedNow = [50, 49, 15];
var continueWorking = _0_Framework.Application.StaticWorkshopAccounts.ContinuesWorkingDate;
foreach (var item in workshopAccount)
{
var oldActive = item.FirstOrDefault(x => oldAccountleftworkActiveNow.Contains(x.AccountId));
if (oldActive != null)
{
var roleId = accounts.FirstOrDefault(x => x.id == oldActive.AccountId)!.RoleId;
var startGr = item.Key != 25 ? new DateTime(2024, 07, 22) : new DateTime(2024, 08, 22);
//if (item.Key is 380 or 381)
// startGr = new DateTime(2025, 02, 19);
if (item.Key is 14 or 18)
startGr = new DateTime(2020, 05, 21);
if (item.Key is 300)
startGr = new DateTime(2024, 05, 22);
foreach (var workshop in item)
{
_accountContext.AccountLeftWorks.Add(new AccountLeftWork(startGr, continueWorking, workshop.AccountId, workshop.WorkshopId, roleId, true));
}
_accountContext.SaveChanges();
}
var oldDeActive = item.FirstOrDefault(x => oldAccountleftworkDeActivedNow.Contains(x.AccountId));
if (oldDeActive != null)
{
var roleId = accounts.FirstOrDefault(x => x.id == oldDeActive.AccountId)!.RoleId;
var startGr = new DateTime(2022, 03, 21);
if (item.Key == 49)
startGr = new DateTime(2023, 04, 21);
if (item.Key == 50)
startGr = new DateTime(2023, 03, 21);
foreach (var workshop in item)
{
_accountContext.Add(new AccountLeftWork(startGr, new DateTime(2024, 07, 21), workshop.AccountId, workshop.WorkshopId, roleId, false));
}
_accountContext.SaveChanges();
}
}
Console.WriteLine("finished");
}
#endregion
#region RefactorRollcall
private void RefactorAllTheRollCallsOnEsfand(List<global::Company.Domain.RollCallAgg.RollCall> endedRollCalls, List<global::Company.Domain.RollCallAgg.RollCall> notEndedRollCalls)
{
var countEndedRollCalls = endedRollCalls.Count;
var countNotEndedRollCalls = notEndedRollCalls.Count;
var step1 = 1;
foreach (var rollCall in endedRollCalls)
{
rollCall.setStartAndEnd(rollCall.StartDate.Value, rollCall.EndDate.Value, _rollCallDomainService);
Console.WriteLine($"{step1} - {countEndedRollCalls} ended Edit {rollCall.id}");
step1 += 1;
}
var step2 = 1;
foreach (var notEndedRollCall in notEndedRollCalls)
{
notEndedRollCall.SetStartAgain(notEndedRollCall.StartDate.Value);
Console.WriteLine($"{step2} - {countNotEndedRollCalls} not ended startAgain {notEndedRollCall.id}");
step2 += 1;
}
_context.SaveChanges();
}
private void SetBreakTime(List<global::Company.Domain.RollCallAgg.RollCall> r1)
{
foreach (var rollCall in r1)
{
}
_context.SaveChanges();
}
private void SetRollCall(List<global::Company.Domain.RollCallAgg.RollCall> r1)
{
var endedRollCalls2 = r1.Where(x => x.EndDate != null).ToList();
var countSetTDRollCall = endedRollCalls2.Count;
var stepSetTDRollCal = 1;
foreach (var rollCall in endedRollCalls2)
{
rollCall.ClearTimeDiff();
}
_context.SaveChanges();
foreach (var endedRollCall in endedRollCalls2)
{
endedRollCall.Edit(endedRollCall.StartDate.Value, endedRollCall.EndDate.Value, _rollCallDomainService);
Console.WriteLine($"{stepSetTDRollCal} - {countSetTDRollCall} ended Set Time Differences{endedRollCall.id}");
stepSetTDRollCal += 1;
}
_context.SaveChanges();
}
private void SetRollCall2(List<global::Company.Domain.RollCallAgg.RollCall> r2)
{
var endedRollCalls2 = r2.Where(x => x.EndDate != null).ToList();
var countSetTDRollCall = endedRollCalls2.Count;
var stepSetTDRollCal = 1;
foreach (var endedRollCall in endedRollCalls2)
{
endedRollCall.SetEndDateTime(endedRollCall.EndDate.Value, _rollCallDomainService);
Console.WriteLine($"{stepSetTDRollCal} - {countSetTDRollCall} ended Set Time Differences{endedRollCall.id}");
stepSetTDRollCal += 1;
}
//_context.SaveChanges();
}
#endregion
//public async Task<IActionResult> OnPostShiftDate()
//{
// var customizeWorkshopSettings = _context.CustomizeWorkshopSettings.AsSplitQuery();
// customizeWorkshopSettings = customizeWorkshopSettings.Where(x => x.WorkshopId == 499);
// var rollCalls =
// _context.RollCalls.Where(x => customizeWorkshopSettings.Any(a => a.WorkshopId == x.WorkshopId))
// .ToList();
// foreach (var rollCall in rollCalls)
// {
// rollCall.SetShiftDate(_rollCallDomainService);
// Console.WriteLine(rollCall.id);
// }
// await _context.SaveChangesAsync();
// ViewData["message"] = "تومام";
// return Page();
//}
private async System.Threading.Tasks.Task ChangeFridayWorkToWeeklyDayOfWeek()
{
var employeeSettingsEnumerable = await _context.CustomizeWorkshopEmployeeSettings.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var employeeSetting in employeeSettingsEnumerable)
{
employeeSetting.FridayWorkToWeeklyDayOfWeek();
}
var groupSettings = await _context.CustomizeWorkshopGroupSettings
.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var groupSetting in groupSettings)
{
groupSetting.FridayWorkToWeeklyDayOfWeek();
}
var workshopSettings = await _context.CustomizeWorkshopSettings
.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var workshopSetting in workshopSettings)
{
workshopSetting.FridayWorkToWeeklyDayOfWeek();
}
await _context.SaveChangesAsync();
}
}
public class IndexModel2 : PageModel
{
private readonly ILogger<IndexModel2> logger;
private readonly IHttpClientFactory httpClientFactory;
public IndexModel2(ILogger<IndexModel2> logger, IHttpClientFactory httpClientFactory)
{
this.logger = logger;
this.httpClientFactory = httpClientFactory;
}
[BindProperty]
public string? Message { get; set; }
public void OnGet()
{
}
public async Task<IActionResult> OnPostAsync()
{
Message = null;
var client = httpClientFactory.CreateClient();
var response = await client.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/create", new
{
pin = "aqayepardakht",
amount = 100,
callback = System.Web.HttpUtility.UrlEncode(Url.Page("./Index", "Callback", null, Request.Scheme, Request.Host.Value)),
card_number = "1111111111111111",
invoice_id = "{C771E841-B810-413D-9D4C-9F659575B8CC}",
mobile = "09121111111",
email = "test@test.com",
description = "توضیحات تست",
});
var result = await response.Content.ReadFromJsonAsync<TokenResponse>();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return Redirect($"https://panel.aqayepardakht.ir/startpay/{result?.TransactionId}");
}
TranslateCode(result?.ErrorCode);
return Page();
}
public async System.Threading.Tasks.Task OnGetCallbackAsync(string? transid, string? cardnumber, string? tracking_number)
{
Message = null;
if (string.IsNullOrEmpty(cardnumber) || string.IsNullOrEmpty(tracking_number))
{
Message = "پرداخت ناموفق بوده است";
return;
}
var client = httpClientFactory.CreateClient();
var response = await client.PostAsJsonAsync("https://panel.aqayepardakht.ir/api/v2/verify", new
{
pin = "aqayepardakht",
amount = 100,
transid = transid,
});
var result = await response.Content.ReadFromJsonAsync<TokenResponse>();
TranslateCode(result?.ErrorCode);
}
private void TranslateCode(int? code)
{
switch (code)
{
case 0:
Message = "پرداخت انجام نشد";
break;
case 1:
Message = "پرداخت با موفقیت انجام شد";
break;
case 2:
Message = "تراکنش قبلا وریفای شده است";
break;
case -1:
Message = "amount نمی تواند خالی باشد";
break;
case -2:
Message = "کد پین درگاه نمی تواند خالی باشد";
break;
case -3:
Message = "callback نمی تواند خالی باشد";
break;
case -4:
Message = "amount باید عددی باشد";
break;
case -5:
Message = "amount باید بین 100 تا 50,000,000 تومان باشد";
break;
case -6:
Message = "کد پین درگاه اشتباه هست";
break;
case -7:
Message = "transid نمی تواند خالی باشد";
break;
case -8:
Message = "تراکنش مورد نظر وجود ندارد";
break;
case -9:
Message = "کد پین درگاه با درگاه تراکنش مطابقت ندارد";
break;
case -10:
Message = "مبلغ با مبلغ تراکنش مطابقت ندارد";
break;
case -11:
Message = "درگاه درانتظار تایید و یا غیر فعال است";
break;
case -12:
Message = "امکان ارسال درخواست برای این پذیرنده وجود ندارد";
break;
case -13:
Message = "شماره کارت باید 16 رقم چسبیده بهم باشد";
break;
default:
Message = "خطای نامشخص";
break;
}
}
public class TokenResponse
{
[JsonPropertyName("status")]
public string? Status { get; set; }
[JsonPropertyName("code")]
public int? ErrorCode { get; set; }
[JsonPropertyName("transid")]
public string? TransactionId { get; set; }
}
}
}