Compare commits
2 Commits
e918e8d3f7
...
81762ecb64
Author | SHA1 | Date |
---|---|---|
|
81762ecb64 | |
|
1fbf37dd82 |
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"PostgresServer": "Host=185.220.227.123;port=5432;Username=postgres;Password=ub0J7sFFThkSBmkc0TzSKsCfheRnQpyu;Database=BrizcoDB",
|
||||
"Postgres": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS",
|
||||
"MartenDB": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoMartenDB;"
|
||||
"Postgres": "Host=pg-0;Username=postgres;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Application Name=BrizCo",
|
||||
"MartenDB": "Host=pg-0;Username=postgres;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoMartenDB;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
|
|
@ -73,7 +73,8 @@
|
|||
<Using Include="Brizco.Domain.CommandQueries.Queries" />
|
||||
<Using Include="Brizco.Domain.Dtos.RequestDtos" />
|
||||
<Using Include="Brizco.Domain.Entities" />
|
||||
<Using Include="Brizco.Domain.Entities.User" />
|
||||
<Using Include="Brizco.Domain.Entities.Users" />
|
||||
<Using Include="Brizco.Domain.Enums" />
|
||||
<Using Include="Brizco.Domain.Models.Settings" />
|
||||
<Using Include="Brizco.Infrastructure" />
|
||||
<Using Include="Brizco.Repository" />
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Brizco.Common.Models.Claims;
|
||||
using Brizco.Domain.Enums;
|
||||
using Brizco.Domain.Enums;
|
||||
|
||||
namespace Brizco.Api.Controllers;
|
||||
|
||||
|
@ -7,7 +6,6 @@ public class ActivityController : ICarterModule
|
|||
{
|
||||
public void AddRoutes(IEndpointRouteBuilder app)
|
||||
{
|
||||
|
||||
var group = app.NewVersionedApi("Activity")
|
||||
.MapGroup($"api/activity")
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());
|
||||
|
|
|
@ -13,8 +13,17 @@ public class NotificationController : ICarterModule
|
|||
.RequireAuthorization(builder=>builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapPost("{id}/read",ReadNotificationAsync)
|
||||
.WithDisplayName("Read Notification")
|
||||
.WithDescription("Read notification , by JWT user id")
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
}
|
||||
|
||||
private async Task<IResult> ReadNotificationAsync([FromRoute] Guid id, [FromServices] IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new ReadNotificationCommand(id), cancellationToken));
|
||||
|
||||
private async Task<IResult> GetUserNotificationsAsync([FromQuery] int page, [FromQuery] int count,
|
||||
[FromServices] IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new GetNotificationsQuery(page, count), cancellationToken));
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
7bec0081-0f19-4cf7-84a9-7deed79e4f61
|
|
@ -8,35 +8,35 @@ public static class ScalarUiConfiguration
|
|||
{
|
||||
|
||||
var scalarScript = $$"""
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Scalar API Reference</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1" />
|
||||
</head>
|
||||
<body>
|
||||
<!-- 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 don’t need it. -->
|
||||
<script
|
||||
id="api-reference"
|
||||
data-url="/swagger/{{documentName}}/swagger.json"></script>
|
||||
|
||||
<!-- Optional: You can set a full configuration object like this: -->
|
||||
<script>
|
||||
var configuration = {
|
||||
theme: 'bluePlanet',
|
||||
}
|
||||
|
||||
document.getElementById('api-reference').dataset.configuration =
|
||||
JSON.stringify(configuration)
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Scalar API Reference</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1" />
|
||||
</head>
|
||||
<body>
|
||||
<!-- 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 don’t need it. -->
|
||||
<script
|
||||
id="api-reference"
|
||||
data-url="/swagger/{{documentName}}/swagger.json"></script>
|
||||
|
||||
<!-- Optional: You can set a full configuration object like this: -->
|
||||
<script>
|
||||
var configuration = {
|
||||
theme: 'bluePlanet',
|
||||
}
|
||||
|
||||
document.getElementById('api-reference').dataset.configuration =
|
||||
JSON.stringify(configuration)
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
|
||||
return Results.Content(scalarScript, "text/html");
|
||||
}).ExcludeFromDescription();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Asp.Versioning;
|
||||
using Brizco.Common.Extensions;
|
||||
using Brizco.Common.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Pluralize.NET;
|
||||
|
@ -10,7 +9,7 @@ namespace Brizco.Api.WebFramework.Swagger;
|
|||
|
||||
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 =>
|
||||
{
|
||||
|
@ -20,9 +19,9 @@ public static class SwaggerConfiguration
|
|||
new OpenApiInfo
|
||||
{
|
||||
Version = "v1",
|
||||
Title = "BrizCo Api Document",
|
||||
Description = "BrizCo api document OpenApi based",
|
||||
License = new OpenApiLicense { Name = "Briz Corp" },
|
||||
Title = "GolBarg Api Document",
|
||||
Description = "GolBarg api for clients that wana use , based OpenApi",
|
||||
License = new OpenApiLicense { Name = "Vira Safir Fanavar " },
|
||||
Contact = new OpenApiContact
|
||||
{
|
||||
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 =>
|
||||
{
|
||||
|
@ -195,13 +194,17 @@ public class ApplySummariesOperationFilter : IOperationFilter
|
|||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
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 actionName = controllerActionDescriptor.ActionName;
|
||||
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();
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\Api\" />
|
||||
<Folder Include="QuartzServices\Commands\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -35,6 +36,7 @@
|
|||
<Using Include="Brizco.Core.CoreServices.ReportServices.Commands" />
|
||||
<Using Include="Brizco.Core.EntityServices.Abstracts" />
|
||||
<Using Include="Brizco.Core.MartenServices.Abstracts" />
|
||||
<Using Include="Brizco.Core.QuartzServices.Commands" />
|
||||
<Using Include="Brizco.Domain" />
|
||||
<Using Include="Brizco.Domain.CommandQueries.Commands" />
|
||||
<Using Include="Brizco.Domain.CommandQueries.Queries" />
|
||||
|
@ -43,8 +45,11 @@
|
|||
<Using Include="Brizco.Domain.Dtos.RequestDtos" />
|
||||
<Using Include="Brizco.Domain.Dtos.ResponseDto" />
|
||||
<Using Include="Brizco.Domain.Dtos.SmallDtos" />
|
||||
<Using Include="Brizco.Domain.Entities.Complex" />
|
||||
<Using Include="Brizco.Domain.Entities.User" />
|
||||
<Using Include="Brizco.Domain.Entities.Complexes" />
|
||||
<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.Mappers" />
|
||||
<Using Include="Brizco.Domain.MartenEntities.Brews" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Threading;
|
||||
using Brizco.Domain.Entities.Complexes;
|
||||
using Brizco.Domain.Entities.Shifts;
|
||||
using Brizco.Domain.Entities.ShiftPlans;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
|
||||
|
@ -168,8 +168,6 @@ public class AccountService : IAccountService
|
|||
throw new AppException("نام و نام خانوادگی را وارد کنید");
|
||||
if (requestDto.ComplexName.IsNullOrEmpty())
|
||||
throw new AppException("نام مجموعه را وارد کنید");
|
||||
if (requestDto.ComplexAddress.IsNullOrEmpty())
|
||||
throw new AppException("آدرس مجموعه را وارد کنید");
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
using Task = Brizco.Domain.Entities.Tasks.Task;
|
||||
using System.Linq;
|
||||
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;
|
||||
using Brizco.Domain.Entities.Tasks;
|
||||
using Task = Brizco.Domain.Entities.Tasks.Task;
|
||||
|
||||
namespace Brizco.Core.CoreServices;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
namespace Brizco.Core.EntityServices;
|
||||
|
@ -95,6 +94,7 @@ public class ActivityService : IActivityService
|
|||
|
||||
var tasks = new List<Task>();
|
||||
tasks.AddRange(weeklyTasks);
|
||||
|
||||
tasks.AddRange(dailyTasks);
|
||||
tasks.AddRange(customTasks);
|
||||
|
||||
|
|
|
@ -1,50 +1,39 @@
|
|||
using Brizco.Domain.Entities.Shifts;
|
||||
namespace Brizco.Core.EntityServices;
|
||||
|
||||
namespace Brizco.Core.EntityServices;
|
||||
|
||||
public class ShiftPlanService : IShiftPlanService
|
||||
public class ShiftPlanService(IMediator mediator, IActivityService activityService, IRepositoryWrapper repositoryWrapper) : 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
var shiftPlan = await _sender.Send(createShiftPlanCommand, cancellationToken);
|
||||
await _activityService.CreateActivitiesByShiftPlan(shiftPlan.Id, cancellationToken);
|
||||
var shiftPlan = await mediator.Send(createShiftPlanCommand, cancellationToken);
|
||||
await activityService.CreateActivitiesByShiftPlan(shiftPlan.Id, cancellationToken);
|
||||
await mediator.Send(new CreateShiftPlanNotificationsCommand(shiftPlan.Id,true), cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(UpdateShiftPlanCommand updateShiftPlanCommand, CancellationToken cancellationToken)
|
||||
{
|
||||
await _sender.Send(updateShiftPlanCommand, cancellationToken);
|
||||
await _activityService.UpdateActivitiesByShiftPlan(updateShiftPlanCommand.Id, cancellationToken);
|
||||
await mediator.Send(updateShiftPlanCommand, cancellationToken);
|
||||
await activityService.UpdateActivitiesByShiftPlan(updateShiftPlanCommand.Id, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
if (shiftPlan == null)
|
||||
throw new AppException("Shift plan not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
shiftPlan.CompletePlan(requestDtos.CompleteDescription,requestDtos.CompletePercent);
|
||||
_repositoryWrapper.SetRepository<ShiftPlan>().Update(shiftPlan);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
await _activityService.CompleteActivitiesAsync(requestDtos.CompleteActivities, cancellationToken);
|
||||
repositoryWrapper.SetRepository<ShiftPlan>().Update(shiftPlan);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
await activityService.CompleteActivitiesAsync(requestDtos.CompleteActivities, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -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>;
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -18,18 +18,7 @@ public class JobScheduler
|
|||
{
|
||||
_scheduler.Start();
|
||||
|
||||
//IJobDetail job = JobBuilder.Create<NotificationScheduledJob>()
|
||||
// .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()} ===========");
|
||||
_logger.LogInformation($"======== Scheduler Start ===========");
|
||||
|
||||
}
|
||||
}
|
|
@ -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}");
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,12 +55,10 @@
|
|||
<Using Include="Brizco.Domain.Dtos.LargeDtos" />
|
||||
<Using Include="Brizco.Domain.Dtos.ResponseDto" />
|
||||
<Using Include="Brizco.Domain.Dtos.SmallDtos" />
|
||||
<Using Include="Brizco.Domain.Entities.Complex" />
|
||||
<Using Include="Brizco.Domain.Entities.Complexes" />
|
||||
<Using Include="Brizco.Domain.Entities.Routine" />
|
||||
<Using Include="Brizco.Domain.Entities.Shift" />
|
||||
<Using Include="Brizco.Domain.Entities.Routines" />
|
||||
<Using Include="Brizco.Domain.Entities.ShiftPlans" />
|
||||
<Using Include="Brizco.Domain.Entities.Shifts" />
|
||||
<Using Include="Brizco.Domain.Entities.Task" />
|
||||
<Using Include="Brizco.Domain.Entities.Users" />
|
||||
<Using Include="Brizco.Domain.Enums" />
|
||||
<Using Include="Mapster" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
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>;
|
|
@ -13,6 +13,7 @@ public class ShiftPlanSDto : BaseDto<ShiftPlanSDto,ShiftPlan>
|
|||
public int CompletePercent { get; set; }
|
||||
public string SupervisorFullName { get; set; } = string.Empty;
|
||||
public string CompleteDescription { get; set; } = string.Empty;
|
||||
public Guid ComplexId { get; set; }
|
||||
public Guid ShiftId { get; set; }
|
||||
public string ShiftTitle { get; set; } = string.Empty;
|
||||
public TimeSpan StartAt { get; set; }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Brizco.Domain.Entities.Shifts;
|
||||
using Brizco.Domain.Entities.ShiftPlans;
|
||||
|
||||
namespace Brizco.Domain.Dtos.SmallDtos;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
using Brizco.Domain.Entities.Routines;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
|
||||
namespace Brizco.Domain.Entities.Shifts;
|
||||
|
||||
namespace Brizco.Domain.Entities.ShiftPlans;
|
||||
|
||||
[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)]
|
||||
|
@ -25,6 +23,7 @@ public partial class ShiftPlan : ApiEntity
|
|||
public DateTime PlanFor { get; internal set; }
|
||||
|
||||
public bool IsCompleted { get; internal set; }
|
||||
public bool IsScheduled { get; internal set; }
|
||||
public int CompletePercent { get; internal set; }
|
||||
public string CompleteDescription { get; internal set; } = string.Empty;
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Entities.Users;
|
||||
|
||||
namespace Brizco.Domain.Entities.Shifts;
|
||||
namespace Brizco.Domain.Entities.ShiftPlans;
|
||||
|
||||
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
|
||||
[GenerateMapper]
|
||||
|
@ -8,10 +6,10 @@ public class ShiftPlanUser : ApiEntity
|
|||
{
|
||||
public ShiftPlanUser()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ShiftPlanUser(Guid shiftPlanId,Guid positionId, Guid userId)
|
||||
public ShiftPlanUser(Guid shiftPlanId, Guid positionId, Guid userId)
|
||||
{
|
||||
ShiftPlanId = shiftPlanId;
|
||||
PositionId = positionId;
|
|
@ -26,20 +26,3 @@ public partial class Shift
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
namespace Brizco.Domain.Enums;
|
||||
|
||||
public enum ShiftPlanNotifyType
|
||||
{
|
||||
None = 0,
|
||||
BeforeEndShift30Min = 1,
|
||||
EndOfShift = 2,
|
||||
AfterStartShift2Hour = 3
|
||||
}
|
|
@ -2,7 +2,7 @@ using System;
|
|||
using System.Linq.Expressions;
|
||||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
using Brizco.Domain.Dtos.SmallDtos;
|
||||
using Brizco.Domain.Entities.Shifts;
|
||||
using Brizco.Domain.Entities.ShiftPlans;
|
||||
using Brizco.Domain.Entities.Tasks;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using Mapster.Models;
|
||||
|
|
|
@ -6,6 +6,7 @@ using Brizco.Domain.Dtos.LargeDtos;
|
|||
using Brizco.Domain.Dtos.SmallDtos;
|
||||
using Brizco.Domain.Entities.Complexes;
|
||||
using Brizco.Domain.Entities.Routines;
|
||||
using Brizco.Domain.Entities.ShiftPlans;
|
||||
using Brizco.Domain.Entities.Shifts;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using Mapster.Models;
|
||||
|
|
|
@ -2,7 +2,7 @@ using System;
|
|||
using System.Linq.Expressions;
|
||||
using Brizco.Domain.Dtos.SmallDtos;
|
||||
using Brizco.Domain.Entities.Complexes;
|
||||
using Brizco.Domain.Entities.Shifts;
|
||||
using Brizco.Domain.Entities.ShiftPlans;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using Mapster.Models;
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
using Brizco.Domain.Entities.Complexes;
|
||||
using Brizco.Domain.Entities.Shifts;
|
||||
using Brizco.Domain.Entities.Tasks;
|
||||
using MD.PersianDateTime.Standard;
|
||||
using Brizco.Domain.Entities.Tasks;
|
||||
using Task = Brizco.Domain.Entities.Tasks.Task;
|
||||
|
||||
namespace Brizco.Domain;
|
||||
|
|
|
@ -46,8 +46,13 @@
|
|||
<Using Include="Brizco.Domain.Dtos.LargeDtos" />
|
||||
<Using Include="Brizco.Domain.Dtos.ResponseDto" />
|
||||
<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.Domain.MartenEntities.Notifications" />
|
||||
<Using Include="Brizco.Repository.Abstracts" />
|
||||
<Using Include="Brizco.Repository.Extensions" />
|
||||
<Using Include="Brizco.Repository.Repositories.Marten" />
|
||||
<Using Include="MediatR" />
|
||||
<Using Include="Brizco.Common.Extensions" />
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Activity;
|
||||
namespace Brizco.Repository.Handlers.Activities;
|
||||
|
||||
public class CreateActivityCommandHandler : IRequestHandler<CreateActivityCommand, ActivityLDto>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Activity;
|
||||
namespace Brizco.Repository.Handlers.Activities;
|
||||
|
||||
public class DeleteActivityCommandHandler : IRequestHandler<DeleteActivityCommand, bool>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Activity;
|
||||
namespace Brizco.Repository.Handlers.Activities;
|
||||
|
||||
public class GetActivitiesQueryHandler : IRequestHandler<GetActivitiesQuery, List<ActivitySDto>>
|
||||
{
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Activity;
|
||||
namespace Brizco.Repository.Handlers.Activities;
|
||||
|
||||
public class GetActivityQueryHandler : IRequestHandler<GetActivityQuery, ActivityLDto>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Activity;
|
||||
namespace Brizco.Repository.Handlers.Activities;
|
||||
|
||||
public class GetShiftPlanActivitiesQueryHandler : IRequestHandler<GetShiftPlanActivitiesQuery, List<ActivitySDto>>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Activity;
|
||||
namespace Brizco.Repository.Handlers.Activities;
|
||||
|
||||
public class UpdateActivityCommandHandler : IRequestHandler<UpdateActivityCommand, bool>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
public class CreateComplexCommandHandler : IRequestHandler<CreateComplexCommand, ComplexSDto>
|
||||
{
|
||||
|
@ -16,8 +16,8 @@ public class CreateComplexCommandHandler : IRequestHandler<CreateComplexCommand,
|
|||
try
|
||||
{
|
||||
await _repositoryWrapper.BeginTransaction(cancellationToken);
|
||||
var complex = Domain.Entities.Complexes.Complex.Create(request.Name, request.Address, request.SupportPhone);
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>().Add(complex);
|
||||
var complex = Complex.Create(request.Name, request.Address, request.SupportPhone);
|
||||
_repositoryWrapper.SetRepository<Complex>().Add(complex);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
await _repositoryWrapper.CommitAsync(cancellationToken);
|
||||
return complex.AdaptToSDto();
|
|
@ -1,8 +1,4 @@
|
|||
using Brizco.Domain.Entities.Complexes;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
public class CreateComplexUserCommandHandler : IRequestHandler<CreateComplexUserCommand, ComplexUserSDto>
|
||||
{
|
||||
|
@ -27,7 +23,7 @@ public class CreateComplexUserCommandHandler : IRequestHandler<CreateComplexUser
|
|||
try
|
||||
{
|
||||
//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);
|
||||
if (complex == null)
|
||||
throw new AppException("Complex not found", ApiResultStatusCode.NotFound);
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
public class DeleteComplexCommandHandler : IRequestHandler<DeleteComplexCommand, bool>
|
||||
{
|
||||
|
@ -13,12 +13,12 @@ public class DeleteComplexCommandHandler : IRequestHandler<DeleteComplexCommand,
|
|||
try
|
||||
{
|
||||
await _repositoryWrapper.BeginTransaction(cancellationToken);
|
||||
var task = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>()
|
||||
var task = await _repositoryWrapper.SetRepository<Complex>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
||||
if (task == null)
|
||||
throw new AppException("Task not found", ApiResultStatusCode.NotFound);
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>()
|
||||
_repositoryWrapper.SetRepository<Complex>()
|
||||
.Delete(task);
|
||||
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Entities.Complexes;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
public class DeleteComplexUserCommandHandler : IRequestHandler<DeleteComplexUserCommand, bool>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
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)
|
||||
{
|
||||
var complex = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>()
|
||||
var complex = await _repositoryWrapper.SetRepository<Complex>()
|
||||
.TableNoTracking
|
||||
.Where(s => s.Id == request.Id)
|
||||
.Select(ComplexMapper.ProjectToSDto)
|
|
@ -1,8 +1,6 @@
|
|||
using Brizco.Domain.Entities.Complexes;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
public class GetComplexUsersQueryHandler : IRequestHandler<GetComplexUsersQuery, List<ComplexUserSDto>>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
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)
|
||||
{
|
||||
var tasks = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Complex>().TableNoTracking
|
||||
var tasks = await _repositoryWrapper.SetRepository<Complex>().TableNoTracking
|
||||
.OrderByDescending(s => s.CreatedAt)
|
||||
.Skip(request.Page * 15).Take(15)
|
||||
.Select(ComplexMapper.ProjectToSDto)
|
|
@ -1,8 +1,4 @@
|
|||
using Brizco.Domain.Entities.Complexes;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Complex;
|
||||
namespace Brizco.Repository.Handlers.Complexes;
|
||||
|
||||
public class UpdateComplexUserCommandHandler : IRequestHandler<UpdateComplexUserCommand, bool>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Position;
|
||||
namespace Brizco.Repository.Handlers.Positions;
|
||||
|
||||
public class CreatePositionCommandHandler : IRequestHandler<CreatePositionCommand, PositionSDto>
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ public class CreatePositionCommandHandler : IRequestHandler<CreatePositionComman
|
|||
try
|
||||
{
|
||||
await _repositoryWrapper.BeginTransaction(cancellationToken);
|
||||
var entity = Domain.Entities.Complexes.Position
|
||||
var entity = Position
|
||||
.Create(request.Title,
|
||||
request.Description,
|
||||
complexId,
|
||||
|
@ -29,7 +29,7 @@ public class CreatePositionCommandHandler : IRequestHandler<CreatePositionComman
|
|||
|
||||
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.CommitAsync(cancellationToken);
|
||||
return entity.AdaptToSDto();
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Position;
|
||||
namespace Brizco.Repository.Handlers.Positions;
|
||||
|
||||
public class DeletePositionCommandHandler : IRequestHandler<DeletePositionCommand, bool>
|
||||
{
|
||||
|
@ -10,12 +10,12 @@ public class DeletePositionCommandHandler : IRequestHandler<DeletePositionComman
|
|||
}
|
||||
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
|
||||
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
||||
if (shift == null)
|
||||
throw new AppException("Postion not found", ApiResultStatusCode.NotFound);
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>()
|
||||
_repositoryWrapper.SetRepository<Position>()
|
||||
.Delete(shift);
|
||||
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Position;
|
||||
namespace Brizco.Repository.Handlers.Positions;
|
||||
|
||||
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)
|
||||
{
|
||||
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>()
|
||||
var shift = await _repositoryWrapper.SetRepository<Position>()
|
||||
.TableNoTracking
|
||||
.Where(s => s.Id == request.Id)
|
||||
.Select(PositionMapper.ProjectToLDto)
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Position;
|
||||
namespace Brizco.Repository.Handlers.Positions;
|
||||
|
||||
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))
|
||||
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)
|
||||
.OrderByDescending(s => s.CreatedAt)
|
||||
.Skip(request.Page * 15).Take(15)
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Entities.Complexes;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Position;
|
||||
namespace Brizco.Repository.Handlers.Positions;
|
||||
|
||||
public class UpdatePositionCommandHandler : IRequestHandler<UpdatePositionCommand, bool>
|
||||
{
|
||||
|
@ -15,7 +13,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdatePositionComman
|
|||
|
||||
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);
|
||||
if (ent == null)
|
||||
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))
|
||||
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,
|
||||
complexId,
|
||||
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)))
|
||||
newPosition.AddPermission(permission);
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>()
|
||||
_repositoryWrapper.SetRepository<Position>()
|
||||
.Update(newPosition);
|
||||
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Routine;
|
||||
namespace Brizco.Repository.Handlers.Routines;
|
||||
|
||||
public class CreateRoutineCommandHandler : IRequestHandler<CreateRoutineCommand, RoutineSDto>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Routine;
|
||||
namespace Brizco.Repository.Handlers.Routines;
|
||||
|
||||
public class DeleteRoutineCommandHandler : IRequestHandler<DeleteRoutineCommand, bool>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Routine;
|
||||
namespace Brizco.Repository.Handlers.Routines;
|
||||
|
||||
public class GetRoutineQueryHandler : IRequestHandler<GetRoutineQuery, RoutineSDto>
|
||||
{
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Entities.Shifts;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Routine;
|
||||
namespace Brizco.Repository.Handlers.Routines;
|
||||
|
||||
public class GetRoutineShiftsQueryHandler : IRequestHandler<GetRoutineShiftsQuery,List<RoutineShiftResponseDto>>
|
||||
{
|
||||
|
@ -21,7 +19,7 @@ public class GetRoutineShiftsQueryHandler : IRequestHandler<GetRoutineShiftsQuer
|
|||
.ToListAsync(cancellationToken);
|
||||
foreach (var shiftRoutine in shiftRoutines)
|
||||
{
|
||||
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>()
|
||||
var shift = await _repositoryWrapper.SetRepository<Shift>()
|
||||
.TableNoTracking
|
||||
.Where(s => s.Id == shiftRoutine.ShiftId)
|
||||
.Select(ShiftMapper.ProjectToSDto)
|
||||
|
@ -48,7 +46,7 @@ public class GetRoutineShiftsQueryHandler : IRequestHandler<GetRoutineShiftsQuer
|
|||
{
|
||||
var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate);
|
||||
|
||||
var existedShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
||||
var existedShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date, cancellationToken);
|
||||
shift.IsCompleted = existedShiftPlan?.IsCompleted ?? false;
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Routine;
|
||||
namespace Brizco.Repository.Handlers.Routines;
|
||||
|
||||
public class GetRoutinesQueryHandler : IRequestHandler<GetRoutinesQuery, List<RoutineSDto>>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Routine;
|
||||
namespace Brizco.Repository.Handlers.Routines;
|
||||
|
||||
public class UpdateRoutineCommandHandler : IRequestHandler<UpdateRoutineCommand, bool>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Section;
|
||||
namespace Brizco.Repository.Handlers.Sections;
|
||||
|
||||
public class CreateSectionCommandHandler : IRequestHandler<CreateSectionCommand, SectionSDto>
|
||||
{
|
||||
|
@ -21,12 +21,12 @@ public class CreateSectionCommandHandler : IRequestHandler<CreateSectionCommand,
|
|||
try
|
||||
{
|
||||
await _repositoryWrapper.BeginTransaction(cancellationToken);
|
||||
var entity = Domain.Entities.Complexes.Section
|
||||
var entity = Section
|
||||
.Create(request.Title,
|
||||
request.Description,
|
||||
complexId);
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>().Add(entity);
|
||||
_repositoryWrapper.SetRepository<Section>().Add(entity);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
await _repositoryWrapper.CommitAsync(cancellationToken);
|
||||
return entity.AdaptToSDto();
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Section;
|
||||
namespace Brizco.Repository.Handlers.Sections;
|
||||
|
||||
public class DeleteSectionCommandHandler : IRequestHandler<DeleteSectionCommand, bool>
|
||||
{
|
||||
|
@ -10,20 +10,20 @@ public class DeleteSectionCommandHandler : IRequestHandler<DeleteSectionCommand,
|
|||
}
|
||||
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
|
||||
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
||||
if (section == null)
|
||||
throw new AppException("Section not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
var positions = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>()
|
||||
var positions = await _repositoryWrapper.SetRepository<Position>()
|
||||
.TableNoTracking
|
||||
.Where(p => p.SectionId == section.Id)
|
||||
.CountAsync(cancellationToken);
|
||||
if (positions > 0)
|
||||
throw new AppException("این سکشن پوزیشن فعال دارد ، نخست پوزیشن های سکشن را حذف کرده یا منتقل کنید");
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>()
|
||||
_repositoryWrapper.SetRepository<Section>()
|
||||
.Delete(section);
|
||||
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Section;
|
||||
namespace Brizco.Repository.Handlers.Sections;
|
||||
|
||||
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)
|
||||
{
|
||||
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>()
|
||||
var shift = await _repositoryWrapper.SetRepository<Section>()
|
||||
.TableNoTracking
|
||||
.Where(s => s.Id == request.Id)
|
||||
.Select(SectionMapper.ProjectToLDto)
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Section;
|
||||
namespace Brizco.Repository.Handlers.Sections;
|
||||
|
||||
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))
|
||||
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)
|
||||
.OrderByDescending(s => s.CreatedAt)
|
||||
.Skip(request.Page * 15).Take(15)
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Section;
|
||||
namespace Brizco.Repository.Handlers.Sections;
|
||||
|
||||
public class UpdateSectionCommandHandler : IRequestHandler<UpdateSectionCommand, bool>
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ public class UpdateSectionCommandHandler : IRequestHandler<UpdateSectionCommand,
|
|||
|
||||
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);
|
||||
if (shift == null)
|
||||
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))
|
||||
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,
|
||||
complexId);
|
||||
newSection.Id = request.Id;
|
||||
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Section>()
|
||||
_repositoryWrapper.SetRepository<Section>()
|
||||
.Update(newSection);
|
||||
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.ShiftPlan;
|
||||
namespace Brizco.Repository.Handlers.ShiftPlans;
|
||||
|
||||
public class CreateShiftPlanCommandHandler : IRequestHandler<CreateShiftPlanCommand, ShiftPlanLDto>
|
||||
{
|
||||
|
@ -14,14 +12,13 @@ public class CreateShiftPlanCommandHandler : IRequestHandler<CreateShiftPlanComm
|
|||
}
|
||||
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
|
||||
.FirstOrDefaultAsync(s => s.Id == request.ShiftId, cancellationToken);
|
||||
|
||||
if (shift == null)
|
||||
throw new AppException("Shift not found", ApiResultStatusCode.NotFound);
|
||||
var planFor = DateTimeExtensions.UnixTimeStampToDateTime(request.PlanDate);
|
||||
var existedShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
||||
var existedShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
||||
.TableNoTracking
|
||||
.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);
|
||||
}
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>().Add(shiftPlan);
|
||||
_repositoryWrapper.SetRepository<ShiftPlan>().Add(shiftPlan);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
await _repositoryWrapper.CommitAsync(cancellationToken);
|
||||
return shiftPlan.AdaptToLDto();
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.ShiftPlan;
|
||||
namespace Brizco.Repository.Handlers.ShiftPlans;
|
||||
|
||||
public class DeleteShiftPlanCommandHandler : IRequestHandler<DeleteShiftPlanCommand, bool>
|
||||
{
|
||||
|
@ -11,13 +11,13 @@ public class DeleteShiftPlanCommandHandler : IRequestHandler<DeleteShiftPlanComm
|
|||
|
||||
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);
|
||||
|
||||
if (shiftPlan == null)
|
||||
throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
||||
_repositoryWrapper.SetRepository<ShiftPlan>()
|
||||
.Delete(shiftPlan);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.ShiftPlan;
|
||||
namespace Brizco.Repository.Handlers.ShiftPlans;
|
||||
|
||||
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)
|
||||
{
|
||||
var shiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
||||
var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
||||
.TableNoTracking
|
||||
.Where(s => s.Id == request.Id)
|
||||
.Select(ShiftPlanMapper.ProjectToLDto)
|
|
@ -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>>
|
||||
{
|
||||
|
@ -20,7 +19,7 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, Lis
|
|||
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
|
||||
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
|
||||
.OrderByDescending(s => s.CreatedAt)
|
||||
.Where(s => s.ComplexId == complexId);
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Entities.Shifts;
|
||||
|
||||
namespace Brizco.Repository.Handlers.ShiftPlan;
|
||||
namespace Brizco.Repository.Handlers.ShiftPlans;
|
||||
|
||||
public class UpdateShiftPlanCommandHandler : IRequestHandler<UpdateShiftPlanCommand, bool>
|
||||
{
|
||||
|
@ -13,13 +11,13 @@ public class UpdateShiftPlanCommandHandler : IRequestHandler<UpdateShiftPlanComm
|
|||
|
||||
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);
|
||||
|
||||
if (shiftPlan == null)
|
||||
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);
|
||||
|
||||
if (shift == null)
|
||||
|
@ -50,7 +48,7 @@ public class UpdateShiftPlanCommandHandler : IRequestHandler<UpdateShiftPlanComm
|
|||
foreach (var userId in request.UserAndPositionIds)
|
||||
newPlan.AddUser(userId.Key,userId.Value);
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
||||
_repositoryWrapper.SetRepository<ShiftPlan>()
|
||||
.Update(newPlan);
|
||||
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Shift;
|
||||
namespace Brizco.Repository.Handlers.Shifts;
|
||||
|
||||
public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, ShiftSDto>
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Shi
|
|||
try
|
||||
{
|
||||
await _repositoryWrapper.BeginTransaction(cancellationToken);
|
||||
var shift = Domain.Entities.Shifts.Shift
|
||||
var shift = Shift
|
||||
.Create(request.Title,
|
||||
request.Description,
|
||||
request.StartAt,
|
||||
|
@ -34,7 +34,7 @@ public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Shi
|
|||
throw new AppException("روتین شیفت را انتخاب کنید");
|
||||
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.CommitAsync(cancellationToken);
|
||||
return shift.AdaptToSDto();
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Shift;
|
||||
namespace Brizco.Repository.Handlers.Shifts;
|
||||
|
||||
public class DeletePositionCommandHandler : IRequestHandler<DeleteShiftCommand, bool>
|
||||
{
|
||||
|
@ -10,12 +10,12 @@ public class DeletePositionCommandHandler : IRequestHandler<DeleteShiftCommand,
|
|||
}
|
||||
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
|
||||
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
||||
if (shift == null)
|
||||
throw new AppException("Routine not found", ApiResultStatusCode.NotFound);
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>()
|
||||
_repositoryWrapper.SetRepository<Shift>()
|
||||
.Delete(shift);
|
||||
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Shift;
|
||||
namespace Brizco.Repository.Handlers.Shifts;
|
||||
|
||||
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)
|
||||
{
|
||||
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>()
|
||||
var shift = await _repositoryWrapper.SetRepository<Shift>()
|
||||
.TableNoTracking
|
||||
.Where(s => s.Id == request.Id)
|
||||
.Select(ShiftMapper.ProjectToLDto)
|
|
@ -1,8 +1,4 @@
|
|||
using Brizco.Domain.Entities.Shifts;
|
||||
using Brizco.Domain.Entities.Users;
|
||||
using Guid = System.Guid;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Shift;
|
||||
namespace Brizco.Repository.Handlers.Shifts;
|
||||
|
||||
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 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
|
||||
orderby shift.StartAt descending
|
||||
select shift;
|
||||
|
||||
shifts = await originalShifts.AsNoTracking().Select(ShiftMapper.ProjectToSDto).ToListAsync(cancellationToken);
|
||||
foreach (var shift in shifts)
|
||||
{
|
||||
var existedShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
||||
var existedShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date, cancellationToken);
|
||||
if(existedShiftPlan == null)
|
||||
|
@ -66,7 +63,7 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<Sh
|
|||
{
|
||||
if (!Guid.TryParse(_currentUserService.UserId, out Guid userId))
|
||||
throw new AppException("User id is wrong");
|
||||
var existedSupervisorShiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
||||
var existedSupervisorShiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date && s.SupervisorId == userId, cancellationToken);
|
||||
shift.IsCompleted = existedSupervisorShiftPlan?.IsCompleted ?? false;
|
||||
|
@ -87,9 +84,9 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<Sh
|
|||
else
|
||||
{
|
||||
|
||||
shifts = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>().TableNoTracking
|
||||
shifts = await _repositoryWrapper.SetRepository<Shift>().TableNoTracking
|
||||
.Where(s => s.ComplexId == complexId)
|
||||
.OrderByDescending(s => s.CreatedAt)
|
||||
.OrderByDescending(s => s.StartAt)
|
||||
.Skip(request.Page * 15).Take(15)
|
||||
.Select(ShiftMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Entities.Shifts;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Shift;
|
||||
namespace Brizco.Repository.Handlers.Shifts;
|
||||
|
||||
public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand, bool>
|
||||
{
|
||||
|
@ -15,7 +13,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand,
|
|||
|
||||
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);
|
||||
if (shift == null)
|
||||
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))
|
||||
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.StartAt,
|
||||
request.EndAt,
|
||||
|
@ -69,7 +67,7 @@ public class UpdatePositionCommandHandler : IRequestHandler<UpdateShiftCommand,
|
|||
newShift.AddRoutine(routine);
|
||||
}
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>()
|
||||
_repositoryWrapper.SetRepository<Shift>()
|
||||
.Update(newShift);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Task;
|
||||
namespace Brizco.Repository.Handlers.Tasks;
|
||||
|
||||
public class CreateActivityCommandHandler : IRequestHandler<CreateTaskCommand, TaskLDto>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Task;
|
||||
namespace Brizco.Repository.Handlers.Tasks;
|
||||
|
||||
public class DeleteActivityCommandHandler : IRequestHandler<DeleteTaskCommand, bool>
|
||||
{
|
|
@ -1,6 +1,4 @@
|
|||
using Brizco.Domain.Dtos.LargeDtos;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Task;
|
||||
namespace Brizco.Repository.Handlers.Tasks;
|
||||
|
||||
public class GetActivityQueryHandler : IRequestHandler<GetTaskQuery, TaskLDto>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace Brizco.Repository.Handlers.Task;
|
||||
namespace Brizco.Repository.Handlers.Tasks;
|
||||
|
||||
public class GetActivitiesQueryHandler : IRequestHandler<GetTasksQuery, List<TaskSDto>>
|
||||
{
|
|
@ -1,6 +1,6 @@
|
|||
using Brizco.Domain.Entities.Tasks;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Task;
|
||||
namespace Brizco.Repository.Handlers.Tasks;
|
||||
|
||||
public class UpdateActivityCommandHandler : IRequestHandler<UpdateTaskCommand, bool>
|
||||
{
|
|
@ -2,26 +2,22 @@
|
|||
|
||||
namespace Brizco.Repository.MartenHandlers.Notifications;
|
||||
|
||||
public class ReadNotificationCommandHandler : IRequestHandler<ReadNotificationCommand, bool>
|
||||
public class ReadNotificationCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler<ReadNotificationCommand, bool>
|
||||
{
|
||||
private readonly IMartenRepositoryWrapper _martenRepositoryWrapper;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
||||
public ReadNotificationCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
|
||||
{
|
||||
_martenRepositoryWrapper = martenRepositoryWrapper;
|
||||
_currentUserService = currentUserService;
|
||||
}
|
||||
public async Task<bool> Handle(ReadNotificationCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var notification = await _martenRepositoryWrapper.SetRepository<Notification>()
|
||||
var notification = await martenRepositoryWrapper.SetRepository<Notification>()
|
||||
.GetEntityAsync(request.Id, cancellationToken);
|
||||
if (notification == null)
|
||||
throw new BaseApiException(ApiResultStatusCode.NotFound,"Notification not found");
|
||||
throw new BaseApiException(ApiResultStatusCode.NotFound, "Notification not found");
|
||||
if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
|
||||
throw new BaseApiException(ApiResultStatusCode.NotFound, "User id is null");
|
||||
if (notification.UserId != userId)
|
||||
throw new BaseApiException(ApiResultStatusCode.NotFound, "This is not your notification");
|
||||
|
||||
notification.IsRead = true;
|
||||
|
||||
await _martenRepositoryWrapper.SetRepository<Notification>()
|
||||
await martenRepositoryWrapper.SetRepository<Notification>()
|
||||
.AddOrUpdateEntityAsync(notification, cancellationToken);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
using Brizco.Domain.Entities.Users;
|
||||
using Brizco.Repository.Extensions;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Brizco.Repository.Models;
|
||||
namespace Brizco.Repository.Models;
|
||||
|
||||
public class ApplicationContext : IdentityDbContext<ApplicationUser,ApplicationRole,Guid>
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Brizco.Repository.Repositories.Base
|
||||
namespace Brizco.Repository.Repositories.Base
|
||||
{
|
||||
public class Repository<T> : IRepository<T> where T : class, IApiEntity
|
||||
{
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
using Brizco.Repository.Abstracts;
|
||||
|
||||
namespace Brizco.Repository.Repositories.Base
|
||||
{
|
||||
public class WriteRepository<T> : Repository<T>, IDisposable, IWriteRepository<T> where T : class, IApiEntity
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Task = System.Threading.Tasks.Task;
|
||||
|
||||
namespace Brizco.Repository.Repositories.UnitOfWork;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue