Files
Backend-Api/ServiceHost/Test/Tester.cs

98 lines
3.7 KiB
C#

using System.Diagnostics;
using _0_Framework.Application.Sms;
using _0_Framework.Domain.CustomizeCheckoutShared.Enums;
using AccountMangement.Infrastructure.EFCore;
using CompanyManagment.App.Contracts.AdminMonthlyOverview;
using CompanyManagment.EFCore;
using Microsoft.EntityFrameworkCore;
using ServiceHost.Areas.AdminNew.Pages.Company.RollCall;
namespace ServiceHost.Test;
public class Tester
{
private readonly IAdminMonthlyOverviewApplication _adminMonthlyOverviewApplication;
private readonly CompanyContext _companyContext;
private readonly AccountContext _accountContext;
private readonly ISmsService _smsService;
public Tester(IAdminMonthlyOverviewApplication adminMonthlyOverviewApplication, CompanyContext companyContext, AccountContext accountContext, ISmsService smsService)
{
_adminMonthlyOverviewApplication = adminMonthlyOverviewApplication;
_companyContext = companyContext;
_accountContext = accountContext;
_smsService = smsService;
}
public async Task Test()
{
// await _smsService.SendInstitutionVerificationLink("09116967898", "ماهان چمنی", Guid.NewGuid());
//await _smsService.SendInstitutionVerificationCode("09116967898", "0154");
// await AdminMonthlyOverviewTest();
//await MoveTasksToAnotherPerson(423, 434);
}
public async Task MoveTasksToAnotherPerson(long oldAccount, long newAccount)
{
var receivedTasks = await _accountContext.Assigns.Include(x => x.Task)
.Include(x => x.TaskMessageList)
.ThenInclude(x => x.TaskMessageItemsList).Where(x => x.AssignedId == oldAccount && !x.IsDone && !x.IsCancel).ToListAsync();
foreach (var receivedTaskAssign in receivedTasks)
{
receivedTaskAssign.ChangeAssignedId(newAccount);
}
await _accountContext.SaveChangesAsync();
var senderTasks = await _accountContext.Tasks.Include(x=>x.Assigns)
.ThenInclude(x => x.TaskMessageList)
.ThenInclude(x => x.TaskMessageItemsList).Where(x => x.SenderId == oldAccount && x.Assigns.Any(a=>!a.IsDone && !a.IsCancel) ).ToListAsync();
foreach (var task in senderTasks)
{
task.ChangeSender(newAccount);
}
await _accountContext.SaveChangesAsync();
}
private async Task ChangeFridayWorkToWeeklyDayOfWeek()
{
var employeeSettingsEnumerable =await _companyContext.CustomizeWorkshopEmployeeSettings.Where(x=>x.FridayWork ==FridayWork.Default).ToListAsync();
foreach (var employeeSetting in employeeSettingsEnumerable)
{
employeeSetting.FridayWorkToWeeklyDayOfWeek();
}
var groupSettings = await _companyContext.CustomizeWorkshopGroupSettings
.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var groupSetting in groupSettings)
{
groupSetting.FridayWorkToWeeklyDayOfWeek();
}
var workshopSettings = await _companyContext.CustomizeWorkshopSettings
.Where(x => x.FridayWork == FridayWork.Default).ToListAsync();
foreach (var workshopSetting in workshopSettings)
{
workshopSetting.FridayWorkToWeeklyDayOfWeek();
}
await _companyContext.SaveChangesAsync();
}
private async Task AdminMonthlyOverviewTest()
{
var acc = _companyContext.WorkshopAccounts.FirstOrDefault(x => x.AccountId == 322);
var searchModel = new AdminMonthlyOverviewSearchModel()
{
Year = 1403,
Month = 12,
AdminAccountId = 322
};
var stopwatch = new Stopwatch();
stopwatch.Start();
var workshopsStatus = await _adminMonthlyOverviewApplication.GetWorkshopListByStatus(searchModel);
Console.WriteLine(stopwatch.Elapsed);
}
}