change(Activities) , feat(NotifyCommands)

master
Amir Hossein Khademi 2024-07-08 17:45:17 +03:30
parent e918e8d3f7
commit 1fbf37dd82
84 changed files with 418 additions and 336 deletions

View File

@ -73,7 +73,7 @@
<Using Include="Brizco.Domain.CommandQueries.Queries" /> <Using Include="Brizco.Domain.CommandQueries.Queries" />
<Using Include="Brizco.Domain.Dtos.RequestDtos" /> <Using Include="Brizco.Domain.Dtos.RequestDtos" />
<Using Include="Brizco.Domain.Entities" /> <Using Include="Brizco.Domain.Entities" />
<Using Include="Brizco.Domain.Entities.User" /> <Using Include="Brizco.Domain.Entities.Users" />
<Using Include="Brizco.Domain.Models.Settings" /> <Using Include="Brizco.Domain.Models.Settings" />
<Using Include="Brizco.Infrastructure" /> <Using Include="Brizco.Infrastructure" />
<Using Include="Brizco.Repository" /> <Using Include="Brizco.Repository" />

View File

@ -8,35 +8,35 @@ public static class ScalarUiConfiguration
{ {
var scalarScript = $$""" var scalarScript = $$"""
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
<title>Scalar API Reference</title> <title>Scalar API Reference</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta <meta
name="viewport" name="viewport"
content="width=device-width, initial-scale=1" /> content="width=device-width, initial-scale=1" />
</head> </head>
<body> <body>
<!-- Add your own OpenAPI/Swagger specification URL here: --> <!-- Add your own OpenAPI/Swagger specification URL here: -->
<!-- Note: The example is our public proxy (to avoid CORS issues). You can remove the `data-proxy-url` attribute if you dont need it. --> <!-- Note: The example is our public proxy (to avoid CORS issues). You can remove the `data-proxy-url` attribute if you dont need it. -->
<script <script
id="api-reference" id="api-reference"
data-url="/swagger/{{documentName}}/swagger.json"></script> data-url="/swagger/{{documentName}}/swagger.json"></script>
<!-- Optional: You can set a full configuration object like this: --> <!-- Optional: You can set a full configuration object like this: -->
<script> <script>
var configuration = { var configuration = {
theme: 'bluePlanet', theme: 'bluePlanet',
} }
document.getElementById('api-reference').dataset.configuration = document.getElementById('api-reference').dataset.configuration =
JSON.stringify(configuration) JSON.stringify(configuration)
</script> </script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script> <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body> </body>
</html> </html>
"""; """;
return Results.Content(scalarScript, "text/html"); return Results.Content(scalarScript, "text/html");
}).ExcludeFromDescription(); }).ExcludeFromDescription();

View File

@ -1,5 +1,4 @@
using Asp.Versioning; using Brizco.Common.Extensions;
using Brizco.Common.Extensions;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Pluralize.NET; using Pluralize.NET;
@ -10,7 +9,7 @@ namespace Brizco.Api.WebFramework.Swagger;
public static class SwaggerConfiguration public static class SwaggerConfiguration
{ {
public static void AddCustomSwagger(this IServiceCollection services,string baseUrl) public static void AddCustomSwagger(this IServiceCollection services, string baseUrl)
{ {
services.AddSwaggerGen(options => services.AddSwaggerGen(options =>
{ {
@ -20,9 +19,9 @@ public static class SwaggerConfiguration
new OpenApiInfo new OpenApiInfo
{ {
Version = "v1", Version = "v1",
Title = "BrizCo Api Document", Title = "GolBarg Api Document",
Description = "BrizCo api document OpenApi based", Description = "GolBarg api for clients that wana use , based OpenApi",
License = new OpenApiLicense { Name = "Briz Corp" }, License = new OpenApiLicense { Name = "Vira Safir Fanavar " },
Contact = new OpenApiContact Contact = new OpenApiContact
{ {
Name = "Amir Hossein Khademi", Name = "Amir Hossein Khademi",
@ -85,7 +84,7 @@ public static class SwaggerConfiguration
}); });
} }
public static void UseCustomSwagger(this IApplicationBuilder app,string baseUrl) public static void UseCustomSwagger(this IApplicationBuilder app, string baseUrl)
{ {
app.UseSwagger(options => app.UseSwagger(options =>
{ {
@ -195,13 +194,17 @@ public class ApplySummariesOperationFilter : IOperationFilter
public void Apply(OpenApiOperation operation, OperationFilterContext context) public void Apply(OpenApiOperation operation, OperationFilterContext context)
{ {
var controllerActionDescriptor = context.ApiDescription.ActionDescriptor as ControllerActionDescriptor; var controllerActionDescriptor = context.ApiDescription.ActionDescriptor as ControllerActionDescriptor;
if (controllerActionDescriptor == null) return; if (controllerActionDescriptor == null)
{
operation.Summary = context.ApiDescription.ActionDescriptor.DisplayName;
return;
}
var pluralizer = new Pluralizer(); var pluralizer = new Pluralizer();
var actionName = controllerActionDescriptor.ActionName; var actionName = controllerActionDescriptor.ActionName;
var singularizeName = pluralizer.Singularize(controllerActionDescriptor.ControllerName); var singularizeName = pluralizer.Singularize(controllerActionDescriptor.ControllerName);
var pluralizeName = pluralizer.Pluralize(singularizeName); var pluralizeName = pluralizer.Pluralize(controllerActionDescriptor.DisplayName);
var parameterCount = operation.Parameters.Where(p => p.Name != "version" && p.Name != "api-version").Count(); var parameterCount = operation.Parameters.Where(p => p.Name != "version" && p.Name != "api-version").Count();

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <!--<PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
@ -12,9 +12,9 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" />
</ItemGroup> </ItemGroup>-->
<!--<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
@ -25,7 +25,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
</ItemGroup>--> </ItemGroup>
<ItemGroup> <ItemGroup>
<Using Include="MD.PersianDateTime.Standard" /> <Using Include="MD.PersianDateTime.Standard" />

View File

@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<Folder Include="Models\Api\" /> <Folder Include="Models\Api\" />
<Folder Include="QuartzServices\Commands\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -35,6 +36,7 @@
<Using Include="Brizco.Core.CoreServices.ReportServices.Commands" /> <Using Include="Brizco.Core.CoreServices.ReportServices.Commands" />
<Using Include="Brizco.Core.EntityServices.Abstracts" /> <Using Include="Brizco.Core.EntityServices.Abstracts" />
<Using Include="Brizco.Core.MartenServices.Abstracts" /> <Using Include="Brizco.Core.MartenServices.Abstracts" />
<Using Include="Brizco.Core.QuartzServices.Commands" />
<Using Include="Brizco.Domain" /> <Using Include="Brizco.Domain" />
<Using Include="Brizco.Domain.CommandQueries.Commands" /> <Using Include="Brizco.Domain.CommandQueries.Commands" />
<Using Include="Brizco.Domain.CommandQueries.Queries" /> <Using Include="Brizco.Domain.CommandQueries.Queries" />
@ -43,8 +45,11 @@
<Using Include="Brizco.Domain.Dtos.RequestDtos" /> <Using Include="Brizco.Domain.Dtos.RequestDtos" />
<Using Include="Brizco.Domain.Dtos.ResponseDto" /> <Using Include="Brizco.Domain.Dtos.ResponseDto" />
<Using Include="Brizco.Domain.Dtos.SmallDtos" /> <Using Include="Brizco.Domain.Dtos.SmallDtos" />
<Using Include="Brizco.Domain.Entities.Complex" /> <Using Include="Brizco.Domain.Entities.Complexes" />
<Using Include="Brizco.Domain.Entities.User" /> <Using Include="Brizco.Domain.Entities.Routines" />
<Using Include="Brizco.Domain.Entities.ShiftPlans" />
<Using Include="Brizco.Domain.Entities.Shifts" />
<Using Include="Brizco.Domain.Entities.Users" />
<Using Include="Brizco.Domain.Enums" /> <Using Include="Brizco.Domain.Enums" />
<Using Include="Brizco.Domain.Mappers" /> <Using Include="Brizco.Domain.Mappers" />
<Using Include="Brizco.Domain.MartenEntities.Brews" /> <Using Include="Brizco.Domain.MartenEntities.Brews" />

View File

@ -1,6 +1,6 @@
using System.Threading; using System.Threading;
using Brizco.Domain.Entities.Complexes; using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.ShiftPlans;
using Brizco.Domain.Entities.Users; using Brizco.Domain.Entities.Users;
using NPOI.SS.Formula.Functions; using NPOI.SS.Formula.Functions;
@ -168,8 +168,6 @@ public class AccountService : IAccountService
throw new AppException("نام و نام خانوادگی را وارد کنید"); throw new AppException("نام و نام خانوادگی را وارد کنید");
if (requestDto.ComplexName.IsNullOrEmpty()) if (requestDto.ComplexName.IsNullOrEmpty())
throw new AppException("نام مجموعه را وارد کنید"); throw new AppException("نام مجموعه را وارد کنید");
if (requestDto.ComplexAddress.IsNullOrEmpty())
throw new AppException("آدرس مجموعه را وارد کنید");

View File

@ -1,10 +1,5 @@
using Task = Brizco.Domain.Entities.Tasks.Task; using Brizco.Domain.Entities.Tasks;
using System.Linq; using Task = Brizco.Domain.Entities.Tasks.Task;
using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Routines;
using Brizco.Domain.Entities.Shifts;
using Brizco.Domain.Entities.Tasks;
using Brizco.Domain.Entities.Users;
namespace Brizco.Core.CoreServices; namespace Brizco.Core.CoreServices;

View File

@ -1,5 +1,4 @@
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.Tasks;
using Brizco.Domain.Entities.Tasks;
using Task = Brizco.Domain.Entities.Tasks.Task; using Task = Brizco.Domain.Entities.Tasks.Task;
namespace Brizco.Core.EntityServices; namespace Brizco.Core.EntityServices;
@ -95,6 +94,7 @@ public class ActivityService : IActivityService
var tasks = new List<Task>(); var tasks = new List<Task>();
tasks.AddRange(weeklyTasks); tasks.AddRange(weeklyTasks);
tasks.AddRange(dailyTasks); tasks.AddRange(dailyTasks);
tasks.AddRange(customTasks); tasks.AddRange(customTasks);

View File

@ -1,50 +1,39 @@
using Brizco.Domain.Entities.Shifts; namespace Brizco.Core.EntityServices;
namespace Brizco.Core.EntityServices; public class ShiftPlanService(IMediator mediator, IActivityService activityService, IRepositoryWrapper repositoryWrapper) : IShiftPlanService
public class ShiftPlanService : IShiftPlanService
{ {
private readonly ISender _sender;
private readonly IActivityService _activityService;
private readonly IRepositoryWrapper _repositoryWrapper;
public ShiftPlanService(ISender sender,IActivityService activityService,IRepositoryWrapper repositoryWrapper)
{
_sender = sender;
_activityService = activityService;
_repositoryWrapper = repositoryWrapper;
}
public async Task ChangeShiftPlanTaskStatusAsync(Guid shiftPlanId, bool isChangeToShift, bool isDisable) public async Task ChangeShiftPlanTaskStatusAsync(Guid shiftPlanId, bool isChangeToShift, bool isDisable)
{ {
var shiftPlan = await _sender.Send(new GetShiftPlanQuery(shiftPlanId)); var shiftPlan = await mediator.Send(new GetShiftPlanQuery(shiftPlanId));
} }
public async Task<bool> CreateAsync(CreateShiftPlanCommand createShiftPlanCommand, CancellationToken cancellationToken) public async Task<bool> CreateAsync(CreateShiftPlanCommand createShiftPlanCommand, CancellationToken cancellationToken)
{ {
var shiftPlan = await _sender.Send(createShiftPlanCommand, cancellationToken); var shiftPlan = await mediator.Send(createShiftPlanCommand, cancellationToken);
await _activityService.CreateActivitiesByShiftPlan(shiftPlan.Id, cancellationToken); await activityService.CreateActivitiesByShiftPlan(shiftPlan.Id, cancellationToken);
await mediator.Send(new CreateShiftPlanNotificationsCommand(shiftPlan.Id), cancellationToken);
return true; return true;
} }
public async Task<bool> UpdateAsync(UpdateShiftPlanCommand updateShiftPlanCommand, CancellationToken cancellationToken) public async Task<bool> UpdateAsync(UpdateShiftPlanCommand updateShiftPlanCommand, CancellationToken cancellationToken)
{ {
await _sender.Send(updateShiftPlanCommand, cancellationToken); await mediator.Send(updateShiftPlanCommand, cancellationToken);
await _activityService.UpdateActivitiesByShiftPlan(updateShiftPlanCommand.Id, cancellationToken); await activityService.UpdateActivitiesByShiftPlan(updateShiftPlanCommand.Id, cancellationToken);
return true; return true;
} }
public async Task<bool> CompleteShiftPlanAsync(Guid id, CompleteShiftPlanRequestDto requestDtos, CancellationToken cancellationToken) public async Task<bool> CompleteShiftPlanAsync(Guid id, CompleteShiftPlanRequestDto requestDtos, CancellationToken cancellationToken)
{ {
var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>() var shiftPlan = await repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == id, cancellationToken); .TableNoTracking.FirstOrDefaultAsync(s => s.Id == id, cancellationToken);
if (shiftPlan == null) if (shiftPlan == null)
throw new AppException("Shift plan not found", ApiResultStatusCode.NotFound); throw new AppException("Shift plan not found", ApiResultStatusCode.NotFound);
shiftPlan.CompletePlan(requestDtos.CompleteDescription,requestDtos.CompletePercent); shiftPlan.CompletePlan(requestDtos.CompleteDescription,requestDtos.CompletePercent);
_repositoryWrapper.SetRepository<ShiftPlan>().Update(shiftPlan); repositoryWrapper.SetRepository<ShiftPlan>().Update(shiftPlan);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await repositoryWrapper.SaveChangesAsync(cancellationToken);
await _activityService.CompleteActivitiesAsync(requestDtos.CompleteActivities, cancellationToken); await activityService.CompleteActivitiesAsync(requestDtos.CompleteActivities, cancellationToken);
return true; return true;
} }
} }

View File

@ -0,0 +1,4 @@
namespace Brizco.Core.QuartzServices.Commands;
public record SetShiftPlanNotificationScheduleCommand(Guid ShiftPlanId) : IRequest<bool>;
public record CreateShiftPlanNotificationsCommand(Guid ShiftPlanId , bool InStart) : IRequest<bool>;

View File

@ -0,0 +1,38 @@
using Brizco.Domain.Entities.ShiftPlans;
namespace Brizco.Core.QuartzServices.Handlers;
public class CreateShiftPlanNotificationsCommandHandler(IMediator mediator,IRepositoryWrapper repositoryWrapper)
: IRequestHandler<CreateShiftPlanNotificationsCommand,bool>
{
public async Task<bool> Handle(CreateShiftPlanNotificationsCommand request, CancellationToken cancellationToken)
{
if (request.InStart)
{
await mediator.Send(new SetShiftPlanNotificationScheduleCommand(request.ShiftPlanId), cancellationToken);
}
else
{
var shiftPlan = await repositoryWrapper.SetRepository<ShiftPlan>().TableNoTracking
.Where(s => s.Id == request.ShiftPlanId)
.Select(ShiftPlanMapper.ProjectToSDto)
.FirstOrDefaultAsync(cancellationToken);
if (shiftPlan == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "ShiftPlan not found in create shift plan notification");
var shiftPlanUsers = await repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking
.Where(f => f.ShiftPlanId == request.ShiftPlanId)
.ToListAsync(cancellationToken);
foreach (var shiftPlanUser in shiftPlanUsers)
{
var completeShiftMessageForUser = $"";
await mediator.Send( new CreateNotificationCommand(completeShiftMessageForUser, shiftPlanUser.UserId, shiftPlan.ComplexId), cancellationToken);
}
}
return true;
}
}

View File

@ -0,0 +1,70 @@
using Brizco.Core.QuartzServices.Commands;
using Quartz;
namespace Brizco.Core.QuartzServices.Handlers;
public class SetShiftPlanNotificationScheduleCommandHandler(IRepositoryWrapper repositoryWrapper,IScheduler scheduler) : IRequestHandler<SetShiftPlanNotificationScheduleCommand,bool>
{
public async Task<bool> Handle(SetShiftPlanNotificationScheduleCommand request, CancellationToken cancellationToken)
{
var shiftPlan = await repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking
.FirstOrDefaultAsync(sp => sp.Id == request.ShiftPlanId, cancellationToken);
if (shiftPlan == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "ShiftPlan not found in set schedule");
var shift = await repositoryWrapper.SetRepository<Shift>()
.TableNoTracking
.FirstOrDefaultAsync(s => s.Id == shiftPlan.ShiftId, cancellationToken);
if(shift == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Shift not found in set schedule");
var shiftPlanStartAt = (new DateTime(shiftPlan.PlanFor.Year, shiftPlan.PlanFor.Month, shiftPlan.PlanFor.Day, shift.StartAt.Hours,shift.StartAt.Minutes,shift.StartAt.Seconds)).ToUniversalTime();
var shiftPlanEndAt = (new DateTime(shiftPlan.PlanFor.Year, shiftPlan.PlanFor.Month, shiftPlan.PlanFor.Day, shift.EndAt.Hours, shift.EndAt.Minutes, shift.EndAt.Seconds)).ToUniversalTime();
var startTimeOffset = new DateTimeOffset(shiftPlanStartAt.Year, shiftPlanStartAt.Month, shiftPlanStartAt.Day, shiftPlanStartAt.Hour,
shiftPlanStartAt.Minute, shiftPlanStartAt.Second, TimeSpan.Zero);
var endTimeOffset = new DateTimeOffset(shiftPlanEndAt.Year, shiftPlanEndAt.Month, shiftPlanEndAt.Day, shiftPlanEndAt.Hour,
shiftPlanEndAt.Minute, shiftPlanEndAt.Second, TimeSpan.Zero);
IJobDetail beforeEndShift30Min = JobBuilder.Create<ShiftPlanNotificationScheduledJob>()
.WithIdentity(ShiftPlanNotifyType.BeforeEndShift30Min.ToString(), shiftPlan.Id.ToString())
.Build();
ITrigger beforeEndShift30MinTrigger = TriggerBuilder.Create()
.WithIdentity(StringExtensions.GetId(9), shift.ComplexId.ToString())
.WithSimpleSchedule(x => x.WithRepeatCount(0))
.StartAt(endTimeOffset.AddMinutes(-40))
.Build();
IJobDetail endOfShift = JobBuilder.Create<ShiftPlanNotificationScheduledJob>()
.WithIdentity(ShiftPlanNotifyType.EndOfShift.ToString(), shiftPlan.Id.ToString())
.Build();
ITrigger endOfShiftTrigger = TriggerBuilder.Create()
.WithIdentity(StringExtensions.GetId(9), shift.ComplexId.ToString())
.WithSimpleSchedule(x => x.WithRepeatCount(0))
.StartAt(endTimeOffset)
.Build();
IJobDetail afterStartShift2Hour = JobBuilder.Create<ShiftPlanNotificationScheduledJob>()
.WithIdentity(ShiftPlanNotifyType.AfterStartShift2Hour.ToString(), shiftPlan.Id.ToString())
.Build();
ITrigger afterStartShift2HourTrigger = TriggerBuilder.Create()
.WithIdentity(StringExtensions.GetId(9), shift.ComplexId.ToString())
.WithSimpleSchedule(x => x.WithRepeatCount(0))
.StartAt(startTimeOffset.AddHours(2))
.Build();
await scheduler.ScheduleJob(beforeEndShift30Min, beforeEndShift30MinTrigger, cancellationToken);
await scheduler.ScheduleJob(endOfShift, endOfShiftTrigger, cancellationToken);
await scheduler.ScheduleJob(afterStartShift2Hour, afterStartShift2HourTrigger, cancellationToken);
return true;
}
}

View File

@ -18,18 +18,7 @@ public class JobScheduler
{ {
_scheduler.Start(); _scheduler.Start();
//IJobDetail job = JobBuilder.Create<NotificationScheduledJob>() _logger.LogInformation($"======== Scheduler Start ===========");
// .WithIdentity("NotificationJob", "notification")
// .Build();
//ITrigger trigger = TriggerBuilder.Create()
// .WithIdentity("NotificationJobTrigger", "notification")
// .WithSimpleSchedule(x=>x.WithIntervalInHours(12))
// .StartNow()
// .Build();
//var offset = _scheduler.ScheduleJob(job, trigger);
//_logger.LogInformation($"======== NOTIFICATION Schedulers Set For {offset.Result.ToString()} IN {DateTime.Now.ToString()} ===========");
} }
} }

View File

@ -1,38 +0,0 @@
using Brizco.Domain.Entities.Shifts;
using Microsoft.Extensions.Logging;
using Quartz;
namespace Brizco.Core.QuartzServices;
public class NotificationScheduledJob : IJob
{
private readonly ILogger<NotificationScheduledJob> _logger;
private readonly IScheduler _scheduler;
private readonly IRepositoryWrapper _repositoryWrapper;
public NotificationScheduledJob(ILogger<NotificationScheduledJob> logger,IScheduler scheduler,IRepositoryWrapper repositoryWrapper)
{
_logger = logger;
_scheduler = scheduler;
_repositoryWrapper = repositoryWrapper;
}
public async Task Execute(IJobExecutionContext context)
{
var currentShiftPlans = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking
.Where(s => s.PlanFor.Date >= DateTime.Today.Date)
.ToListAsync();
IJobDetail job = JobBuilder.Create<NotificationScheduledJob>()
.WithIdentity("NotificationJob", "notification")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("NotificationJobTrigger", "notification")
.StartNow()
.Build();
var offset = _scheduler.ScheduleJob(job, trigger);
_logger.LogInformation($"Notification Job Done At : {DateTime.Now}");
}
}

View File

@ -0,0 +1,80 @@
using Brizco.Domain.Entities.ShiftPlans;
using Brizco.Domain.Entities.Tasks;
using Microsoft.Extensions.Logging;
using Quartz;
using Task = System.Threading.Tasks.Task;
namespace Brizco.Core.QuartzServices;
public class ShiftPlanNotificationScheduledJob : IJob
{
private readonly ILogger<ShiftPlanNotificationScheduledJob> _logger;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly IMediator _mediator;
public ShiftPlanNotificationScheduledJob(ILogger<ShiftPlanNotificationScheduledJob> logger,IRepositoryWrapper repositoryWrapper,IMediator mediator)
{
_logger = logger;
_repositoryWrapper = repositoryWrapper;
_mediator = mediator;
}
public async Task Execute(IJobExecutionContext context)
{
try
{
var notifyType = (ShiftPlanNotifyType)int.Parse(context.JobDetail.Key.Name);
var shiftPlanId = Guid.Parse(context.JobDetail.Key.Group);
var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>().TableNoTracking
.FirstOrDefaultAsync(f => f.Id == shiftPlanId);
if (shiftPlan == null)
throw new Exception("Shift plan not found");
var shiftPlanUsers = await _repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking
.Where(f => f.ShiftPlanId == shiftPlanId)
.ToListAsync();
var superVisorId = shiftPlan.SupervisorId;
switch (notifyType)
{
case ShiftPlanNotifyType.None:
return;
break;
case ShiftPlanNotifyType.BeforeEndShift30Min:
var activities = await _repositoryWrapper.SetRepository<Activity>().TableNoTracking
.Where(a => a.ShiftPlanId == shiftPlanId).ToListAsync();
foreach (var shiftPlanUser in shiftPlanUsers)
{
var unDoneCount = activities.Count(a => a.UserId == shiftPlanUser.UserId && a.IsDone == false);
if(unDoneCount == 0)
continue;
string message = $"شما تعداد {unDoneCount} وظیفه انجام نشده در شیفت مورد نظر دارید ، نیم ساعت به پایان شیفت مانده است";
await _mediator.Send(new CreateNotificationCommand(message, shiftPlanUser.UserId, shiftPlan.ComplexId));
}
break;
case ShiftPlanNotifyType.EndOfShift:
var activitiesEndShift = await _repositoryWrapper.SetRepository<Activity>().TableNoTracking
.Where(a => a.ShiftPlanId == shiftPlanId).ToListAsync();
foreach (var shiftPlanUser in shiftPlanUsers)
{
var unDoneCount = activitiesEndShift.Count(a => a.UserId == shiftPlanUser.UserId && a.IsDone == false);
if (unDoneCount == 0)
continue;
string message = $"شما تعداد {unDoneCount} وظیفه انجام نشده در شیفت مورد نظر دارید";
await _mediator.Send(new CreateNotificationCommand(message, shiftPlanUser.UserId, shiftPlan.ComplexId));
}
string superVisorAfterShiftMessage = $"سوپر وایزر محترم ، شیفت مورد نظر به پایان رسیده است ، لطفا فعالیت ها را رسیدگی کنید";
await _mediator.Send(new CreateNotificationCommand(superVisorAfterShiftMessage, shiftPlan.SupervisorId, shiftPlan.ComplexId));
break;
case ShiftPlanNotifyType.AfterStartShift2Hour:
break;
default:
return;
}
}
catch (Exception e)
{
_logger.LogError(e.Message);
}
}
}

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <!--<PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
@ -13,10 +13,10 @@
<PackageReference Include="MediatR" Version="12.3.0" /> <PackageReference Include="MediatR" Version="12.3.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.6" /> <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.6" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" /> <PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
</ItemGroup> </ItemGroup>-->
<!--<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<LangVersion>10</LangVersion> <LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
@ -32,7 +32,7 @@
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" /> <PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
</ItemGroup>--> </ItemGroup>
<Target Name="Mapster"> <Target Name="Mapster">
@ -55,12 +55,10 @@
<Using Include="Brizco.Domain.Dtos.LargeDtos" /> <Using Include="Brizco.Domain.Dtos.LargeDtos" />
<Using Include="Brizco.Domain.Dtos.ResponseDto" /> <Using Include="Brizco.Domain.Dtos.ResponseDto" />
<Using Include="Brizco.Domain.Dtos.SmallDtos" /> <Using Include="Brizco.Domain.Dtos.SmallDtos" />
<Using Include="Brizco.Domain.Entities.Complex" />
<Using Include="Brizco.Domain.Entities.Complexes" /> <Using Include="Brizco.Domain.Entities.Complexes" />
<Using Include="Brizco.Domain.Entities.Routine" /> <Using Include="Brizco.Domain.Entities.Routines" />
<Using Include="Brizco.Domain.Entities.Shift" /> <Using Include="Brizco.Domain.Entities.ShiftPlans" />
<Using Include="Brizco.Domain.Entities.Shifts" /> <Using Include="Brizco.Domain.Entities.Shifts" />
<Using Include="Brizco.Domain.Entities.Task" />
<Using Include="Brizco.Domain.Entities.Users" /> <Using Include="Brizco.Domain.Entities.Users" />
<Using Include="Brizco.Domain.Enums" /> <Using Include="Brizco.Domain.Enums" />
<Using Include="Mapster" /> <Using Include="Mapster" />

View File

@ -1,4 +1,4 @@
namespace Brizco.Domain.CommandQueries.Commands; namespace Brizco.Domain.CommandQueries.Commands;
public record CreateNotificationCommand(string Message,Guid UserId) : IRequest<Guid>; public record CreateNotificationCommand(string Message,Guid UserId,Guid ComplexId) : IRequest<Guid>;
public record ReadNotificationCommand(Guid Id) : IRequest<bool>; public record ReadNotificationCommand(Guid Id) : IRequest<bool>;

View File

@ -13,6 +13,7 @@ public class ShiftPlanSDto : BaseDto<ShiftPlanSDto,ShiftPlan>
public int CompletePercent { get; set; } public int CompletePercent { get; set; }
public string SupervisorFullName { get; set; } = string.Empty; public string SupervisorFullName { get; set; } = string.Empty;
public string CompleteDescription { get; set; } = string.Empty; public string CompleteDescription { get; set; } = string.Empty;
public Guid ComplexId { get; set; }
public Guid ShiftId { get; set; } public Guid ShiftId { get; set; }
public string ShiftTitle { get; set; } = string.Empty; public string ShiftTitle { get; set; } = string.Empty;
public TimeSpan StartAt { get; set; } public TimeSpan StartAt { get; set; }

View File

@ -1,4 +1,4 @@
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.ShiftPlans;
namespace Brizco.Domain.Dtos.SmallDtos; namespace Brizco.Domain.Dtos.SmallDtos;

View File

@ -0,0 +1,17 @@
namespace Brizco.Domain.Entities.ShiftPlans;
public partial class ShiftPlan
{
public ShiftPlanUser AddUser(Guid positionId, Guid userId)
{
var planUser = new ShiftPlanUser(Id, positionId, userId);
Users.Add(planUser);
return planUser;
}
public void CompletePlan(string completeDescription, int completePercent)
{
IsCompleted = true;
CompleteDescription = completeDescription;
CompletePercent = completePercent;
}
}

View File

@ -1,7 +1,5 @@
using Brizco.Domain.Entities.Routines; 
using Brizco.Domain.Entities.Users; namespace Brizco.Domain.Entities.ShiftPlans;
namespace Brizco.Domain.Entities.Shifts;
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] [AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
[AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget)] [AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget)]
@ -25,6 +23,7 @@ public partial class ShiftPlan : ApiEntity
public DateTime PlanFor { get; internal set; } public DateTime PlanFor { get; internal set; }
public bool IsCompleted { get; internal set; } public bool IsCompleted { get; internal set; }
public bool IsScheduled { get; internal set; }
public int CompletePercent { get; internal set; } public int CompletePercent { get; internal set; }
public string CompleteDescription { get; internal set; } = string.Empty; public string CompleteDescription { get; internal set; } = string.Empty;

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Entities.Users; namespace Brizco.Domain.Entities.ShiftPlans;
namespace Brizco.Domain.Entities.Shifts;
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] [AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
[GenerateMapper] [GenerateMapper]
@ -8,10 +6,10 @@ public class ShiftPlanUser : ApiEntity
{ {
public ShiftPlanUser() public ShiftPlanUser()
{ {
} }
public ShiftPlanUser(Guid shiftPlanId,Guid positionId, Guid userId) public ShiftPlanUser(Guid shiftPlanId, Guid positionId, Guid userId)
{ {
ShiftPlanId = shiftPlanId; ShiftPlanId = shiftPlanId;
PositionId = positionId; PositionId = positionId;

View File

@ -26,20 +26,3 @@ public partial class Shift
return routine; return routine;
} }
} }
public partial class ShiftPlan
{
public ShiftPlanUser AddUser(Guid positionId,Guid userId)
{
var planUser = new ShiftPlanUser(Id , positionId, userId);
Users.Add(planUser);
return planUser;
}
public void CompletePlan(string completeDescription,int completePercent)
{
IsCompleted = true;
CompleteDescription = completeDescription;
CompletePercent = completePercent;
}
}

View File

@ -0,0 +1,9 @@
namespace Brizco.Domain.Enums;
public enum ShiftPlanNotifyType
{
None = 0,
BeforeEndShift30Min = 1,
EndOfShift = 2,
AfterStartShift2Hour = 3
}

View File

@ -2,7 +2,7 @@ using System;
using System.Linq.Expressions; using System.Linq.Expressions;
using Brizco.Domain.Dtos.LargeDtos; using Brizco.Domain.Dtos.LargeDtos;
using Brizco.Domain.Dtos.SmallDtos; using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.ShiftPlans;
using Brizco.Domain.Entities.Tasks; using Brizco.Domain.Entities.Tasks;
using Brizco.Domain.Entities.Users; using Brizco.Domain.Entities.Users;
using Mapster.Models; using Mapster.Models;

View File

@ -6,6 +6,7 @@ using Brizco.Domain.Dtos.LargeDtos;
using Brizco.Domain.Dtos.SmallDtos; using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Complexes; using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Routines; using Brizco.Domain.Entities.Routines;
using Brizco.Domain.Entities.ShiftPlans;
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.Shifts;
using Brizco.Domain.Entities.Users; using Brizco.Domain.Entities.Users;
using Mapster.Models; using Mapster.Models;

View File

@ -2,7 +2,7 @@ using System;
using System.Linq.Expressions; using System.Linq.Expressions;
using Brizco.Domain.Dtos.SmallDtos; using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Complexes; using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.ShiftPlans;
using Brizco.Domain.Entities.Users; using Brizco.Domain.Entities.Users;
using Mapster.Models; using Mapster.Models;

View File

@ -9,7 +9,6 @@ using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.Shifts;
using Brizco.Domain.Entities.Tasks; using Brizco.Domain.Entities.Tasks;
using Mapster.Models; using Mapster.Models;
using Task = Brizco.Domain.Entities.Tasks.Task;
namespace Brizco.Domain.Mappers namespace Brizco.Domain.Mappers
{ {

View File

@ -4,7 +4,6 @@ using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Complexes; using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Tasks; using Brizco.Domain.Entities.Tasks;
using Mapster.Models; using Mapster.Models;
using Task = Brizco.Domain.Entities.Tasks.Task;
namespace Brizco.Domain.Mappers namespace Brizco.Domain.Mappers
{ {

View File

@ -4,7 +4,6 @@ using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.Shifts;
using Brizco.Domain.Entities.Tasks; using Brizco.Domain.Entities.Tasks;
using Mapster.Models; using Mapster.Models;
using Task = Brizco.Domain.Entities.Tasks.Task;
namespace Brizco.Domain.Mappers namespace Brizco.Domain.Mappers
{ {

View File

@ -1,6 +1,6 @@
using Brizco.Domain.Dtos.LargeDtos; using Brizco.Domain.Dtos.LargeDtos;
using Brizco.Domain.Entities.Complexes; using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.ShiftPlans;
using Brizco.Domain.Entities.Tasks; using Brizco.Domain.Entities.Tasks;
using MD.PersianDateTime.Standard; using MD.PersianDateTime.Standard;
using Task = Brizco.Domain.Entities.Tasks.Task; using Task = Brizco.Domain.Entities.Tasks.Task;

View File

@ -46,8 +46,12 @@
<Using Include="Brizco.Domain.Dtos.LargeDtos" /> <Using Include="Brizco.Domain.Dtos.LargeDtos" />
<Using Include="Brizco.Domain.Dtos.ResponseDto" /> <Using Include="Brizco.Domain.Dtos.ResponseDto" />
<Using Include="Brizco.Domain.Dtos.SmallDtos" /> <Using Include="Brizco.Domain.Dtos.SmallDtos" />
<Using Include="Brizco.Domain.Entities.Complex" /> <Using Include="Brizco.Domain.Entities.Complexes" />
<Using Include="Brizco.Domain.Entities.ShiftPlans" />
<Using Include="Brizco.Domain.Entities.Shifts" />
<Using Include="Brizco.Domain.Entities.Users" />
<Using Include="Brizco.Repository.Abstracts" /> <Using Include="Brizco.Repository.Abstracts" />
<Using Include="Brizco.Repository.Extensions" />
<Using Include="Brizco.Repository.Repositories.Marten" /> <Using Include="Brizco.Repository.Repositories.Marten" />
<Using Include="MediatR" /> <Using Include="MediatR" />
<Using Include="Brizco.Common.Extensions" /> <Using Include="Brizco.Common.Extensions" />

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.Activities;
namespace Brizco.Repository.Handlers.Activity;
public class CreateActivityCommandHandler : IRequestHandler<CreateActivityCommand, ActivityLDto> public class CreateActivityCommandHandler : IRequestHandler<CreateActivityCommand, ActivityLDto>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Activity; namespace Brizco.Repository.Handlers.Activities;
public class DeleteActivityCommandHandler : IRequestHandler<DeleteActivityCommand, bool> public class DeleteActivityCommandHandler : IRequestHandler<DeleteActivityCommand, bool>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Activity; namespace Brizco.Repository.Handlers.Activities;
public class GetActivitiesQueryHandler : IRequestHandler<GetActivitiesQuery, List<ActivitySDto>> public class GetActivitiesQueryHandler : IRequestHandler<GetActivitiesQuery, List<ActivitySDto>>
{ {

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.Activities;
namespace Brizco.Repository.Handlers.Activity;
public class GetActivityQueryHandler : IRequestHandler<GetActivityQuery, ActivityLDto> public class GetActivityQueryHandler : IRequestHandler<GetActivityQuery, ActivityLDto>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Activity; namespace Brizco.Repository.Handlers.Activities;
public class GetShiftPlanActivitiesQueryHandler : IRequestHandler<GetShiftPlanActivitiesQuery, List<ActivitySDto>> public class GetShiftPlanActivitiesQueryHandler : IRequestHandler<GetShiftPlanActivitiesQuery, List<ActivitySDto>>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Activity; namespace Brizco.Repository.Handlers.Activities;
public class UpdateActivityCommandHandler : IRequestHandler<UpdateActivityCommand, bool> public class UpdateActivityCommandHandler : IRequestHandler<UpdateActivityCommand, bool>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Complex; namespace Brizco.Repository.Handlers.Complexes;
public class CreateComplexCommandHandler : IRequestHandler<CreateComplexCommand, ComplexSDto> public class CreateComplexCommandHandler : IRequestHandler<CreateComplexCommand, ComplexSDto>
{ {
@ -16,8 +16,8 @@ public class CreateComplexCommandHandler : IRequestHandler<CreateComplexCommand,
try try
{ {
await _repositoryWrapper.BeginTransaction(cancellationToken); await _repositoryWrapper.BeginTransaction(cancellationToken);
var complex = Domain.Entities.Complexes.Complex.Create(request.Name, request.Address, request.SupportPhone); var complex = Complex.Create(request.Name, request.Address, request.SupportPhone);
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>().Add(complex); _repositoryWrapper.SetRepository<Complex>().Add(complex);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);
await _repositoryWrapper.CommitAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken);
return complex.AdaptToSDto(); return complex.AdaptToSDto();

View File

@ -1,8 +1,4 @@
using Brizco.Domain.Entities.Complexes; namespace Brizco.Repository.Handlers.Complexes;
using Brizco.Domain.Entities.Users;
using Microsoft.AspNetCore.Identity;
namespace Brizco.Repository.Handlers.Complex;
public class CreateComplexUserCommandHandler : IRequestHandler<CreateComplexUserCommand, ComplexUserSDto> public class CreateComplexUserCommandHandler : IRequestHandler<CreateComplexUserCommand, ComplexUserSDto>
{ {
@ -27,7 +23,7 @@ public class CreateComplexUserCommandHandler : IRequestHandler<CreateComplexUser
try try
{ {
//await _repositoryWrapper.BeginTransaction(cancellationToken); //await _repositoryWrapper.BeginTransaction(cancellationToken);
var complex = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>().TableNoTracking var complex = await _repositoryWrapper.SetRepository<Complex>().TableNoTracking
.FirstOrDefaultAsync(c => c.Id == request.ComplexId, cancellationToken); .FirstOrDefaultAsync(c => c.Id == request.ComplexId, cancellationToken);
if (complex == null) if (complex == null)
throw new AppException("Complex not found", ApiResultStatusCode.NotFound); throw new AppException("Complex not found", ApiResultStatusCode.NotFound);

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Complex; namespace Brizco.Repository.Handlers.Complexes;
public class DeleteComplexCommandHandler : IRequestHandler<DeleteComplexCommand, bool> public class DeleteComplexCommandHandler : IRequestHandler<DeleteComplexCommand, bool>
{ {
@ -13,12 +13,12 @@ public class DeleteComplexCommandHandler : IRequestHandler<DeleteComplexCommand,
try try
{ {
await _repositoryWrapper.BeginTransaction(cancellationToken); await _repositoryWrapper.BeginTransaction(cancellationToken);
var task = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>() var task = await _repositoryWrapper.SetRepository<Complex>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); .FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (task == null) if (task == null)
throw new AppException("Task not found", ApiResultStatusCode.NotFound); throw new AppException("Task not found", ApiResultStatusCode.NotFound);
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>() _repositoryWrapper.SetRepository<Complex>()
.Delete(task); .Delete(task);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Entities.Complexes; namespace Brizco.Repository.Handlers.Complexes;
namespace Brizco.Repository.Handlers.Complex;
public class DeleteComplexUserCommandHandler : IRequestHandler<DeleteComplexUserCommand, bool> public class DeleteComplexUserCommandHandler : IRequestHandler<DeleteComplexUserCommand, bool>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Complex; namespace Brizco.Repository.Handlers.Complexes;
public class GetComplexQueryHandler : IRequestHandler<GetComplexQuery, ComplexSDto> public class GetComplexQueryHandler : IRequestHandler<GetComplexQuery, ComplexSDto>
{ {
@ -11,7 +11,7 @@ public class GetComplexQueryHandler : IRequestHandler<GetComplexQuery, ComplexSD
public async Task<ComplexSDto> Handle(GetComplexQuery request, CancellationToken cancellationToken) public async Task<ComplexSDto> Handle(GetComplexQuery request, CancellationToken cancellationToken)
{ {
var complex = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>() var complex = await _repositoryWrapper.SetRepository<Complex>()
.TableNoTracking .TableNoTracking
.Where(s => s.Id == request.Id) .Where(s => s.Id == request.Id)
.Select(ComplexMapper.ProjectToSDto) .Select(ComplexMapper.ProjectToSDto)

View File

@ -1,8 +1,6 @@
using Brizco.Domain.Entities.Complexes; using Microsoft.IdentityModel.Tokens;
using Brizco.Domain.Entities.Users;
using Microsoft.IdentityModel.Tokens;
namespace Brizco.Repository.Handlers.Complex; namespace Brizco.Repository.Handlers.Complexes;
public class GetComplexUsersQueryHandler : IRequestHandler<GetComplexUsersQuery, List<ComplexUserSDto>> public class GetComplexUsersQueryHandler : IRequestHandler<GetComplexUsersQuery, List<ComplexUserSDto>>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Complex; namespace Brizco.Repository.Handlers.Complexes;
public class GetComplexesQueryHandler : IRequestHandler<GetComplexesQuery, List<ComplexSDto>> public class GetComplexesQueryHandler : IRequestHandler<GetComplexesQuery, List<ComplexSDto>>
{ {
@ -10,7 +10,7 @@ public class GetComplexesQueryHandler : IRequestHandler<GetComplexesQuery, List<
} }
public async Task<List<ComplexSDto>> Handle(GetComplexesQuery request, CancellationToken cancellationToken) public async Task<List<ComplexSDto>> Handle(GetComplexesQuery request, CancellationToken cancellationToken)
{ {
var tasks = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>().TableNoTracking var tasks = await _repositoryWrapper.SetRepository<Complex>().TableNoTracking
.OrderByDescending(s => s.CreatedAt) .OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15) .Skip(request.Page * 15).Take(15)
.Select(ComplexMapper.ProjectToSDto) .Select(ComplexMapper.ProjectToSDto)

View File

@ -1,8 +1,4 @@
using Brizco.Domain.Entities.Complexes; namespace Brizco.Repository.Handlers.Complexes;
using Brizco.Domain.Entities.Users;
using StackExchange.Redis;
namespace Brizco.Repository.Handlers.Complex;
public class UpdateComplexUserCommandHandler : IRequestHandler<UpdateComplexUserCommand, bool> public class UpdateComplexUserCommandHandler : IRequestHandler<UpdateComplexUserCommand, bool>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Position; namespace Brizco.Repository.Handlers.Positions;
public class CreatePositionCommandHandler : IRequestHandler<CreatePositionCommand, PositionSDto> public class CreatePositionCommandHandler : IRequestHandler<CreatePositionCommand, PositionSDto>
{ {
@ -21,7 +21,7 @@ public class CreatePositionCommandHandler : IRequestHandler<CreatePositionComman
try try
{ {
await _repositoryWrapper.BeginTransaction(cancellationToken); await _repositoryWrapper.BeginTransaction(cancellationToken);
var entity = Domain.Entities.Complexes.Position var entity = Position
.Create(request.Title, .Create(request.Title,
request.Description, request.Description,
complexId, complexId,
@ -29,7 +29,7 @@ public class CreatePositionCommandHandler : IRequestHandler<CreatePositionComman
request.Permissions.ForEach(f=>entity.AddPermission(f)); request.Permissions.ForEach(f=>entity.AddPermission(f));
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>().Add(entity); _repositoryWrapper.SetRepository<Position>().Add(entity);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);
await _repositoryWrapper.CommitAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken);
return entity.AdaptToSDto(); return entity.AdaptToSDto();

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Position; namespace Brizco.Repository.Handlers.Positions;
public class DeletePositionCommandHandler : IRequestHandler<DeletePositionCommand, bool> public class DeletePositionCommandHandler : IRequestHandler<DeletePositionCommand, bool>
{ {
@ -10,12 +10,12 @@ public class DeletePositionCommandHandler : IRequestHandler<DeletePositionComman
} }
public async Task<bool> Handle(DeletePositionCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(DeletePositionCommand request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>() var shift = await _repositoryWrapper.SetRepository<Position>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); .FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null) if (shift == null)
throw new AppException("Postion not found", ApiResultStatusCode.NotFound); throw new AppException("Postion not found", ApiResultStatusCode.NotFound);
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>() _repositoryWrapper.SetRepository<Position>()
.Delete(shift); .Delete(shift);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.Positions;
namespace Brizco.Repository.Handlers.Position;
public class GetPositionQueryHandler : IRequestHandler<GetPositionQuery, PositionLDto> public class GetPositionQueryHandler : IRequestHandler<GetPositionQuery, PositionLDto>
{ {
@ -12,7 +10,7 @@ public class GetPositionQueryHandler : IRequestHandler<GetPositionQuery, Positio
} }
public async Task<PositionLDto> Handle(GetPositionQuery request, CancellationToken cancellationToken) public async Task<PositionLDto> Handle(GetPositionQuery request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>() var shift = await _repositoryWrapper.SetRepository<Position>()
.TableNoTracking .TableNoTracking
.Where(s => s.Id == request.Id) .Where(s => s.Id == request.Id)
.Select(PositionMapper.ProjectToLDto) .Select(PositionMapper.ProjectToLDto)

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Position; namespace Brizco.Repository.Handlers.Positions;
public class GetPositionsQueryHandler : IRequestHandler<GetPositionsQuery, List<PositionSDto>> public class GetPositionsQueryHandler : IRequestHandler<GetPositionsQuery, List<PositionSDto>>
{ {
@ -18,7 +18,7 @@ public class GetPositionsQueryHandler : IRequestHandler<GetPositionsQuery, List<
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
var shifts = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>().TableNoTracking var shifts = await _repositoryWrapper.SetRepository<Position>().TableNoTracking
.Where(p=>p.ComplexId==complexId) .Where(p=>p.ComplexId==complexId)
.OrderByDescending(s => s.CreatedAt) .OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15) .Skip(request.Page * 15).Take(15)

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Entities.Complexes; namespace Brizco.Repository.Handlers.Positions;
namespace Brizco.Repository.Handlers.Position;
public class UpdatePositionCommandHandler : IRequestHandler<UpdatePositionCommand, bool> public class UpdatePositionCommandHandler : IRequestHandler<UpdatePositionCommand, bool>
{ {
@ -15,7 +13,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdatePositionComman
public async Task<bool> Handle(UpdatePositionCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(UpdatePositionCommand request, CancellationToken cancellationToken)
{ {
var ent = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>() var ent = await _repositoryWrapper.SetRepository<Position>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); .TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (ent == null) if (ent == null)
throw new AppException("Postion not found", ApiResultStatusCode.NotFound); throw new AppException("Postion not found", ApiResultStatusCode.NotFound);
@ -25,7 +23,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdatePositionComman
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
var newPosition = Domain.Entities.Complexes.Position.Create(request.Title, var newPosition = Position.Create(request.Title,
request.Description, request.Description,
complexId, complexId,
request.SectionId); request.SectionId);
@ -48,7 +46,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdatePositionComman
foreach (var permission in request.Permissions.Where(p => !permissionsDb.Select(d => d.Permission).Contains(p))) foreach (var permission in request.Permissions.Where(p => !permissionsDb.Select(d => d.Permission).Contains(p)))
newPosition.AddPermission(permission); newPosition.AddPermission(permission);
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>() _repositoryWrapper.SetRepository<Position>()
.Update(newPosition); .Update(newPosition);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Routine; namespace Brizco.Repository.Handlers.Routines;
public class CreateRoutineCommandHandler : IRequestHandler<CreateRoutineCommand, RoutineSDto> public class CreateRoutineCommandHandler : IRequestHandler<CreateRoutineCommand, RoutineSDto>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Routine; namespace Brizco.Repository.Handlers.Routines;
public class DeleteRoutineCommandHandler : IRequestHandler<DeleteRoutineCommand, bool> public class DeleteRoutineCommandHandler : IRequestHandler<DeleteRoutineCommand, bool>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Routine; namespace Brizco.Repository.Handlers.Routines;
public class GetRoutineQueryHandler : IRequestHandler<GetRoutineQuery, RoutineSDto> public class GetRoutineQueryHandler : IRequestHandler<GetRoutineQuery, RoutineSDto>
{ {

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Entities.Shifts; namespace Brizco.Repository.Handlers.Routines;
namespace Brizco.Repository.Handlers.Routine;
public class GetRoutineShiftsQueryHandler : IRequestHandler<GetRoutineShiftsQuery,List<RoutineShiftResponseDto>> public class GetRoutineShiftsQueryHandler : IRequestHandler<GetRoutineShiftsQuery,List<RoutineShiftResponseDto>>
{ {
@ -21,7 +19,7 @@ public class GetRoutineShiftsQueryHandler : IRequestHandler<GetRoutineShiftsQuer
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
foreach (var shiftRoutine in shiftRoutines) foreach (var shiftRoutine in shiftRoutines)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() var shift = await _repositoryWrapper.SetRepository<Shift>()
.TableNoTracking .TableNoTracking
.Where(s => s.Id == shiftRoutine.ShiftId) .Where(s => s.Id == shiftRoutine.ShiftId)
.Select(ShiftMapper.ProjectToSDto) .Select(ShiftMapper.ProjectToSDto)
@ -48,7 +46,7 @@ public class GetRoutineShiftsQueryHandler : IRequestHandler<GetRoutineShiftsQuer
{ {
var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate); var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate);
var existedShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() var existedShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date, cancellationToken); .FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date, cancellationToken);
shift.IsCompleted = existedShiftPlan?.IsCompleted ?? false; shift.IsCompleted = existedShiftPlan?.IsCompleted ?? false;

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Routine; namespace Brizco.Repository.Handlers.Routines;
public class GetRoutinesQueryHandler : IRequestHandler<GetRoutinesQuery, List<RoutineSDto>> public class GetRoutinesQueryHandler : IRequestHandler<GetRoutinesQuery, List<RoutineSDto>>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Routine; namespace Brizco.Repository.Handlers.Routines;
public class UpdateRoutineCommandHandler : IRequestHandler<UpdateRoutineCommand, bool> public class UpdateRoutineCommandHandler : IRequestHandler<UpdateRoutineCommand, bool>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Section; namespace Brizco.Repository.Handlers.Sections;
public class CreateSectionCommandHandler : IRequestHandler<CreateSectionCommand, SectionSDto> public class CreateSectionCommandHandler : IRequestHandler<CreateSectionCommand, SectionSDto>
{ {
@ -21,12 +21,12 @@ public class CreateSectionCommandHandler : IRequestHandler<CreateSectionCommand,
try try
{ {
await _repositoryWrapper.BeginTransaction(cancellationToken); await _repositoryWrapper.BeginTransaction(cancellationToken);
var entity = Domain.Entities.Complexes.Section var entity = Section
.Create(request.Title, .Create(request.Title,
request.Description, request.Description,
complexId); complexId);
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>().Add(entity); _repositoryWrapper.SetRepository<Section>().Add(entity);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);
await _repositoryWrapper.CommitAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken);
return entity.AdaptToSDto(); return entity.AdaptToSDto();

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Section; namespace Brizco.Repository.Handlers.Sections;
public class DeleteSectionCommandHandler : IRequestHandler<DeleteSectionCommand, bool> public class DeleteSectionCommandHandler : IRequestHandler<DeleteSectionCommand, bool>
{ {
@ -10,20 +10,20 @@ public class DeleteSectionCommandHandler : IRequestHandler<DeleteSectionCommand,
} }
public async Task<bool> Handle(DeleteSectionCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(DeleteSectionCommand request, CancellationToken cancellationToken)
{ {
var section = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>() var section = await _repositoryWrapper.SetRepository<Section>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); .FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (section == null) if (section == null)
throw new AppException("Section not found", ApiResultStatusCode.NotFound); throw new AppException("Section not found", ApiResultStatusCode.NotFound);
var positions = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>() var positions = await _repositoryWrapper.SetRepository<Position>()
.TableNoTracking .TableNoTracking
.Where(p => p.SectionId == section.Id) .Where(p => p.SectionId == section.Id)
.CountAsync(cancellationToken); .CountAsync(cancellationToken);
if (positions > 0) if (positions > 0)
throw new AppException("این سکشن پوزیشن فعال دارد ، نخست پوزیشن های سکشن را حذف کرده یا منتقل کنید"); throw new AppException("این سکشن پوزیشن فعال دارد ، نخست پوزیشن های سکشن را حذف کرده یا منتقل کنید");
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>() _repositoryWrapper.SetRepository<Section>()
.Delete(section); .Delete(section);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.Sections;
namespace Brizco.Repository.Handlers.Section;
public class GetSectionQueryHandler : IRequestHandler<GetSectionQuery, SectionLDto> public class GetSectionQueryHandler : IRequestHandler<GetSectionQuery, SectionLDto>
{ {
@ -12,7 +10,7 @@ public class GetSectionQueryHandler : IRequestHandler<GetSectionQuery, SectionLD
} }
public async Task<SectionLDto> Handle(GetSectionQuery request, CancellationToken cancellationToken) public async Task<SectionLDto> Handle(GetSectionQuery request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>() var shift = await _repositoryWrapper.SetRepository<Section>()
.TableNoTracking .TableNoTracking
.Where(s => s.Id == request.Id) .Where(s => s.Id == request.Id)
.Select(SectionMapper.ProjectToLDto) .Select(SectionMapper.ProjectToLDto)

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Section; namespace Brizco.Repository.Handlers.Sections;
public class GetSectionsQueryHandler : IRequestHandler<GetSectionsQuery, List<SectionSDto>> public class GetSectionsQueryHandler : IRequestHandler<GetSectionsQuery, List<SectionSDto>>
{ {
@ -17,7 +17,7 @@ public class GetSectionsQueryHandler : IRequestHandler<GetSectionsQuery, List<Se
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
var shifts = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>().TableNoTracking var shifts = await _repositoryWrapper.SetRepository<Section>().TableNoTracking
.Where(s=>s.ComplexId==complexId) .Where(s=>s.ComplexId==complexId)
.OrderByDescending(s => s.CreatedAt) .OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15) .Skip(request.Page * 15).Take(15)

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Section; namespace Brizco.Repository.Handlers.Sections;
public class UpdateSectionCommandHandler : IRequestHandler<UpdateSectionCommand, bool> public class UpdateSectionCommandHandler : IRequestHandler<UpdateSectionCommand, bool>
{ {
@ -13,7 +13,7 @@ public class UpdateSectionCommandHandler : IRequestHandler<UpdateSectionCommand,
public async Task<bool> Handle(UpdateSectionCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(UpdateSectionCommand request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>() var shift = await _repositoryWrapper.SetRepository<Section>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); .TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null) if (shift == null)
throw new AppException("Section not found", ApiResultStatusCode.NotFound); throw new AppException("Section not found", ApiResultStatusCode.NotFound);
@ -23,13 +23,13 @@ public class UpdateSectionCommandHandler : IRequestHandler<UpdateSectionCommand,
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
var newSection = Domain.Entities.Complexes.Section.Create(request.Title, var newSection = Section.Create(request.Title,
request.Description, request.Description,
complexId); complexId);
newSection.Id = request.Id; newSection.Id = request.Id;
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>() _repositoryWrapper.SetRepository<Section>()
.Update(newSection); .Update(newSection);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.ShiftPlans;
namespace Brizco.Repository.Handlers.ShiftPlan;
public class CreateShiftPlanCommandHandler : IRequestHandler<CreateShiftPlanCommand, ShiftPlanLDto> public class CreateShiftPlanCommandHandler : IRequestHandler<CreateShiftPlanCommand, ShiftPlanLDto>
{ {
@ -14,14 +12,13 @@ public class CreateShiftPlanCommandHandler : IRequestHandler<CreateShiftPlanComm
} }
public async Task<ShiftPlanLDto> Handle(CreateShiftPlanCommand request, CancellationToken cancellationToken) public async Task<ShiftPlanLDto> Handle(CreateShiftPlanCommand request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() var shift = await _repositoryWrapper.SetRepository<Shift>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.ShiftId, cancellationToken); .FirstOrDefaultAsync(s => s.Id == request.ShiftId, cancellationToken);
if (shift == null) if (shift == null)
throw new AppException("Shift not found", ApiResultStatusCode.NotFound); throw new AppException("Shift not found", ApiResultStatusCode.NotFound);
var planFor = DateTimeExtensions.UnixTimeStampToDateTime(request.PlanDate); var planFor = DateTimeExtensions.UnixTimeStampToDateTime(request.PlanDate);
var existedShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() var existedShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.ShiftId == request.ShiftId && s.PlanFor.Date == planFor.Date, cancellationToken); .FirstOrDefaultAsync(s => s.ShiftId == request.ShiftId && s.PlanFor.Date == planFor.Date, cancellationToken);
@ -42,7 +39,7 @@ public class CreateShiftPlanCommandHandler : IRequestHandler<CreateShiftPlanComm
shiftPlan.AddUser(userAndPositionId.Key, userAndPositionId.Value); shiftPlan.AddUser(userAndPositionId.Key, userAndPositionId.Value);
} }
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>().Add(shiftPlan); _repositoryWrapper.SetRepository<ShiftPlan>().Add(shiftPlan);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);
await _repositoryWrapper.CommitAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken);
return shiftPlan.AdaptToLDto(); return shiftPlan.AdaptToLDto();

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.ShiftPlan; namespace Brizco.Repository.Handlers.ShiftPlans;
public class DeleteShiftPlanCommandHandler : IRequestHandler<DeleteShiftPlanCommand, bool> public class DeleteShiftPlanCommandHandler : IRequestHandler<DeleteShiftPlanCommand, bool>
{ {
@ -11,13 +11,13 @@ public class DeleteShiftPlanCommandHandler : IRequestHandler<DeleteShiftPlanComm
public async Task<bool> Handle(DeleteShiftPlanCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(DeleteShiftPlanCommand request, CancellationToken cancellationToken)
{ {
var shiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id,cancellationToken); .TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id,cancellationToken);
if (shiftPlan == null) if (shiftPlan == null)
throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound); throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound);
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() _repositoryWrapper.SetRepository<ShiftPlan>()
.Delete(shiftPlan); .Delete(shiftPlan);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.ShiftPlans;
namespace Brizco.Repository.Handlers.ShiftPlan;
public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftPlanQuery, ShiftPlanLDto> public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftPlanQuery, ShiftPlanLDto>
{ {
@ -12,7 +10,7 @@ public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftPlanQuery, Shift
} }
public async Task<ShiftPlanLDto> Handle(GetShiftPlanQuery request, CancellationToken cancellationToken) public async Task<ShiftPlanLDto> Handle(GetShiftPlanQuery request, CancellationToken cancellationToken)
{ {
var shiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking .TableNoTracking
.Where(s => s.Id == request.Id) .Where(s => s.Id == request.Id)
.Select(ShiftPlanMapper.ProjectToLDto) .Select(ShiftPlanMapper.ProjectToLDto)

View File

@ -1,7 +1,6 @@
using Brizco.Domain.Entities.Shifts; using MD.PersianDateTime.Standard;
using MD.PersianDateTime.Standard;
namespace Brizco.Repository.Handlers.ShiftPlan; namespace Brizco.Repository.Handlers.ShiftPlans;
public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, List<ShiftPlanSDto>> public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, List<ShiftPlanSDto>>
{ {
@ -20,7 +19,7 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, Lis
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
IQueryable<Domain.Entities.Shifts.ShiftPlan> baseQuery = _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() IQueryable<ShiftPlan> baseQuery = _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking .TableNoTracking
.OrderByDescending(s => s.CreatedAt) .OrderByDescending(s => s.CreatedAt)
.Where(s => s.ComplexId == complexId); .Where(s => s.ComplexId == complexId);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Entities.Shifts; namespace Brizco.Repository.Handlers.ShiftPlans;
namespace Brizco.Repository.Handlers.ShiftPlan;
public class UpdateShiftPlanCommandHandler : IRequestHandler<UpdateShiftPlanCommand, bool> public class UpdateShiftPlanCommandHandler : IRequestHandler<UpdateShiftPlanCommand, bool>
{ {
@ -13,13 +11,13 @@ public class UpdateShiftPlanCommandHandler : IRequestHandler<UpdateShiftPlanComm
public async Task<bool> Handle(UpdateShiftPlanCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(UpdateShiftPlanCommand request, CancellationToken cancellationToken)
{ {
var shiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id,cancellationToken); .TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id,cancellationToken);
if (shiftPlan == null) if (shiftPlan == null)
throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound); throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound);
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() var shift = await _repositoryWrapper.SetRepository<Shift>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.ShiftId, cancellationToken); .TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.ShiftId, cancellationToken);
if (shift == null) if (shift == null)
@ -50,7 +48,7 @@ public class UpdateShiftPlanCommandHandler : IRequestHandler<UpdateShiftPlanComm
foreach (var userId in request.UserAndPositionIds) foreach (var userId in request.UserAndPositionIds)
newPlan.AddUser(userId.Key,userId.Value); newPlan.AddUser(userId.Key,userId.Value);
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() _repositoryWrapper.SetRepository<ShiftPlan>()
.Update(newPlan); .Update(newPlan);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Shift; namespace Brizco.Repository.Handlers.Shifts;
public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, ShiftSDto> public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, ShiftSDto>
{ {
@ -21,7 +21,7 @@ public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Shi
try try
{ {
await _repositoryWrapper.BeginTransaction(cancellationToken); await _repositoryWrapper.BeginTransaction(cancellationToken);
var shift = Domain.Entities.Shifts.Shift var shift = Shift
.Create(request.Title, .Create(request.Title,
request.Description, request.Description,
request.StartAt, request.StartAt,
@ -34,7 +34,7 @@ public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Shi
throw new AppException("روتین شیفت را انتخاب کنید"); throw new AppException("روتین شیفت را انتخاب کنید");
request.Routines.ForEach(r=>shift.AddRoutine(r)); request.Routines.ForEach(r=>shift.AddRoutine(r));
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>().Add(shift); _repositoryWrapper.SetRepository<Shift>().Add(shift);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);
await _repositoryWrapper.CommitAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken);
return shift.AdaptToSDto(); return shift.AdaptToSDto();

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Shift; namespace Brizco.Repository.Handlers.Shifts;
public class DeletePositionCommandHandler : IRequestHandler<DeleteShiftCommand, bool> public class DeletePositionCommandHandler : IRequestHandler<DeleteShiftCommand, bool>
{ {
@ -10,12 +10,12 @@ public class DeletePositionCommandHandler : IRequestHandler<DeleteShiftCommand,
} }
public async Task<bool> Handle(DeleteShiftCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(DeleteShiftCommand request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() var shift = await _repositoryWrapper.SetRepository<Shift>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); .FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null) if (shift == null)
throw new AppException("Routine not found", ApiResultStatusCode.NotFound); throw new AppException("Routine not found", ApiResultStatusCode.NotFound);
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() _repositoryWrapper.SetRepository<Shift>()
.Delete(shift); .Delete(shift);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.Shifts;
namespace Brizco.Repository.Handlers.Shift;
public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftQuery, ShiftLDto> public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftQuery, ShiftLDto>
{ {
@ -12,7 +10,7 @@ public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftQuery, ShiftLDto
} }
public async Task<ShiftLDto> Handle(GetShiftQuery request, CancellationToken cancellationToken) public async Task<ShiftLDto> Handle(GetShiftQuery request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() var shift = await _repositoryWrapper.SetRepository<Shift>()
.TableNoTracking .TableNoTracking
.Where(s => s.Id == request.Id) .Where(s => s.Id == request.Id)
.Select(ShiftMapper.ProjectToLDto) .Select(ShiftMapper.ProjectToLDto)

View File

@ -1,8 +1,4 @@
using Brizco.Domain.Entities.Shifts; namespace Brizco.Repository.Handlers.Shifts;
using Brizco.Domain.Entities.Users;
using Guid = System.Guid;
namespace Brizco.Repository.Handlers.Shift;
public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<ShiftSDto>> public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<ShiftSDto>>
{ {
@ -29,14 +25,15 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<Sh
var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate); var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate);
var originalShifts = from shiftDay in _repositoryWrapper.SetRepository<ShiftDay>().Entities var originalShifts = from shiftDay in _repositoryWrapper.SetRepository<ShiftDay>().Entities
join shift in _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>().Entities on shiftDay.ShiftId equals shift.Id join shift in _repositoryWrapper.SetRepository<Shift>().Entities on shiftDay.ShiftId equals shift.Id
where shiftDay.DayOfWeek == selectedDate.DayOfWeek && shift.ComplexId == complexId where shiftDay.DayOfWeek == selectedDate.DayOfWeek && shift.ComplexId == complexId
orderby shift.StartAt descending
select shift; select shift;
shifts = await originalShifts.AsNoTracking().Select(ShiftMapper.ProjectToSDto).ToListAsync(cancellationToken); shifts = await originalShifts.AsNoTracking().Select(ShiftMapper.ProjectToSDto).ToListAsync(cancellationToken);
foreach (var shift in shifts) foreach (var shift in shifts)
{ {
var existedShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() var existedShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date, cancellationToken); .FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date, cancellationToken);
if(existedShiftPlan == null) if(existedShiftPlan == null)
@ -66,7 +63,7 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<Sh
{ {
if (!Guid.TryParse(_currentUserService.UserId, out Guid userId)) if (!Guid.TryParse(_currentUserService.UserId, out Guid userId))
throw new AppException("User id is wrong"); throw new AppException("User id is wrong");
var existedSupervisorShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>() var existedSupervisorShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date && s.SupervisorId == userId, cancellationToken); .FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date && s.SupervisorId == userId, cancellationToken);
shift.IsCompleted = existedSupervisorShiftPlan?.IsCompleted ?? false; shift.IsCompleted = existedSupervisorShiftPlan?.IsCompleted ?? false;
@ -87,9 +84,9 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<Sh
else else
{ {
shifts = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>().TableNoTracking shifts = await _repositoryWrapper.SetRepository<Shift>().TableNoTracking
.Where(s => s.ComplexId == complexId) .Where(s => s.ComplexId == complexId)
.OrderByDescending(s => s.CreatedAt) .OrderByDescending(s => s.StartAt)
.Skip(request.Page * 15).Take(15) .Skip(request.Page * 15).Take(15)
.Select(ShiftMapper.ProjectToSDto) .Select(ShiftMapper.ProjectToSDto)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Entities.Shifts; namespace Brizco.Repository.Handlers.Shifts;
namespace Brizco.Repository.Handlers.Shift;
public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand, bool> public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand, bool>
{ {
@ -15,7 +13,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand,
public async Task<bool> Handle(UpdateShiftCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(UpdateShiftCommand request, CancellationToken cancellationToken)
{ {
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() var shift = await _repositoryWrapper.SetRepository<Shift>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken); .TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null) if (shift == null)
throw new AppException("Shift not found", ApiResultStatusCode.NotFound); throw new AppException("Shift not found", ApiResultStatusCode.NotFound);
@ -25,7 +23,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand,
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
var newShift = Domain.Entities.Shifts.Shift.Create(request.Title, var newShift = Shift.Create(request.Title,
request.Description, request.Description,
request.StartAt, request.StartAt,
request.EndAt, request.EndAt,
@ -69,7 +67,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand,
newShift.AddRoutine(routine); newShift.AddRoutine(routine);
} }
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>() _repositoryWrapper.SetRepository<Shift>()
.Update(newShift); .Update(newShift);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.SaveChangesAsync(cancellationToken);

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.Tasks;
namespace Brizco.Repository.Handlers.Task;
public class CreateActivityCommandHandler : IRequestHandler<CreateTaskCommand, TaskLDto> public class CreateActivityCommandHandler : IRequestHandler<CreateTaskCommand, TaskLDto>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Task; namespace Brizco.Repository.Handlers.Tasks;
public class DeleteActivityCommandHandler : IRequestHandler<DeleteTaskCommand, bool> public class DeleteActivityCommandHandler : IRequestHandler<DeleteTaskCommand, bool>
{ {

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Dtos.LargeDtos; namespace Brizco.Repository.Handlers.Tasks;
namespace Brizco.Repository.Handlers.Task;
public class GetActivityQueryHandler : IRequestHandler<GetTaskQuery, TaskLDto> public class GetActivityQueryHandler : IRequestHandler<GetTaskQuery, TaskLDto>
{ {

View File

@ -1,4 +1,4 @@
namespace Brizco.Repository.Handlers.Task; namespace Brizco.Repository.Handlers.Tasks;
public class GetActivitiesQueryHandler : IRequestHandler<GetTasksQuery, List<TaskSDto>> public class GetActivitiesQueryHandler : IRequestHandler<GetTasksQuery, List<TaskSDto>>
{ {

View File

@ -1,6 +1,6 @@
using Brizco.Domain.Entities.Tasks; using Brizco.Domain.Entities.Tasks;
namespace Brizco.Repository.Handlers.Task; namespace Brizco.Repository.Handlers.Tasks;
public class UpdateActivityCommandHandler : IRequestHandler<UpdateTaskCommand, bool> public class UpdateActivityCommandHandler : IRequestHandler<UpdateTaskCommand, bool>
{ {

View File

@ -1,9 +1,4 @@
using Brizco.Domain.Entities.Users; namespace Brizco.Repository.Models;
using Brizco.Repository.Extensions;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace Brizco.Repository.Models;
public class ApplicationContext : IdentityDbContext<ApplicationUser,ApplicationRole,Guid> public class ApplicationContext : IdentityDbContext<ApplicationUser,ApplicationRole,Guid>
{ {

View File

@ -1,6 +1,4 @@
using Brizco.Common.Extensions; namespace Brizco.Repository.Repositories.Base
namespace Brizco.Repository.Repositories.Base
{ {
public class BaseRepository<T> : Repository<T>, IBaseRepository<T> where T : class, IApiEntity public class BaseRepository<T> : Repository<T>, IBaseRepository<T> where T : class, IApiEntity
{ {

View File

@ -1,7 +1,4 @@
using System.Text; namespace Brizco.Repository.Repositories.Base
using Microsoft.EntityFrameworkCore;
namespace Brizco.Repository.Repositories.Base
{ {
public class Repository<T> : IRepository<T> where T : class, IApiEntity public class Repository<T> : IRepository<T> where T : class, IApiEntity
{ {

View File

@ -1,6 +1,4 @@
 
using Brizco.Repository.Abstracts;
namespace Brizco.Repository.Repositories.Base namespace Brizco.Repository.Repositories.Base
{ {
public class WriteRepository<T> : Repository<T>, IDisposable, IWriteRepository<T> where T : class, IApiEntity public class WriteRepository<T> : Repository<T>, IDisposable, IWriteRepository<T> where T : class, IApiEntity

View File

@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage;
using Task = System.Threading.Tasks.Task; using Task = System.Threading.Tasks.Task;
namespace Brizco.Repository.Repositories.UnitOfWork; namespace Brizco.Repository.Repositories.UnitOfWork;

View File

@ -1,5 +1,4 @@
using Brizco.Common.Models; using Task = System.Threading.Tasks.Task;
using Task = System.Threading.Tasks.Task;
namespace Brizco.Repository.Services.Contracts; namespace Brizco.Repository.Services.Contracts;

View File

@ -1,5 +1,4 @@
using Brizco.Domain.Entities.Users; using Task = System.Threading.Tasks.Task;
using Task = System.Threading.Tasks.Task;
namespace Brizco.Repository.Services; namespace Brizco.Repository.Services;