Complete Notification Phase

master
Amir Hossein Khademi 2024-07-31 10:18:38 +03:30
parent a8f6fe66b3
commit 5328e74f79
52 changed files with 2582 additions and 631 deletions

View File

@ -1 +1 @@
1.0.1.2 1.4.9.4

View File

@ -1,6 +1,7 @@
{ {
"ConnectionStrings": { "ConnectionStrings": {
"PostgresServer": "Host=185.220.227.123;port=5432;Username=postgres;Password=ub0J7sFFThkSBmkc0TzSKsCfheRnQpyu;Database=BrizcoDB", "PostgresServer": "Host=185.220.227.126;port=5432;Username=postgres;Password=ub0J7sFFThkSBmkc0TzSKsCfheRnQpyu;Database=BrizcoDB",
"MartenDBServer": "Host=185.228.236.40;port=5432;Username=postgres;Password=ub0J7sFFThkSBmkc0TzSKsCfheRnQpyu;Database=BrizcoMartenDB",
"Postgres": "Host=pg-0;Username=postgres;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Application Name=BrizCo", "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;" "MartenDB": "Host=pg-0;Username=postgres;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoMartenDB;"
}, },

View File

@ -6,8 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath> <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<AssemblyVersion>1.0.1.2</AssemblyVersion> <AssemblyVersion>1.4.9.4</AssemblyVersion>
<FileVersion>1.0.1.2</FileVersion> <FileVersion>1.4.9.4</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Enums; namespace Brizco.Api.Controllers;
namespace Brizco.Api.Controllers;
public class ActivityController : ICarterModule public class ActivityController : ICarterModule
{ {
@ -12,7 +10,7 @@ public class ActivityController : ICarterModule
group.MapGet("", GetAllAsync) group.MapGet("", GetAllAsync)
.WithDisplayName("GetActivities") .WithDisplayName("GetActivities")
.RequireAuthorization(builder=>builder.RequireClaim(CustomClaimType.Permission,ApplicationPermission.ViewActivities, ApplicationPermission.ManageActivities)) .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewActivities, ApplicationPermission.ManageActivities))
.HasApiVersion(1.0); .HasApiVersion(1.0);
group.MapGet("{id:guid}", GetAsync) group.MapGet("{id:guid}", GetAsync)
@ -26,7 +24,7 @@ public class ActivityController : ICarterModule
.HasApiVersion(1.0); .HasApiVersion(1.0);
group.MapPost("complete", CompleteActivityAsync) group.MapPost("complete", CompleteActivityAsync)
.WithDisplayName("DoneActivity") .WithDisplayName("CompleteActivity")
.RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ChangeActivityStatus)) .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ChangeActivityStatus))
.HasApiVersion(1.0); .HasApiVersion(1.0);
@ -34,36 +32,35 @@ public class ActivityController : ICarterModule
.WithDisplayName("UnDoneActivity") .WithDisplayName("UnDoneActivity")
.RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ChangeActivityStatus)) .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ChangeActivityStatus))
.HasApiVersion(1.0); .HasApiVersion(1.0);
//group.MapPost("", Post)
// .AllowAnonymous()
// .HasApiVersion(1.0);
//group.MapPut("", Put)
// .HasApiVersion(1.0);
//group.MapDelete("{id:guid}", Delete)
// .HasApiVersion(1.0);
} }
// GET:Get All Entity // GET:Get All Entity
public async Task<IResult> GetAllAsync([FromQuery] int page, [FromQuery] DateQueryFilter? dateQueryFilter, [FromQuery] long? selectedDate, [FromQuery] Guid? selectedShiftPlanId, ISender sender, CancellationToken cancellationToken) public async Task<IResult> GetAllAsync([FromQuery] int page,
=> TypedResults.Ok(await sender.Send(new GetActivitiesQuery(Page: page, SelectedDate: selectedDate ?? 0 , SelectedShiftPlanId: selectedShiftPlanId ?? default , DateQueryFilter: dateQueryFilter ?? null), cancellationToken)); [FromQuery] DateTimeQueryFilter? dateQueryFilter,
[FromQuery] long? selectedDate,
[FromQuery] Guid? selectedShiftPlanId,
[FromQuery] Guid? userId,
ISender sender,
CancellationToken cancellationToken)
=> TypedResults.Ok(await sender.Send(new GetActivitiesQuery(UserId: userId,
Page: page,
SelectedDate: selectedDate ?? 0,
SelectedShiftPlanId: selectedShiftPlanId,
DateQueryFilter: dateQueryFilter), cancellationToken));
// GET:Get An Entity By Id // GET:Get An Entity By Id
public async Task<IResult> GetAsync(Guid id, IActivityService activityService, CancellationToken cancellationToken) public async Task<IResult> GetAsync(Guid id, IActivityService activityService, CancellationToken cancellationToken)
=> TypedResults.Ok(await activityService.DoneActivityAsync(id,cancellationToken)); => TypedResults.Ok(await activityService.DoneActivityAsync(id, cancellationToken));
public async Task<IResult> CompleteActivityAsync([FromBody]List<CompleteActivityRequestDto> requestDtos, [FromServices] IActivityService activityService, CancellationToken cancellationToken) public async Task<IResult> CompleteActivityAsync([FromBody] List<CompleteActivityRequestDto> requestDtos, [FromServices] IActivityService activityService, CancellationToken cancellationToken)
=> TypedResults.Ok(await activityService.CompleteActivitiesAsync(requestDtos, cancellationToken)); => TypedResults.Ok(await activityService.CompleteActivitiesAsync(requestDtos, cancellationToken));
public async Task<IResult> DoneActivityAsync(Guid id, [FromServices] IActivityService activityService, CancellationToken cancellationToken) public async Task<IResult> DoneActivityAsync(Guid id, [FromServices] IActivityService activityService, CancellationToken cancellationToken)
=> TypedResults.Ok(await activityService.DoneActivityAsync(id, cancellationToken)); => TypedResults.Ok(await activityService.DoneActivityAsync(id, cancellationToken));
public async Task<IResult> UnDoneActivityAsync(Guid id,[FromQuery]string undoneReason, [FromServices]IActivityService activityService, CancellationToken cancellationToken) public async Task<IResult> UnDoneActivityAsync(Guid id, [FromQuery] string undoneReason, [FromServices] IActivityService activityService, CancellationToken cancellationToken)
=> TypedResults.Ok(await activityService.UnDoneActivityAsync(id,undoneReason, cancellationToken)); => TypedResults.Ok(await activityService.UnDoneActivityAsync(id, undoneReason, cancellationToken));
//// POST:Create Entity //// POST:Create Entity
//public async Task<IResult> Post([FromQuery]Guid shiftPlanId,IActivityService activityService, CancellationToken cancellationToken) //public async Task<IResult> Post([FromQuery]Guid shiftPlanId,IActivityService activityService, CancellationToken cancellationToken)

View File

@ -0,0 +1,38 @@
namespace Brizco.Api.Controllers;
public class NewsFeedController : ICarterModule
{
public void AddRoutes(IEndpointRouteBuilder app)
{
var group = app.NewVersionedApi("News")
.MapGroup("api/news");
group.MapGet("", GetEntitiesAsync)
.WithDisplayName("Get News Feed")
.HasApiVersion(1.0);
group.MapPost("", PostEntitiesAsync)
.WithDisplayName("Create News Feed")
.HasApiVersion(1.0);
group.MapPut("{id}/pin", ChangePinAsync)
.WithDisplayName("Change NewsFeed Pin")
.HasApiVersion(1.0);
group.MapDelete("{id}", DeleteEntitiesAsync)
.WithDisplayName("Delete News Feed")
.HasApiVersion(1.0);
}
private async Task GetEntitiesAsync([FromQuery] int page, [FromQuery] int? count, [FromServices] IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetNewsFeedsQuery(page, count), cancellationToken));
private async Task PostEntitiesAsync([FromBody]CreateNewsFeedCommand request, [FromServices] IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(request, cancellationToken));
private async Task ChangePinAsync([FromRoute] Guid id, [FromQuery]bool isPin, [FromServices] IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new ChangeNewsFeedPinCommand(id,isPin), cancellationToken));
private async Task DeleteEntitiesAsync([FromRoute] Guid id, [FromServices] IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new DeleteNewsFeedCommand(id), cancellationToken));
}

View File

@ -13,6 +13,12 @@ public class NotificationController : ICarterModule
.RequireAuthorization(builder=>builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()) .RequireAuthorization(builder=>builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
.HasApiVersion(1.0); .HasApiVersion(1.0);
group.MapGet("/unread/count", GetUserNotificationsCountAsync)
.WithDisplayName("Get Unread Notifications Count")
.WithDescription("Get user notifications , by JWT user id")
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
.HasApiVersion(1.0);
group.MapPost("{id}/read",ReadNotificationAsync) group.MapPost("{id}/read",ReadNotificationAsync)
.WithDisplayName("Read Notification") .WithDisplayName("Read Notification")
.WithDescription("Read notification , by JWT user id") .WithDescription("Read notification , by JWT user id")
@ -24,7 +30,10 @@ public class NotificationController : ICarterModule
private async Task<IResult> ReadNotificationAsync([FromRoute] Guid id, [FromServices] IMediator mediator, CancellationToken cancellationToken) private async Task<IResult> ReadNotificationAsync([FromRoute] Guid id, [FromServices] IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new ReadNotificationCommand(id), cancellationToken)); => TypedResults.Ok(await mediator.Send(new ReadNotificationCommand(id), cancellationToken));
private async Task<IResult> GetUserNotificationsAsync([FromQuery] int page, [FromQuery] int count, private async Task<IResult> GetUserNotificationsAsync([FromQuery] int page, [FromQuery] int? count,
[FromServices] IMediator mediator, CancellationToken cancellationToken) [FromServices] IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetNotificationsQuery(page, count), cancellationToken)); => TypedResults.Ok(await mediator.Send(new GetNotificationsQuery(page, count), cancellationToken));
private async Task<IResult> GetUserNotificationsCountAsync([FromServices] IMediator mediator, CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetNotificationsCountQuery(), cancellationToken));
} }

View File

@ -1,6 +1,4 @@
using Brizco.Domain.Enums; namespace Brizco.Api.Controllers;
namespace Brizco.Api.Controllers;
public class ShiftPlanController : ICarterModule public class ShiftPlanController : ICarterModule
{ {
@ -32,6 +30,7 @@ public class ShiftPlanController : ICarterModule
.RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShiftPlans)) .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShiftPlans))
.HasApiVersion(1.0); .HasApiVersion(1.0);
group.MapPost("", Post) group.MapPost("", Post)
.RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShiftPlans)) .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShiftPlans))
.HasApiVersion(1.0); .HasApiVersion(1.0);
@ -54,7 +53,10 @@ public class ShiftPlanController : ICarterModule
// GET:Get All Entity // GET:Get All Entity
public async Task<IResult> GetAllAsync([FromQuery] int page, [FromQuery] long? selectedDate, [FromQuery] DateTimeQueryFilter? dateFilter , ISender sender, CancellationToken cancellationToken) public async Task<IResult> GetAllAsync([FromQuery] int page,
[FromQuery] long? selectedDate,
[FromQuery] DateTimeQueryFilter? dateFilter ,
[FromServices]ISender sender, CancellationToken cancellationToken)
=> TypedResults.Ok(await sender.Send(new GetShiftPlansQuery(page , selectedDate ?? 0 , DateTimeQueryFilter: dateFilter), cancellationToken)); => TypedResults.Ok(await sender.Send(new GetShiftPlansQuery(page , selectedDate ?? 0 , DateTimeQueryFilter: dateFilter), cancellationToken));
// GET:Get An Entity By Id // GET:Get An Entity By Id

View File

@ -34,7 +34,7 @@ public class TaskController : ICarterModule
// GET:Get All Entity // GET:Get All Entity
public async Task<IResult> GetAllAsync([FromQuery] int page, public async Task<IResult> GetAllAsync([FromQuery] int page,
[FromQuery] int? count, [FromQuery] int? count,
[FromQuery] Guid shiftId, [FromQuery] Guid? shiftId,
ISender sender, CancellationToken cancellationToken) ISender sender, CancellationToken cancellationToken)
=> TypedResults.Ok(await sender.Send(new GetTasksQuery(page, ShiftId: shiftId, Count: count), cancellationToken)); => TypedResults.Ok(await sender.Send(new GetTasksQuery(page, ShiftId: shiftId, Count: count), cancellationToken));

View File

@ -16,6 +16,11 @@ public class UserController : ICarterModule
.RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewUsers,ApplicationPermission.ManageUsers)) .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewUsers,ApplicationPermission.ManageUsers))
.HasApiVersion(1.0); .HasApiVersion(1.0);
group.MapGet("/staff", GetAllStaffAsync)
.WithDisplayName("GetAllStaff")
.RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewUsers, ApplicationPermission.ManageUsers))
.HasApiVersion(1.0);
group.MapGet("{id}", GetAsync) group.MapGet("{id}", GetAsync)
.WithDisplayName("GetOneUser") .WithDisplayName("GetOneUser")
.RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewUsers, ApplicationPermission.ManageUsers)) .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewUsers, ApplicationPermission.ManageUsers))
@ -42,6 +47,12 @@ public class UserController : ICarterModule
.HasApiVersion(1.0); .HasApiVersion(1.0);
} }
private async Task<IResult> GetAllStaffAsync([FromQuery] DateTimeQueryFilter filter,
[FromQuery] int page,
[FromQuery] int? count,
IMediator mediator,
CancellationToken cancellationToken)
=> TypedResults.Ok(await mediator.Send(new GetStaffQuery(page, filter, count), cancellationToken));
public async Task<IResult> ChangeUserRoleAsync(Guid roleId,IUserService userService, CancellationToken cancellationToken) public async Task<IResult> ChangeUserRoleAsync(Guid roleId,IUserService userService, CancellationToken cancellationToken)
=> TypedResults.Ok(await userService.ChangeUserRoleAsync(roleId,cancellationToken)); => TypedResults.Ok(await userService.ChangeUserRoleAsync(roleId,cancellationToken));

View File

@ -83,6 +83,7 @@ builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
.Create(typeof(CoreConfig).Assembly) .Create(typeof(CoreConfig).Assembly)
.WithAllOpenGenericHandlerTypesRegistered() .WithAllOpenGenericHandlerTypesRegistered()
.Build()); .Build());
builder.AddSchedulerToAutoFac();
}); });
var app = builder.Build(); var app = builder.Build();

View File

@ -23,7 +23,8 @@
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/scalar/v1", "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/scalar/v1",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_URLS": "http://+:80" "ASPNETCORE_URLS": "http://+:80",
"TZ": "Asia/Tehran"
}, },
"publishAllPorts": true, "publishAllPorts": true,
"DockerfileRunArguments": " --network=mother -p 32767:80" "DockerfileRunArguments": " --network=mother -p 32767:80"

View File

@ -1,8 +1,10 @@
using System.IO.Compression; using System.Collections.Specialized;
using System.IO.Compression;
using Asp.Versioning; using Asp.Versioning;
using AspNetCoreRateLimit; using AspNetCoreRateLimit;
using AspNetCoreRateLimit.Redis; using AspNetCoreRateLimit.Redis;
using Brizco.Domain.Entities.Users; using Autofac.Extras.Quartz;
using Brizco.Core.QuartzServices;
using Marten; using Marten;
using Microsoft.AspNetCore.ResponseCompression; using Microsoft.AspNetCore.ResponseCompression;
using StackExchange.Redis.Extensions.Core.Configuration; using StackExchange.Redis.Extensions.Core.Configuration;
@ -14,6 +16,22 @@ namespace Brizco.Api.WebFramework.Configurations;
public static class ServiceExtensions public static class ServiceExtensions
{ {
public static void AddSchedulerToAutoFac(this ContainerBuilder builder)
{
// configure and register Quartz
var schedulerConfig = new NameValueCollection {
{"quartz.threadPool.threadCount", "3"},
{"quartz.scheduler.threadName", "MyScheduler"},
};
builder.RegisterModule(new QuartzAutofacFactoryModule
{
ConfigurationProvider = c => schedulerConfig
});
builder.RegisterModule(new QuartzAutofacJobsModule(typeof(JobScheduler).Assembly));
builder.RegisterType<JobScheduler>().AsSelf();
}
public static void AddIpRateLimit(this IServiceCollection services, IConfigurationRoot configuration) public static void AddIpRateLimit(this IServiceCollection services, IConfigurationRoot configuration)
{ {

View File

@ -37,6 +37,8 @@ namespace Brizco.Common.Extensions
public static long DateTimeToUnixTimeStamp(DateTime dateTime) public static long DateTimeToUnixTimeStamp(DateTime dateTime)
{ {
if (dateTime == DateTime.MinValue)
return 0;
return ((DateTimeOffset)dateTime).ToUnixTimeMilliseconds(); return ((DateTimeOffset)dateTime).ToUnixTimeMilliseconds();
} }

View File

@ -63,9 +63,11 @@
<Using Include="Microsoft.AspNetCore.Identity" /> <Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="Microsoft.EntityFrameworkCore" /> <Using Include="Microsoft.EntityFrameworkCore" />
<Using Include="Microsoft.IdentityModel.Tokens" /> <Using Include="Microsoft.IdentityModel.Tokens" />
<Using Include="Newtonsoft.Json" />
<Using Include="NPOI.SS.UserModel" /> <Using Include="NPOI.SS.UserModel" />
<Using Include="NPOI.SS.Util" /> <Using Include="NPOI.SS.Util" />
<Using Include="NPOI.XSSF.UserModel" /> <Using Include="NPOI.XSSF.UserModel" />
<Using Include="System.Reflection" />
<Using Include="System.Security.Claims" /> <Using Include="System.Security.Claims" />
<Using Include="System.Text.Json" /> <Using Include="System.Text.Json" />
</ItemGroup> </ItemGroup>

View File

@ -3,29 +3,21 @@ using Task = Brizco.Domain.Entities.Tasks.Task;
namespace Brizco.Core.EntityServices; namespace Brizco.Core.EntityServices;
public class ActivityService : IActivityService public class ActivityService(IMediator mediator, IRepositoryWrapper repositoryWrapper) : IActivityService
{ {
private readonly IMediator _mediator;
private readonly IRepositoryWrapper _repositoryWrapper;
public ActivityService(IMediator mediator, IRepositoryWrapper repositoryWrapper)
{
_mediator = mediator;
_repositoryWrapper = repositoryWrapper;
}
public async Task<bool> DoneActivityAsync(Guid activityId, CancellationToken cancellationToken) public async Task<bool> DoneActivityAsync(Guid activityId, CancellationToken cancellationToken)
{ {
var activity = await _repositoryWrapper.SetRepository<Activity>() var activity = await repositoryWrapper.SetRepository<Activity>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(a => a.Id == activityId, cancellationToken); .FirstOrDefaultAsync(a => a.Id == activityId, cancellationToken);
if (activity == null) if (activity == null)
throw new AppException("Activity not found", ApiResultStatusCode.NotFound); throw new AppException("Activity not found", ApiResultStatusCode.NotFound);
activity.DoneActivity(); activity.DoneActivity();
_repositoryWrapper.SetRepository<Activity>() repositoryWrapper.SetRepository<Activity>()
.Update(activity); .Update(activity);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true; return true;
} }
@ -33,14 +25,14 @@ public class ActivityService : IActivityService
{ {
foreach (var activityRequestDto in requestDtos) foreach (var activityRequestDto in requestDtos)
{ {
var activity = await _repositoryWrapper.SetRepository<Activity>().TableNoTracking var activity = await repositoryWrapper.SetRepository<Activity>().TableNoTracking
.FirstOrDefaultAsync(a => a.Id == activityRequestDto.ActivityId, cancellationToken); .FirstOrDefaultAsync(a => a.Id == activityRequestDto.ActivityId, cancellationToken);
if (activity == null) if (activity == null)
continue; continue;
activity.CompleteActivity(activityRequestDto.IsCompleted, activityRequestDto.PerformanceDescription); activity.CompleteActivity(activityRequestDto.IsCompleted, activityRequestDto.PerformanceDescription);
_repositoryWrapper.SetRepository<Activity>().Update(activity); repositoryWrapper.SetRepository<Activity>().Update(activity);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await repositoryWrapper.SaveChangesAsync(cancellationToken);
} }
return true; return true;
@ -49,44 +41,44 @@ public class ActivityService : IActivityService
public async Task<bool> UnDoneActivityAsync(Guid activityId, string undoneReason, CancellationToken cancellationToken) public async Task<bool> UnDoneActivityAsync(Guid activityId, string undoneReason, CancellationToken cancellationToken)
{ {
var activity = await _repositoryWrapper.SetRepository<Activity>() var activity = await repositoryWrapper.SetRepository<Activity>()
.TableNoTracking .TableNoTracking
.FirstOrDefaultAsync(a => a.Id == activityId, cancellationToken); .FirstOrDefaultAsync(a => a.Id == activityId, cancellationToken);
if (activity == null) if (activity == null)
throw new AppException("Activity not found ", ApiResultStatusCode.NotFound); throw new AppException("Activity not found ", ApiResultStatusCode.NotFound);
activity.UnDoneActivity(undoneReason); activity.UnDoneActivity(undoneReason);
_repositoryWrapper.SetRepository<Activity>() repositoryWrapper.SetRepository<Activity>()
.Update(activity); .Update(activity);
await _repositoryWrapper.SaveChangesAsync(cancellationToken); await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true; return true;
} }
public async Task<bool> UpdateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken) public async Task<bool> UpdateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken)
{ {
var shiftPlan = await _mediator.Send(new GetShiftPlanQuery(shiftPlanId), cancellationToken); var shiftPlan = await mediator.Send(new GetShiftPlanQuery(shiftPlanId), cancellationToken);
if (shiftPlan.Id == Guid.Empty) if (shiftPlan.Id == Guid.Empty)
return false; return false;
var dailyTasks = await (from task in _repositoryWrapper.SetRepository<Task>().Entities var dailyTasks = await (from task in repositoryWrapper.SetRepository<Task>().Entities
join taskShift in _repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId join taskShift in repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId
join taskRoutine in _repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine join taskRoutine in repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine
.TaskId .TaskId
where taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && task.ScheduleType == TaskScheduleType.Daily where taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && task.ScheduleType == TaskScheduleType.Daily
select task).AsNoTracking().ToListAsync(cancellationToken); select task).AsNoTracking().ToListAsync(cancellationToken);
var weeklyTasks = await (from task in _repositoryWrapper.SetRepository<Task>().Entities var weeklyTasks = await (from task in repositoryWrapper.SetRepository<Task>().Entities
join taskShift in _repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId join taskShift in repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId
join taskDay in _repositoryWrapper.SetRepository<TaskDay>().Entities on task.Id equals taskDay.TaskId join taskDay in repositoryWrapper.SetRepository<TaskDay>().Entities on task.Id equals taskDay.TaskId
join taskRoutine in _repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine join taskRoutine in repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine
.TaskId .TaskId
where taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && where taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId &&
taskDay.DayOfWeek == shiftPlan.PlanFor.DayOfWeek && task.ScheduleType == TaskScheduleType.Weekly taskDay.DayOfWeek == shiftPlan.PlanFor.DayOfWeek && task.ScheduleType == TaskScheduleType.Weekly
group task by task.Id into groupedTask group task by task.Id into groupedTask
select groupedTask.FirstOrDefault()).AsNoTracking().ToListAsync(cancellationToken); select groupedTask.FirstOrDefault()).AsNoTracking().ToListAsync(cancellationToken);
var customTasks = await (from task in _repositoryWrapper.SetRepository<Task>().Entities var customTasks = await (from task in repositoryWrapper.SetRepository<Task>().Entities
join taskShift in _repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId join taskShift in repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId
join taskRoutine in _repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine join taskRoutine in repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine
.TaskId .TaskId
where taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && where taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId &&
task.ScheduleType == TaskScheduleType.Custom && task.SetFor.Date == shiftPlan.PlanFor.Date task.ScheduleType == TaskScheduleType.Custom && task.SetFor.Date == shiftPlan.PlanFor.Date
@ -98,13 +90,13 @@ public class ActivityService : IActivityService
tasks.AddRange(dailyTasks); tasks.AddRange(dailyTasks);
tasks.AddRange(customTasks); tasks.AddRange(customTasks);
var shiftPlanPositions = await _repositoryWrapper.SetRepository<ShiftPlanUser>() var shiftPlanPositions = await repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking .TableNoTracking
.Where(spu => spu.ShiftPlanId == shiftPlan.Id) .Where(spu => spu.ShiftPlanId == shiftPlan.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
var activities = await _repositoryWrapper.SetRepository<Activity>() var activities = await repositoryWrapper.SetRepository<Activity>()
.TableNoTracking .TableNoTracking
.Where(a => a.ShiftPlanId == shiftPlan.ShiftId && a.SetFor.Date == shiftPlan.PlanFor.Date) .Where(a => a.ShiftPlanId == shiftPlan.ShiftId && a.SetFor.Date == shiftPlan.PlanFor.Date)
.Select(ActivityMapper.ProjectToLDto) .Select(ActivityMapper.ProjectToLDto)
@ -115,7 +107,7 @@ public class ActivityService : IActivityService
if (foundedTask == null) if (foundedTask == null)
continue; continue;
var taskPositions = await _repositoryWrapper.SetRepository<TaskPosition>() var taskPositions = await repositoryWrapper.SetRepository<TaskPosition>()
.TableNoTracking .TableNoTracking
.Where(tp => tp.TaskId == foundedTask.Id) .Where(tp => tp.TaskId == foundedTask.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
@ -128,7 +120,7 @@ public class ActivityService : IActivityService
if (activity.UserId != foundedUser.UserId) if (activity.UserId != foundedUser.UserId)
{ {
await _mediator.Send(new UpdateActivityCommand(activity.Id, activity.Status, activity.DoneAt, activity.PerformanceDescription, await mediator.Send(new UpdateActivityCommand(activity.Id, activity.Status, activity.DoneAt, activity.PerformanceDescription,
activity.Type, activity.Title, activity.Description, activity.IsDisposable, activity.SetFor, activity.HasDisposed, activity.Amount activity.Type, activity.Title, activity.Description, activity.IsDisposable, activity.SetFor, activity.HasDisposed, activity.Amount
, activity.AmountType, activity.ScheduleType, shiftPlan.Id, foundedUser.UserId), cancellationToken); , activity.AmountType, activity.ScheduleType, shiftPlan.Id, foundedUser.UserId), cancellationToken);
} }
@ -138,30 +130,30 @@ public class ActivityService : IActivityService
} }
public async Task<bool> CreateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken) { public async Task<bool> CreateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken) {
var shiftPlan = await _mediator.Send(new GetShiftPlanQuery(shiftPlanId), cancellationToken); var shiftPlan = await mediator.Send(new GetShiftPlanQuery(shiftPlanId), cancellationToken);
if (shiftPlan.Id == Guid.Empty) if (shiftPlan.Id == Guid.Empty)
return false; return false;
var dailyTasks = await (from task in _repositoryWrapper.SetRepository<Task>().Entities var dailyTasks = await (from task in repositoryWrapper.SetRepository<Task>().Entities
join taskShift in _repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId join taskShift in repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId
join taskRoutine in _repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine join taskRoutine in repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine
.TaskId .TaskId
where task.IsActivity == false && taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && task.ScheduleType == TaskScheduleType.Daily where task.IsActivity == false && taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && task.ScheduleType == TaskScheduleType.Daily
select task).AsNoTracking().ToListAsync(cancellationToken); select task).AsNoTracking().ToListAsync(cancellationToken);
var weeklyTasks = await (from task in _repositoryWrapper.SetRepository<Task>().Entities var weeklyTasks = await (from task in repositoryWrapper.SetRepository<Task>().Entities
join taskShift in _repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId join taskShift in repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId
join taskDay in _repositoryWrapper.SetRepository<TaskDay>().Entities on task.Id equals taskDay.TaskId join taskDay in repositoryWrapper.SetRepository<TaskDay>().Entities on task.Id equals taskDay.TaskId
join taskRoutine in _repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine join taskRoutine in repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine
.TaskId .TaskId
where task.IsActivity == false && taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && where task.IsActivity == false && taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId &&
taskDay.DayOfWeek == shiftPlan.PlanFor.DayOfWeek && task.ScheduleType == TaskScheduleType.Weekly taskDay.DayOfWeek == shiftPlan.PlanFor.DayOfWeek && task.ScheduleType == TaskScheduleType.Weekly
group task by task.Id into groupedTask group task by task.Id into groupedTask
select groupedTask.FirstOrDefault()).AsNoTracking().ToListAsync(cancellationToken); select groupedTask.FirstOrDefault()).AsNoTracking().ToListAsync(cancellationToken);
var customTasks = await (from task in _repositoryWrapper.SetRepository<Task>().Entities var customTasks = await (from task in repositoryWrapper.SetRepository<Task>().Entities
join taskShift in _repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId join taskShift in repositoryWrapper.SetRepository<TaskShift>().Entities on task.Id equals taskShift.TaskId
join taskRoutine in _repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine join taskRoutine in repositoryWrapper.SetRepository<TaskRoutine>().Entities on task.Id equals taskRoutine
.TaskId .TaskId
where task.IsActivity == false && taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId && where task.IsActivity == false && taskShift.ShiftId == shiftPlan.ShiftId && taskRoutine.RoutineId == shiftPlan.RoutineId &&
task.ScheduleType == TaskScheduleType.Custom && task.SetFor.Date == shiftPlan.PlanFor.Date task.ScheduleType == TaskScheduleType.Custom && task.SetFor.Date == shiftPlan.PlanFor.Date
@ -173,14 +165,14 @@ public class ActivityService : IActivityService
tasks.AddRange(customTasks); tasks.AddRange(customTasks);
var shiftPlanPositions = await _repositoryWrapper.SetRepository<ShiftPlanUser>() var shiftPlanPositions = await repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking .TableNoTracking
.Where(spu => spu.ShiftPlanId == shiftPlan.Id) .Where(spu => spu.ShiftPlanId == shiftPlan.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
foreach (var task in tasks) foreach (var task in tasks)
{ {
var taskPositions = await _repositoryWrapper.SetRepository<TaskPosition>() var taskPositions = await repositoryWrapper.SetRepository<TaskPosition>()
.TableNoTracking .TableNoTracking
.Where(tp => tp.TaskId == task.Id) .Where(tp => tp.TaskId == task.Id)
.ToListAsync(cancellationToken); .ToListAsync(cancellationToken);
@ -190,7 +182,7 @@ public class ActivityService : IActivityService
var fundedUser = shiftPlanPositions.FirstOrDefault(spu => spu.PositionId == taskPosition.PositionId); var fundedUser = shiftPlanPositions.FirstOrDefault(spu => spu.PositionId == taskPosition.PositionId);
if (fundedUser != null) if (fundedUser != null)
{ {
await _mediator.Send(new CreateActivityCommand(task.Type, task.Title, task.Description, task.IsDisposable, await mediator.Send(new CreateActivityCommand(task.Type, task.Title, task.Description, task.IsDisposable,
shiftPlan.PlanFor, task.HasDisposed, task.Amount, task.AmountType, shiftPlan.PlanFor, task.HasDisposed, task.Amount, task.AmountType,
task.ScheduleType, shiftPlan.Id, fundedUser.UserId), cancellationToken); task.ScheduleType, shiftPlan.Id, fundedUser.UserId), cancellationToken);
} }

View File

@ -34,6 +34,17 @@ public class ShiftPlanService(IMediator mediator, IActivityService activityServi
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);
var shiftPlanUsers = await repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking.Where(s => s.ShiftPlanId == id)
.Select(ShiftPlanUserMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
foreach (var shiftPlanUser in shiftPlanUsers)
{
var message = $"{shiftPlanUser.UserFullName}";
}
return true; return true;
} }
} }

View File

@ -1,7 +1,4 @@
using Newtonsoft.Json; namespace Brizco.Core.MartenServices;
using System.Reflection;
namespace Brizco.Core.MartenServices;
public class BrewService : IBrewService public class BrewService : IBrewService
{ {

View File

@ -1,9 +1,7 @@
using Brizco.Domain.Entities.ShiftPlans; namespace Brizco.Core.QuartzServices.Handlers;
namespace Brizco.Core.QuartzServices.Handlers; public class CreateShiftPlanNotificationsCommandHandler(IMediator mediator, IRepositoryWrapper repositoryWrapper)
: IRequestHandler<CreateShiftPlanNotificationsCommand, bool>
public class CreateShiftPlanNotificationsCommandHandler(IMediator mediator,IRepositoryWrapper repositoryWrapper)
: IRequestHandler<CreateShiftPlanNotificationsCommand,bool>
{ {
public async Task<bool> Handle(CreateShiftPlanNotificationsCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(CreateShiftPlanNotificationsCommand request, CancellationToken cancellationToken)
{ {
@ -28,8 +26,8 @@ public class CreateShiftPlanNotificationsCommandHandler(IMediator mediator,IRepo
foreach (var shiftPlanUser in shiftPlanUsers) foreach (var shiftPlanUser in shiftPlanUsers)
{ {
var completeShiftMessageForUser = $""; var completeShiftMessageForUser = $"شیفت‌های هفته بعد بسته شد، دیگه کار، کار، کار.";
await mediator.Send( new CreateNotificationCommand(completeShiftMessageForUser, shiftPlanUser.UserId, shiftPlan.ComplexId), cancellationToken); await mediator.Send(new CreateNotificationCommand(completeShiftMessageForUser, shiftPlanUser.UserId, shiftPlan.ComplexId), cancellationToken);
} }
} }

View File

@ -1,9 +1,11 @@
using Brizco.Core.QuartzServices.Commands; using Brizco.Core.QuartzServices.Commands;
using Microsoft.Extensions.Logging;
using Quartz; using Quartz;
namespace Brizco.Core.QuartzServices.Handlers; namespace Brizco.Core.QuartzServices.Handlers;
public class SetShiftPlanNotificationScheduleCommandHandler(IRepositoryWrapper repositoryWrapper,IScheduler scheduler) : IRequestHandler<SetShiftPlanNotificationScheduleCommand,bool> public class SetShiftPlanNotificationScheduleCommandHandler(IRepositoryWrapper repositoryWrapper,IScheduler scheduler,IMediator mediator,ILogger<SetShiftPlanNotificationScheduleCommand> logger)
: IRequestHandler<SetShiftPlanNotificationScheduleCommand,bool>
{ {
public async Task<bool> Handle(SetShiftPlanNotificationScheduleCommand request, CancellationToken cancellationToken) public async Task<bool> Handle(SetShiftPlanNotificationScheduleCommand request, CancellationToken cancellationToken)
{ {
@ -20,9 +22,22 @@ public class SetShiftPlanNotificationScheduleCommandHandler(IRepositoryWrapper r
if(shift == null) if(shift == null)
throw new BaseApiException(ApiResultStatusCode.NotFound, "Shift not found in set schedule"); 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 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);
}
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 shiftPlanEndAt = (new DateTime(shiftPlan.PlanFor.Year, shiftPlan.PlanFor.Month, shiftPlan.PlanFor.Day, shift.EndAt.Hours, shift.EndAt.Minutes, shift.EndAt.Seconds)).ToUniversalTime();
var currentDate = DateTime.UtcNow;
var startTimeOffset = new DateTimeOffset(shiftPlanStartAt.Year, shiftPlanStartAt.Month, shiftPlanStartAt.Day, shiftPlanStartAt.Hour, var startTimeOffset = new DateTimeOffset(shiftPlanStartAt.Year, shiftPlanStartAt.Month, shiftPlanStartAt.Day, shiftPlanStartAt.Hour,
shiftPlanStartAt.Minute, shiftPlanStartAt.Second, TimeSpan.Zero); shiftPlanStartAt.Minute, shiftPlanStartAt.Second, TimeSpan.Zero);
var endTimeOffset = new DateTimeOffset(shiftPlanEndAt.Year, shiftPlanEndAt.Month, shiftPlanEndAt.Day, shiftPlanEndAt.Hour, var endTimeOffset = new DateTimeOffset(shiftPlanEndAt.Year, shiftPlanEndAt.Month, shiftPlanEndAt.Day, shiftPlanEndAt.Hour,
@ -36,10 +51,9 @@ public class SetShiftPlanNotificationScheduleCommandHandler(IRepositoryWrapper r
ITrigger beforeEndShift30MinTrigger = TriggerBuilder.Create() ITrigger beforeEndShift30MinTrigger = TriggerBuilder.Create()
.WithIdentity(StringExtensions.GetId(9), shift.ComplexId.ToString()) .WithIdentity(StringExtensions.GetId(9), shift.ComplexId.ToString())
.WithSimpleSchedule(x => x.WithRepeatCount(0)) .WithSimpleSchedule(x => x.WithRepeatCount(0))
.StartAt(endTimeOffset.AddMinutes(-40)) .StartAt(endTimeOffset.AddMinutes(-35))
.Build(); .Build();
IJobDetail endOfShift = JobBuilder.Create<ShiftPlanNotificationScheduledJob>() IJobDetail endOfShift = JobBuilder.Create<ShiftPlanNotificationScheduledJob>()
.WithIdentity(ShiftPlanNotifyType.EndOfShift.ToString(), shiftPlan.Id.ToString()) .WithIdentity(ShiftPlanNotifyType.EndOfShift.ToString(), shiftPlan.Id.ToString())
.Build(); .Build();
@ -60,9 +74,10 @@ public class SetShiftPlanNotificationScheduleCommandHandler(IRepositoryWrapper r
.Build(); .Build();
await scheduler.ScheduleJob(beforeEndShift30Min, beforeEndShift30MinTrigger, cancellationToken); var seTimeOffsetA = await scheduler.ScheduleJob(beforeEndShift30Min, beforeEndShift30MinTrigger, cancellationToken);
await scheduler.ScheduleJob(endOfShift, endOfShiftTrigger, cancellationToken); var seTimeOffsetB = await scheduler.ScheduleJob(endOfShift, endOfShiftTrigger, cancellationToken);
await scheduler.ScheduleJob(afterStartShift2Hour, afterStartShift2HourTrigger, cancellationToken); var seTimeOffsetC = await scheduler.ScheduleJob(afterStartShift2Hour, afterStartShift2HourTrigger, cancellationToken);
await scheduler.Start(cancellationToken);
return true; return true;

View File

@ -1,5 +1,4 @@
using Brizco.Domain.Entities.ShiftPlans; using Brizco.Domain.Entities.Tasks;
using Brizco.Domain.Entities.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Quartz; using Quartz;
using Task = System.Threading.Tasks.Task; using Task = System.Threading.Tasks.Task;
@ -26,12 +25,15 @@ public class ShiftPlanNotificationScheduledJob : IJob
var notifyType = (ShiftPlanNotifyType)int.Parse(context.JobDetail.Key.Name); var notifyType = (ShiftPlanNotifyType)int.Parse(context.JobDetail.Key.Name);
var shiftPlanId = Guid.Parse(context.JobDetail.Key.Group); var shiftPlanId = Guid.Parse(context.JobDetail.Key.Group);
var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>().TableNoTracking var shiftPlan = await _repositoryWrapper.SetRepository<ShiftPlan>().TableNoTracking
.FirstOrDefaultAsync(f => f.Id == shiftPlanId); .Where(f => f.Id == shiftPlanId)
.Select(ShiftPlanMapper.ProjectToSDto)
.FirstOrDefaultAsync();
if (shiftPlan == null) if (shiftPlan == null)
throw new Exception("Shift plan not found"); throw new Exception("Shift plan not found");
var shiftPlanUsers = await _repositoryWrapper.SetRepository<ShiftPlanUser>() var shiftPlanUsers = await _repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking .TableNoTracking
.Where(f => f.ShiftPlanId == shiftPlanId) .Where(f => f.ShiftPlanId == shiftPlanId)
.Select(ShiftPlanUserMapper.ProjectToSDto)
.ToListAsync(); .ToListAsync();
var superVisorId = shiftPlan.SupervisorId; var superVisorId = shiftPlan.SupervisorId;
switch (notifyType) switch (notifyType)
@ -47,7 +49,7 @@ public class ShiftPlanNotificationScheduledJob : IJob
var unDoneCount = activities.Count(a => a.UserId == shiftPlanUser.UserId && a.IsDone == false); var unDoneCount = activities.Count(a => a.UserId == shiftPlanUser.UserId && a.IsDone == false);
if(unDoneCount == 0) if(unDoneCount == 0)
continue; continue;
string message = $"شما تعداد {unDoneCount} وظیفه انجام نشده در شیفت مورد نظر دارید ، نیم ساعت به پایان شیفت مانده است"; string message = $"نیم ساعت مونده تا شیفت تموم شه و {unDoneCount} عدد از تست هات مونده، حالا چه خاکی به سر کنیم!😱";
await _mediator.Send(new CreateNotificationCommand(message, shiftPlanUser.UserId, shiftPlan.ComplexId)); await _mediator.Send(new CreateNotificationCommand(message, shiftPlanUser.UserId, shiftPlan.ComplexId));
} }
break; break;
@ -59,14 +61,23 @@ public class ShiftPlanNotificationScheduledJob : IJob
var unDoneCount = activitiesEndShift.Count(a => a.UserId == shiftPlanUser.UserId && a.IsDone == false); var unDoneCount = activitiesEndShift.Count(a => a.UserId == shiftPlanUser.UserId && a.IsDone == false);
if (unDoneCount == 0) if (unDoneCount == 0)
continue; continue;
string message = $"شما تعداد {unDoneCount} وظیفه انجام نشده در شیفت مورد نظر دارید"; string message = $"{shiftPlanUser.UserFullName} {shiftPlan.ShiftTitle} {shiftPlan.PlanFor.ToPersianDateTime().ToLongDateTimeString()} تموم شده است و {unDoneCount} - عدد از تسک های شما کاری روشون انجام نشده ، خطر سوپروایزر در کمین است";
await _mediator.Send(new CreateNotificationCommand(message, shiftPlanUser.UserId, shiftPlan.ComplexId)); await _mediator.Send(new CreateNotificationCommand(message, shiftPlanUser.UserId, shiftPlan.ComplexId));
} }
string superVisorAfterShiftMessage = $"سوپر وایزر محترم ، شیفت مورد نظر به پایان رسیده است ، لطفا فعالیت ها را رسیدگی کنید"; string superVisorAfterShiftMessage = $"{shiftPlan.SupervisorFullName} محترم {shiftPlan.ShiftTitle} تموم شد. برو به کار بچه ها نمره بده و مو رو از ماست بکش و کامنت یادت نره";
await _mediator.Send(new CreateNotificationCommand(superVisorAfterShiftMessage, shiftPlan.SupervisorId, shiftPlan.ComplexId)); await _mediator.Send(new CreateNotificationCommand(superVisorAfterShiftMessage, shiftPlan.SupervisorId, shiftPlan.ComplexId));
break; break;
case ShiftPlanNotifyType.AfterStartShift2Hour: case ShiftPlanNotifyType.AfterStartShift2Hour:
var activities2AfterStartShift = await _repositoryWrapper.SetRepository<Activity>().TableNoTracking
.Where(a => a.ShiftPlanId == shiftPlanId).ToListAsync();
foreach (var shiftPlanUser in shiftPlanUsers)
{
var unDoneCount = activities2AfterStartShift.Count(a => a.UserId == shiftPlanUser.UserId && a.IsDone == false);
if (unDoneCount == 0)
continue;
string message = $"{shiftPlanUser.UserFullName} دوساعت از {shiftPlan.ShiftTitle} گذشته ، اون انگشت و بزن روی تیک تسک ها که وقت طلاس مشتیییییی ";
await _mediator.Send(new CreateNotificationCommand(message, shiftPlanUser.UserId, shiftPlan.ComplexId));
}
break; break;
default: default:
return; return;

View File

@ -61,6 +61,7 @@
<Using Include="Brizco.Domain.Entities.Shifts" /> <Using Include="Brizco.Domain.Entities.Shifts" />
<Using Include="Brizco.Domain.Entities.Users" /> <Using Include="Brizco.Domain.Entities.Users" />
<Using Include="Brizco.Domain.Enums" /> <Using Include="Brizco.Domain.Enums" />
<Using Include="Brizco.Domain.MartenEntities.NewFeeds" />
<Using Include="Mapster" /> <Using Include="Mapster" />
<Using Include="Microsoft.AspNetCore.Identity" /> <Using Include="Microsoft.AspNetCore.Identity" />
<Using Include="System.ComponentModel" /> <Using Include="System.ComponentModel" />
@ -70,4 +71,10 @@
<Using Include="MediatR" /> <Using Include="MediatR" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="MartenEntities\NewFeeds\" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,5 @@
namespace Brizco.Domain.CommandQueries.Commands;
public record CreateNewsFeedCommand(string Title,string Content,bool IsPin) : IRequest<Guid>;
public record DeleteNewsFeedCommand(Guid Id) : IRequest<bool>;
public record ChangeNewsFeedPinCommand(Guid Id , bool IsPin) : IRequest<bool>;

View File

@ -2,7 +2,11 @@
namespace Brizco.Domain.CommandQueries.Queries; namespace Brizco.Domain.CommandQueries.Queries;
public sealed record GetActivitiesQuery(int Page = 0 , long SelectedDate = 0 , Guid SelectedShiftPlanId = default , DateQueryFilter? DateQueryFilter = null) : IRequest<List<ActivitySDto>>; public sealed record GetActivitiesQuery(int Page = 0 ,
long SelectedDate = 0 ,
Guid? SelectedShiftPlanId = null ,
DateTimeQueryFilter? DateQueryFilter = null,
Guid? UserId = null) : IRequest<List<ActivitySDto>>;
public sealed record GetActivityQuery(Guid Id) : IRequest<ActivityLDto>; public sealed record GetActivityQuery(Guid Id) : IRequest<ActivityLDto>;

View File

@ -0,0 +1,3 @@
namespace Brizco.Domain.CommandQueries.Queries;
public record GetNewsFeedsQuery(int Page , int? Count = 0) : IRequest<List<NewsFeed>>;

View File

@ -2,4 +2,5 @@
namespace Brizco.Domain.CommandQueries.Queries; namespace Brizco.Domain.CommandQueries.Queries;
public record GetNotificationsQuery(int Page,int Count, Guid? UserId=null) : IRequest<List<Notification>>; public record GetNotificationsQuery(int Page,int? Count=null, Guid? UserId=null) : IRequest<List<Notification>>;
public record GetNotificationsCountQuery() : IRequest<int>;

View File

@ -0,0 +1,3 @@
namespace Brizco.Domain.CommandQueries.Queries;
public record GetStaffQuery(int Page , DateTimeQueryFilter DateTimeQuery , int? Count = null) : IRequest<List<StaffResponseSDto>>;

View File

@ -0,0 +1,8 @@
namespace Brizco.Domain.Dtos.ResponseDto;
public class StaffResponseSDto
{
public Guid Id { get; set; }
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
}

View File

@ -20,6 +20,7 @@ public class ActivitySDto : BaseDto<ActivitySDto , Activity>
public string UserFirstName { get; set; } = string.Empty; public string UserFirstName { get; set; } = string.Empty;
public string UserLastName { get; set; } = string.Empty; public string UserLastName { get; set; } = string.Empty;
public string UserFullName => UserFirstName + " " + UserLastName; public string UserFullName => UserFirstName + " " + UserLastName;
public Guid UserId { get; set; }
public int Amount { get; set; } public int Amount { get; set; }

View File

@ -18,6 +18,7 @@ public class ShiftPlanSDto : BaseDto<ShiftPlanSDto,ShiftPlan>
public string ShiftTitle { get; set; } = string.Empty; public string ShiftTitle { get; set; } = string.Empty;
public TimeSpan StartAt { get; set; } public TimeSpan StartAt { get; set; }
public TimeSpan EndAt { get; set; } public TimeSpan EndAt { get; set; }
public Guid SupervisorId { get; set; }
public List<ShiftPlanUserSDto> Users { get; set; } = new(); public List<ShiftPlanUserSDto> Users { get; set; } = new();
} }

View File

@ -1,9 +0,0 @@
namespace Brizco.Domain.Enums;
public enum DateQueryFilter
{
Today = 0,
Tomorrow = 1,
ThisWeek = 2,
Yesterday = 3,
}

View File

@ -5,6 +5,7 @@ public enum DateTimeQueryFilter
CustomDate = 0, CustomDate = 0,
Today = 1, Today = 1,
Yesterday = 2, Yesterday = 2,
Tomorrow = 3,
PastWeek = 10, PastWeek = 10,
NextWeek = 11, NextWeek = 11,
ThisWeek = 12, ThisWeek = 12,

View File

@ -20,10 +20,12 @@ namespace Brizco.Domain.Mappers
IsDone = p1.IsDone, IsDone = p1.IsDone,
UnDoneReason = p1.UnDoneReason, UnDoneReason = p1.UnDoneReason,
PerformanceDescription = p1.PerformanceDescription, PerformanceDescription = p1.PerformanceDescription,
UserId = p1.UserId,
User = new ApplicationUser() User = new ApplicationUser()
{ {
FirstName = p1.UserFirstName, FirstName = p1.UserFirstName,
LastName = p1.UserLastName LastName = p1.UserLastName,
Id = p1.UserId
}, },
ShiftPlanId = p1.ShiftPlanId, ShiftPlanId = p1.ShiftPlanId,
ShiftPlan = new ShiftPlan() {Id = p1.ShiftPlanId}, ShiftPlan = new ShiftPlan() {Id = p1.ShiftPlanId},
@ -52,6 +54,7 @@ namespace Brizco.Domain.Mappers
result.IsDone = p2.IsDone; result.IsDone = p2.IsDone;
result.UnDoneReason = p2.UnDoneReason; result.UnDoneReason = p2.UnDoneReason;
result.PerformanceDescription = p2.PerformanceDescription; result.PerformanceDescription = p2.PerformanceDescription;
result.UserId = p2.UserId;
result.User = funcMain1(new Never(), result.User, p2); result.User = funcMain1(new Never(), result.User, p2);
result.ShiftPlanId = p2.ShiftPlanId; result.ShiftPlanId = p2.ShiftPlanId;
result.ShiftPlan = funcMain2(new Never(), result.ShiftPlan, p2); result.ShiftPlan = funcMain2(new Never(), result.ShiftPlan, p2);
@ -75,10 +78,12 @@ namespace Brizco.Domain.Mappers
IsDone = p8.IsDone, IsDone = p8.IsDone,
UnDoneReason = p8.UnDoneReason, UnDoneReason = p8.UnDoneReason,
PerformanceDescription = p8.PerformanceDescription, PerformanceDescription = p8.PerformanceDescription,
UserId = p8.UserId,
User = new ApplicationUser() User = new ApplicationUser()
{ {
FirstName = p8.UserFirstName, FirstName = p8.UserFirstName,
LastName = p8.UserLastName LastName = p8.UserLastName,
Id = p8.UserId
}, },
ShiftPlanId = p8.ShiftPlanId, ShiftPlanId = p8.ShiftPlanId,
ShiftPlan = new ShiftPlan() {Id = p8.ShiftPlanId}, ShiftPlan = new ShiftPlan() {Id = p8.ShiftPlanId},
@ -112,6 +117,7 @@ namespace Brizco.Domain.Mappers
PerformanceDescription = p9.PerformanceDescription, PerformanceDescription = p9.PerformanceDescription,
UserFirstName = p9.User != null ? p9.User.FirstName : string.Empty, UserFirstName = p9.User != null ? p9.User.FirstName : string.Empty,
UserLastName = p9.User != null ? p9.User.LastName : string.Empty, UserLastName = p9.User != null ? p9.User.LastName : string.Empty,
UserId = p9.UserId,
Amount = p9.Amount, Amount = p9.Amount,
ShiftPlanId = p9.ShiftPlanId, ShiftPlanId = p9.ShiftPlanId,
AmountType = p9.AmountType, AmountType = p9.AmountType,
@ -141,6 +147,7 @@ namespace Brizco.Domain.Mappers
result.PerformanceDescription = p10.PerformanceDescription; result.PerformanceDescription = p10.PerformanceDescription;
result.UserFirstName = p10.User != null ? p10.User.FirstName : string.Empty; result.UserFirstName = p10.User != null ? p10.User.FirstName : string.Empty;
result.UserLastName = p10.User != null ? p10.User.LastName : string.Empty; result.UserLastName = p10.User != null ? p10.User.LastName : string.Empty;
result.UserId = p10.UserId;
result.Amount = p10.Amount; result.Amount = p10.Amount;
result.ShiftPlanId = p10.ShiftPlanId; result.ShiftPlanId = p10.ShiftPlanId;
result.AmountType = p10.AmountType; result.AmountType = p10.AmountType;
@ -165,6 +172,7 @@ namespace Brizco.Domain.Mappers
PerformanceDescription = p12.PerformanceDescription, PerformanceDescription = p12.PerformanceDescription,
UserFirstName = p12.User != null ? p12.User.FirstName : string.Empty, UserFirstName = p12.User != null ? p12.User.FirstName : string.Empty,
UserLastName = p12.User != null ? p12.User.LastName : string.Empty, UserLastName = p12.User != null ? p12.User.LastName : string.Empty,
UserId = p12.UserId,
Amount = p12.Amount, Amount = p12.Amount,
ShiftPlanId = p12.ShiftPlanId, ShiftPlanId = p12.ShiftPlanId,
AmountType = p12.AmountType, AmountType = p12.AmountType,
@ -289,6 +297,7 @@ namespace Brizco.Domain.Mappers
result.FirstName = p2.UserFirstName; result.FirstName = p2.UserFirstName;
result.LastName = p2.UserLastName; result.LastName = p2.UserLastName;
result.Id = p2.UserId;
return result; return result;
} }

View File

@ -29,6 +29,10 @@ namespace Brizco.Domain.Mappers
Title = p1.ShiftTitle, Title = p1.ShiftTitle,
Id = p1.ShiftId Id = p1.ShiftId
}, },
ComplexId = p1.ComplexId,
Complex = new Complex() {Id = p1.ComplexId},
SupervisorId = p1.SupervisorId,
Supervisor = new ApplicationUser() {Id = p1.SupervisorId},
Users = funcMain1(p1.Users), Users = funcMain1(p1.Users),
Id = p1.Id Id = p1.Id
}; };
@ -47,198 +51,212 @@ namespace Brizco.Domain.Mappers
result.CompleteDescription = p3.CompleteDescription; result.CompleteDescription = p3.CompleteDescription;
result.ShiftId = p3.ShiftId; result.ShiftId = p3.ShiftId;
result.Shift = funcMain2(new Never(), result.Shift, p3); result.Shift = funcMain2(new Never(), result.Shift, p3);
result.Users = funcMain3(p3.Users, result.Users); result.ComplexId = p3.ComplexId;
result.Complex = funcMain3(new Never(), result.Complex, p3);
result.SupervisorId = p3.SupervisorId;
result.Supervisor = funcMain4(new Never(), result.Supervisor, p3);
result.Users = funcMain5(p3.Users, result.Users);
result.Id = p3.Id; result.Id = p3.Id;
return result; return result;
} }
public static Expression<Func<ShiftPlanSDto, ShiftPlan>> ProjectToShiftPlan => p9 => new ShiftPlan() public static Expression<Func<ShiftPlanSDto, ShiftPlan>> ProjectToShiftPlan => p13 => new ShiftPlan()
{ {
PlanFor = p9.PlanFor, PlanFor = p13.PlanFor,
IsCompleted = p9.IsCompleted, IsCompleted = p13.IsCompleted,
CompletePercent = p9.CompletePercent, CompletePercent = p13.CompletePercent,
CompleteDescription = p9.CompleteDescription, CompleteDescription = p13.CompleteDescription,
ShiftId = p9.ShiftId, ShiftId = p13.ShiftId,
Shift = new Shift() Shift = new Shift()
{ {
Title = p9.ShiftTitle, Title = p13.ShiftTitle,
Id = p9.ShiftId Id = p13.ShiftId
}, },
Users = p9.Users.Select<ShiftPlanUserSDto, ShiftPlanUser>(p10 => new ShiftPlanUser() ComplexId = p13.ComplexId,
Complex = new Complex() {Id = p13.ComplexId},
SupervisorId = p13.SupervisorId,
Supervisor = new ApplicationUser() {Id = p13.SupervisorId},
Users = p13.Users.Select<ShiftPlanUserSDto, ShiftPlanUser>(p14 => new ShiftPlanUser()
{ {
ShiftPlanId = p10.ShiftPlanId, ShiftPlanId = p14.ShiftPlanId,
ShiftPlan = new ShiftPlan() {Id = p10.ShiftPlanId}, ShiftPlan = new ShiftPlan() {Id = p14.ShiftPlanId},
PositionId = p10.PositionId, PositionId = p14.PositionId,
Position = new Position() Position = new Position()
{ {
Name = p10.PositionName, Name = p14.PositionName,
Id = p10.PositionId Id = p14.PositionId
}, },
UserId = p10.UserId, UserId = p14.UserId,
User = new ApplicationUser() {Id = p10.UserId}, User = new ApplicationUser() {Id = p14.UserId},
Id = p10.Id Id = p14.Id
}).ToList<ShiftPlanUser>(), }).ToList<ShiftPlanUser>(),
Id = p9.Id Id = p13.Id
}; };
public static ShiftPlanSDto AdaptToSDto(this ShiftPlan p11) public static ShiftPlanSDto AdaptToSDto(this ShiftPlan p15)
{ {
return p11 == null ? null : new ShiftPlanSDto() return p15 == null ? null : new ShiftPlanSDto()
{ {
PlanFor = p11.PlanFor, PlanFor = p15.PlanFor,
IsCompleted = p11.IsCompleted, IsCompleted = p15.IsCompleted,
CompletePercent = p11.CompletePercent, CompletePercent = p15.CompletePercent,
SupervisorFullName = p11.Supervisor != null ? p11.Supervisor.FirstName + " " + p11.Supervisor.LastName : string.Empty, SupervisorFullName = p15.Supervisor != null ? p15.Supervisor.FirstName + " " + p15.Supervisor.LastName : string.Empty,
CompleteDescription = p11.CompleteDescription, CompleteDescription = p15.CompleteDescription,
ShiftId = p11.ShiftId, ComplexId = p15.ComplexId,
ShiftTitle = p11.Shift == null ? null : p11.Shift.Title, ShiftId = p15.ShiftId,
StartAt = p11.Shift != null ? p11.Shift.StartAt : TimeSpan.MinValue, ShiftTitle = p15.Shift == null ? null : p15.Shift.Title,
EndAt = p11.Shift != null ? p11.Shift.EndAt : TimeSpan.MinValue, StartAt = p15.Shift != null ? p15.Shift.StartAt : TimeSpan.MinValue,
Users = funcMain4(p11.Users), EndAt = p15.Shift != null ? p15.Shift.EndAt : TimeSpan.MinValue,
Id = p11.Id SupervisorId = p15.SupervisorId,
Users = funcMain6(p15.Users),
Id = p15.Id
}; };
} }
public static ShiftPlanSDto AdaptTo(this ShiftPlan p13, ShiftPlanSDto p14) public static ShiftPlanSDto AdaptTo(this ShiftPlan p17, ShiftPlanSDto p18)
{ {
if (p13 == null) if (p17 == null)
{ {
return null; return null;
} }
ShiftPlanSDto result = p14 ?? new ShiftPlanSDto(); ShiftPlanSDto result = p18 ?? new ShiftPlanSDto();
result.PlanFor = p13.PlanFor; result.PlanFor = p17.PlanFor;
result.IsCompleted = p13.IsCompleted; result.IsCompleted = p17.IsCompleted;
result.CompletePercent = p13.CompletePercent; result.CompletePercent = p17.CompletePercent;
result.SupervisorFullName = p13.Supervisor != null ? p13.Supervisor.FirstName + " " + p13.Supervisor.LastName : string.Empty; result.SupervisorFullName = p17.Supervisor != null ? p17.Supervisor.FirstName + " " + p17.Supervisor.LastName : string.Empty;
result.CompleteDescription = p13.CompleteDescription; result.CompleteDescription = p17.CompleteDescription;
result.ShiftId = p13.ShiftId; result.ComplexId = p17.ComplexId;
result.ShiftTitle = p13.Shift == null ? null : p13.Shift.Title; result.ShiftId = p17.ShiftId;
result.StartAt = p13.Shift != null ? p13.Shift.StartAt : TimeSpan.MinValue; result.ShiftTitle = p17.Shift == null ? null : p17.Shift.Title;
result.EndAt = p13.Shift != null ? p13.Shift.EndAt : TimeSpan.MinValue; result.StartAt = p17.Shift != null ? p17.Shift.StartAt : TimeSpan.MinValue;
result.Users = funcMain5(p13.Users, result.Users); result.EndAt = p17.Shift != null ? p17.Shift.EndAt : TimeSpan.MinValue;
result.Id = p13.Id; result.SupervisorId = p17.SupervisorId;
result.Users = funcMain7(p17.Users, result.Users);
result.Id = p17.Id;
return result; return result;
} }
public static Expression<Func<ShiftPlan, ShiftPlanSDto>> ProjectToSDto => p17 => new ShiftPlanSDto() public static Expression<Func<ShiftPlan, ShiftPlanSDto>> ProjectToSDto => p21 => new ShiftPlanSDto()
{ {
PlanFor = p17.PlanFor, PlanFor = p21.PlanFor,
IsCompleted = p17.IsCompleted, IsCompleted = p21.IsCompleted,
CompletePercent = p17.CompletePercent, CompletePercent = p21.CompletePercent,
SupervisorFullName = p17.Supervisor != null ? p17.Supervisor.FirstName + " " + p17.Supervisor.LastName : string.Empty, SupervisorFullName = p21.Supervisor != null ? p21.Supervisor.FirstName + " " + p21.Supervisor.LastName : string.Empty,
CompleteDescription = p17.CompleteDescription, CompleteDescription = p21.CompleteDescription,
ShiftId = p17.ShiftId, ComplexId = p21.ComplexId,
ShiftTitle = p17.Shift.Title, ShiftId = p21.ShiftId,
StartAt = p17.Shift != null ? p17.Shift.StartAt : TimeSpan.MinValue, ShiftTitle = p21.Shift.Title,
EndAt = p17.Shift != null ? p17.Shift.EndAt : TimeSpan.MinValue, StartAt = p21.Shift != null ? p21.Shift.StartAt : TimeSpan.MinValue,
Users = p17.Users.Select<ShiftPlanUser, ShiftPlanUserSDto>(p18 => new ShiftPlanUserSDto() EndAt = p21.Shift != null ? p21.Shift.EndAt : TimeSpan.MinValue,
SupervisorId = p21.SupervisorId,
Users = p21.Users.Select<ShiftPlanUser, ShiftPlanUserSDto>(p22 => new ShiftPlanUserSDto()
{ {
ShiftPlanId = p18.ShiftPlanId, ShiftPlanId = p22.ShiftPlanId,
UserId = p18.UserId, UserId = p22.UserId,
UserFullName = p18.User != null ? p18.User.FirstName + " " + p18.User.LastName : string.Empty, UserFullName = p22.User != null ? p22.User.FirstName + " " + p22.User.LastName : string.Empty,
PositionId = p18.PositionId, PositionId = p22.PositionId,
PositionName = p18.Position != null ? p18.Position.Name : string.Empty, PositionName = p22.Position != null ? p22.Position.Name : string.Empty,
Id = p18.Id Id = p22.Id
}).ToList<ShiftPlanUserSDto>(), }).ToList<ShiftPlanUserSDto>(),
Id = p17.Id Id = p21.Id
}; };
public static ShiftPlan AdaptToShiftPlan(this ShiftPlanLDto p19) public static ShiftPlan AdaptToShiftPlan(this ShiftPlanLDto p23)
{ {
return p19 == null ? null : new ShiftPlan() return p23 == null ? null : new ShiftPlan()
{ {
PlanFor = p19.PlanFor, PlanFor = p23.PlanFor,
IsCompleted = p19.IsCompleted, IsCompleted = p23.IsCompleted,
CompletePercent = p19.CompletePercent, CompletePercent = p23.CompletePercent,
CompleteDescription = p19.CompleteDescription, CompleteDescription = p23.CompleteDescription,
ShiftId = p19.ShiftId, ShiftId = p23.ShiftId,
Shift = new Shift() {Id = p19.ShiftId}, Shift = new Shift() {Id = p23.ShiftId},
RoutineId = p19.RoutineId, RoutineId = p23.RoutineId,
Routine = new Routine() {Id = p19.RoutineId}, Routine = new Routine() {Id = p23.RoutineId},
SupervisorId = p19.SupervisorId, SupervisorId = p23.SupervisorId,
Supervisor = new ApplicationUser() {Id = p19.SupervisorId}, Supervisor = new ApplicationUser() {Id = p23.SupervisorId},
Users = funcMain6(p19.Users), Users = funcMain8(p23.Users),
Id = p19.Id Id = p23.Id
}; };
} }
public static ShiftPlan AdaptTo(this ShiftPlanLDto p21, ShiftPlan p22) public static ShiftPlan AdaptTo(this ShiftPlanLDto p25, ShiftPlan p26)
{ {
if (p21 == null) if (p25 == null)
{ {
return null; return null;
} }
ShiftPlan result = p22 ?? new ShiftPlan(); ShiftPlan result = p26 ?? new ShiftPlan();
result.PlanFor = p21.PlanFor; result.PlanFor = p25.PlanFor;
result.IsCompleted = p21.IsCompleted; result.IsCompleted = p25.IsCompleted;
result.CompletePercent = p21.CompletePercent; result.CompletePercent = p25.CompletePercent;
result.CompleteDescription = p21.CompleteDescription; result.CompleteDescription = p25.CompleteDescription;
result.ShiftId = p21.ShiftId; result.ShiftId = p25.ShiftId;
result.Shift = funcMain7(new Never(), result.Shift, p21); result.Shift = funcMain9(new Never(), result.Shift, p25);
result.RoutineId = p21.RoutineId; result.RoutineId = p25.RoutineId;
result.Routine = funcMain8(new Never(), result.Routine, p21); result.Routine = funcMain10(new Never(), result.Routine, p25);
result.SupervisorId = p21.SupervisorId; result.SupervisorId = p25.SupervisorId;
result.Supervisor = funcMain9(new Never(), result.Supervisor, p21); result.Supervisor = funcMain11(new Never(), result.Supervisor, p25);
result.Users = funcMain10(p21.Users, result.Users); result.Users = funcMain12(p25.Users, result.Users);
result.Id = p21.Id; result.Id = p25.Id;
return result; return result;
} }
public static ShiftPlanLDto AdaptToLDto(this ShiftPlan p31) public static ShiftPlanLDto AdaptToLDto(this ShiftPlan p35)
{ {
return p31 == null ? null : new ShiftPlanLDto() return p35 == null ? null : new ShiftPlanLDto()
{ {
PlanFor = p31.PlanFor, PlanFor = p35.PlanFor,
RoutineId = p31.RoutineId, RoutineId = p35.RoutineId,
IsCompleted = p31.IsCompleted, IsCompleted = p35.IsCompleted,
CompletePercent = p31.CompletePercent, CompletePercent = p35.CompletePercent,
CompleteDescription = p31.CompleteDescription, CompleteDescription = p35.CompleteDescription,
ShiftId = p31.ShiftId, ShiftId = p35.ShiftId,
Users = funcMain11(p31.Users), Users = funcMain13(p35.Users),
SupervisorId = p31.SupervisorId, SupervisorId = p35.SupervisorId,
SupervisorFullName = p31.Supervisor != null ? p31.Supervisor.FirstName + " " + p31.Supervisor.LastName : string.Empty, SupervisorFullName = p35.Supervisor != null ? p35.Supervisor.FirstName + " " + p35.Supervisor.LastName : string.Empty,
Id = p31.Id Id = p35.Id
}; };
} }
public static ShiftPlanLDto AdaptTo(this ShiftPlan p33, ShiftPlanLDto p34) public static ShiftPlanLDto AdaptTo(this ShiftPlan p37, ShiftPlanLDto p38)
{ {
if (p33 == null) if (p37 == null)
{ {
return null; return null;
} }
ShiftPlanLDto result = p34 ?? new ShiftPlanLDto(); ShiftPlanLDto result = p38 ?? new ShiftPlanLDto();
result.PlanFor = p33.PlanFor; result.PlanFor = p37.PlanFor;
result.RoutineId = p33.RoutineId; result.RoutineId = p37.RoutineId;
result.IsCompleted = p33.IsCompleted; result.IsCompleted = p37.IsCompleted;
result.CompletePercent = p33.CompletePercent; result.CompletePercent = p37.CompletePercent;
result.CompleteDescription = p33.CompleteDescription; result.CompleteDescription = p37.CompleteDescription;
result.ShiftId = p33.ShiftId; result.ShiftId = p37.ShiftId;
result.Users = funcMain12(p33.Users, result.Users); result.Users = funcMain14(p37.Users, result.Users);
result.SupervisorId = p33.SupervisorId; result.SupervisorId = p37.SupervisorId;
result.SupervisorFullName = p33.Supervisor != null ? p33.Supervisor.FirstName + " " + p33.Supervisor.LastName : string.Empty; result.SupervisorFullName = p37.Supervisor != null ? p37.Supervisor.FirstName + " " + p37.Supervisor.LastName : string.Empty;
result.Id = p33.Id; result.Id = p37.Id;
return result; return result;
} }
public static Expression<Func<ShiftPlan, ShiftPlanLDto>> ProjectToLDto => p37 => new ShiftPlanLDto() public static Expression<Func<ShiftPlan, ShiftPlanLDto>> ProjectToLDto => p41 => new ShiftPlanLDto()
{ {
PlanFor = p37.PlanFor, PlanFor = p41.PlanFor,
RoutineId = p37.RoutineId, RoutineId = p41.RoutineId,
IsCompleted = p37.IsCompleted, IsCompleted = p41.IsCompleted,
CompletePercent = p37.CompletePercent, CompletePercent = p41.CompletePercent,
CompleteDescription = p37.CompleteDescription, CompleteDescription = p41.CompleteDescription,
ShiftId = p37.ShiftId, ShiftId = p41.ShiftId,
Users = p37.Users.Select<ShiftPlanUser, ShiftPlanUserSDto>(p38 => new ShiftPlanUserSDto() Users = p41.Users.Select<ShiftPlanUser, ShiftPlanUserSDto>(p42 => new ShiftPlanUserSDto()
{ {
ShiftPlanId = p38.ShiftPlanId, ShiftPlanId = p42.ShiftPlanId,
UserId = p38.UserId, UserId = p42.UserId,
UserFullName = p38.User != null ? p38.User.FirstName + " " + p38.User.LastName : string.Empty, UserFullName = p42.User != null ? p42.User.FirstName + " " + p42.User.LastName : string.Empty,
PositionId = p38.PositionId, PositionId = p42.PositionId,
PositionName = p38.Position != null ? p38.Position.Name : string.Empty, PositionName = p42.Position != null ? p42.Position.Name : string.Empty,
Id = p38.Id Id = p42.Id
}).ToList<ShiftPlanUserSDto>(), }).ToList<ShiftPlanUserSDto>(),
SupervisorId = p37.SupervisorId, SupervisorId = p41.SupervisorId,
SupervisorFullName = p37.Supervisor != null ? p37.Supervisor.FirstName + " " + p37.Supervisor.LastName : string.Empty, SupervisorFullName = p41.Supervisor != null ? p41.Supervisor.FirstName + " " + p41.Supervisor.LastName : string.Empty,
Id = p37.Id Id = p41.Id
}; };
private static List<ShiftPlanUser> funcMain1(List<ShiftPlanUserSDto> p2) private static List<ShiftPlanUser> funcMain1(List<ShiftPlanUserSDto> p2)
@ -285,20 +303,38 @@ namespace Brizco.Domain.Mappers
} }
private static List<ShiftPlanUser> funcMain3(List<ShiftPlanUserSDto> p7, List<ShiftPlanUser> p8) private static Complex funcMain3(Never p7, Complex p8, ShiftPlanSDto p3)
{ {
if (p7 == null) Complex result = p8 ?? new Complex();
result.Id = p3.ComplexId;
return result;
}
private static ApplicationUser funcMain4(Never p9, ApplicationUser p10, ShiftPlanSDto p3)
{
ApplicationUser result = p10 ?? new ApplicationUser();
result.Id = p3.SupervisorId;
return result;
}
private static List<ShiftPlanUser> funcMain5(List<ShiftPlanUserSDto> p11, List<ShiftPlanUser> p12)
{
if (p11 == null)
{ {
return null; return null;
} }
List<ShiftPlanUser> result = new List<ShiftPlanUser>(p7.Count); List<ShiftPlanUser> result = new List<ShiftPlanUser>(p11.Count);
int i = 0; int i = 0;
int len = p7.Count; int len = p11.Count;
while (i < len) while (i < len)
{ {
ShiftPlanUserSDto item = p7[i]; ShiftPlanUserSDto item = p11[i];
result.Add(item == null ? null : new ShiftPlanUser() result.Add(item == null ? null : new ShiftPlanUser()
{ {
ShiftPlanId = item.ShiftPlanId, ShiftPlanId = item.ShiftPlanId,
@ -319,20 +355,20 @@ namespace Brizco.Domain.Mappers
} }
private static List<ShiftPlanUserSDto> funcMain4(List<ShiftPlanUser> p12) private static List<ShiftPlanUserSDto> funcMain6(List<ShiftPlanUser> p16)
{ {
if (p12 == null) if (p16 == null)
{ {
return null; return null;
} }
List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p12.Count); List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p16.Count);
int i = 0; int i = 0;
int len = p12.Count; int len = p16.Count;
while (i < len) while (i < len)
{ {
ShiftPlanUser item = p12[i]; ShiftPlanUser item = p16[i];
result.Add(item == null ? null : new ShiftPlanUserSDto() result.Add(item == null ? null : new ShiftPlanUserSDto()
{ {
ShiftPlanId = item.ShiftPlanId, ShiftPlanId = item.ShiftPlanId,
@ -348,20 +384,20 @@ namespace Brizco.Domain.Mappers
} }
private static List<ShiftPlanUserSDto> funcMain5(List<ShiftPlanUser> p15, List<ShiftPlanUserSDto> p16) private static List<ShiftPlanUserSDto> funcMain7(List<ShiftPlanUser> p19, List<ShiftPlanUserSDto> p20)
{ {
if (p15 == null) if (p19 == null)
{ {
return null; return null;
} }
List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p15.Count); List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p19.Count);
int i = 0; int i = 0;
int len = p15.Count; int len = p19.Count;
while (i < len) while (i < len)
{ {
ShiftPlanUser item = p15[i]; ShiftPlanUser item = p19[i];
result.Add(item == null ? null : new ShiftPlanUserSDto() result.Add(item == null ? null : new ShiftPlanUserSDto()
{ {
ShiftPlanId = item.ShiftPlanId, ShiftPlanId = item.ShiftPlanId,
@ -377,20 +413,20 @@ namespace Brizco.Domain.Mappers
} }
private static List<ShiftPlanUser> funcMain6(List<ShiftPlanUserSDto> p20) private static List<ShiftPlanUser> funcMain8(List<ShiftPlanUserSDto> p24)
{ {
if (p20 == null) if (p24 == null)
{ {
return null; return null;
} }
List<ShiftPlanUser> result = new List<ShiftPlanUser>(p20.Count); List<ShiftPlanUser> result = new List<ShiftPlanUser>(p24.Count);
int i = 0; int i = 0;
int len = p20.Count; int len = p24.Count;
while (i < len) while (i < len)
{ {
ShiftPlanUserSDto item = p20[i]; ShiftPlanUserSDto item = p24[i];
result.Add(item == null ? null : new ShiftPlanUser() result.Add(item == null ? null : new ShiftPlanUser()
{ {
ShiftPlanId = item.ShiftPlanId, ShiftPlanId = item.ShiftPlanId,
@ -411,47 +447,47 @@ namespace Brizco.Domain.Mappers
} }
private static Shift funcMain7(Never p23, Shift p24, ShiftPlanLDto p21) private static Shift funcMain9(Never p27, Shift p28, ShiftPlanLDto p25)
{ {
Shift result = p24 ?? new Shift(); Shift result = p28 ?? new Shift();
result.Id = p21.ShiftId; result.Id = p25.ShiftId;
return result; return result;
} }
private static Routine funcMain8(Never p25, Routine p26, ShiftPlanLDto p21) private static Routine funcMain10(Never p29, Routine p30, ShiftPlanLDto p25)
{ {
Routine result = p26 ?? new Routine(); Routine result = p30 ?? new Routine();
result.Id = p21.RoutineId; result.Id = p25.RoutineId;
return result; return result;
} }
private static ApplicationUser funcMain9(Never p27, ApplicationUser p28, ShiftPlanLDto p21) private static ApplicationUser funcMain11(Never p31, ApplicationUser p32, ShiftPlanLDto p25)
{ {
ApplicationUser result = p28 ?? new ApplicationUser(); ApplicationUser result = p32 ?? new ApplicationUser();
result.Id = p21.SupervisorId; result.Id = p25.SupervisorId;
return result; return result;
} }
private static List<ShiftPlanUser> funcMain10(List<ShiftPlanUserSDto> p29, List<ShiftPlanUser> p30) private static List<ShiftPlanUser> funcMain12(List<ShiftPlanUserSDto> p33, List<ShiftPlanUser> p34)
{ {
if (p29 == null) if (p33 == null)
{ {
return null; return null;
} }
List<ShiftPlanUser> result = new List<ShiftPlanUser>(p29.Count); List<ShiftPlanUser> result = new List<ShiftPlanUser>(p33.Count);
int i = 0; int i = 0;
int len = p29.Count; int len = p33.Count;
while (i < len) while (i < len)
{ {
ShiftPlanUserSDto item = p29[i]; ShiftPlanUserSDto item = p33[i];
result.Add(item == null ? null : new ShiftPlanUser() result.Add(item == null ? null : new ShiftPlanUser()
{ {
ShiftPlanId = item.ShiftPlanId, ShiftPlanId = item.ShiftPlanId,
@ -472,20 +508,20 @@ namespace Brizco.Domain.Mappers
} }
private static List<ShiftPlanUserSDto> funcMain11(List<ShiftPlanUser> p32) private static List<ShiftPlanUserSDto> funcMain13(List<ShiftPlanUser> p36)
{ {
if (p32 == null) if (p36 == null)
{ {
return null; return null;
} }
List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p32.Count); List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p36.Count);
int i = 0; int i = 0;
int len = p32.Count; int len = p36.Count;
while (i < len) while (i < len)
{ {
ShiftPlanUser item = p32[i]; ShiftPlanUser item = p36[i];
result.Add(item == null ? null : new ShiftPlanUserSDto() result.Add(item == null ? null : new ShiftPlanUserSDto()
{ {
ShiftPlanId = item.ShiftPlanId, ShiftPlanId = item.ShiftPlanId,
@ -501,20 +537,20 @@ namespace Brizco.Domain.Mappers
} }
private static List<ShiftPlanUserSDto> funcMain12(List<ShiftPlanUser> p35, List<ShiftPlanUserSDto> p36) private static List<ShiftPlanUserSDto> funcMain14(List<ShiftPlanUser> p39, List<ShiftPlanUserSDto> p40)
{ {
if (p35 == null) if (p39 == null)
{ {
return null; return null;
} }
List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p35.Count); List<ShiftPlanUserSDto> result = new List<ShiftPlanUserSDto>(p39.Count);
int i = 0; int i = 0;
int len = p35.Count; int len = p39.Count;
while (i < len) while (i < len)
{ {
ShiftPlanUser item = p35[i]; ShiftPlanUser item = p39[i];
result.Add(item == null ? null : new ShiftPlanUserSDto() result.Add(item == null ? null : new ShiftPlanUserSDto()
{ {
ShiftPlanId = item.ShiftPlanId, ShiftPlanId = item.ShiftPlanId,

View File

@ -0,0 +1,9 @@
namespace Brizco.Domain.MartenEntities.NewFeeds;
public class NewsFeed : MartenEntity
{
public string Content { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public bool IsPin { get; set; }
public DateTime CreatedAt { get; set; }
}

View File

@ -36,7 +36,7 @@ public class MartenRepository<TMartenEntity> : IMartenRepository<TMartenEntity>
await using var session = _documentStore.QuerySession(); await using var session = _documentStore.QuerySession();
var setting = await session.LoadAsync<TMartenEntity>(id, cancellation); var setting = await session.LoadAsync<TMartenEntity>(id, cancellation);
if (setting == null) if (setting == null)
throw new AppException($"{nameof(setting)} not found", ApiResultStatusCode.NotFound); throw new AppException($"{nameof(TMartenEntity)} not found", ApiResultStatusCode.NotFound);
return setting; return setting;
} }

View File

@ -27,7 +27,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="MartenHandlers\Notifications\" /> <Folder Include="Handlers\Users\" />
<Folder Include="Models\" /> <Folder Include="Models\" />
<Folder Include="Extensions\" /> <Folder Include="Extensions\" />
<Folder Include="Services\Contracts\" /> <Folder Include="Services\Contracts\" />
@ -50,6 +50,7 @@
<Using Include="Brizco.Domain.Entities.ShiftPlans" /> <Using Include="Brizco.Domain.Entities.ShiftPlans" />
<Using Include="Brizco.Domain.Entities.Shifts" /> <Using Include="Brizco.Domain.Entities.Shifts" />
<Using Include="Brizco.Domain.Entities.Users" /> <Using Include="Brizco.Domain.Entities.Users" />
<Using Include="Brizco.Domain.MartenEntities.NewFeeds" />
<Using Include="Brizco.Domain.MartenEntities.Notifications" /> <Using Include="Brizco.Domain.MartenEntities.Notifications" />
<Using Include="Brizco.Repository.Abstracts" /> <Using Include="Brizco.Repository.Abstracts" />
<Using Include="Brizco.Repository.Extensions" /> <Using Include="Brizco.Repository.Extensions" />

View File

@ -1,51 +1,52 @@
namespace Brizco.Repository.Handlers.Activities; namespace Brizco.Repository.Handlers.Activities;
public class GetActivitiesQueryHandler : IRequestHandler<GetActivitiesQuery, List<ActivitySDto>> public class GetActivitiesQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<GetActivitiesQuery, List<ActivitySDto>>
{ {
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ICurrentUserService _currentUserService;
public GetActivitiesQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
{
_repositoryWrapper = repositoryWrapper;
_currentUserService = currentUserService;
}
public async Task<List<ActivitySDto>> Handle(GetActivitiesQuery request, CancellationToken cancellationToken) public async Task<List<ActivitySDto>> Handle(GetActivitiesQuery request, CancellationToken cancellationToken)
{ {
if (_currentUserService.ComplexId == null) if (currentUserService.ComplexId == null)
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
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);
if (_currentUserService.UserId == null) if (currentUserService.UserId == null)
throw new AppException("UserId is null", ApiResultStatusCode.NotFound); throw new AppException("UserId is null", ApiResultStatusCode.NotFound);
if (!Guid.TryParse(_currentUserService.UserId, out Guid userId)) if (!Guid.TryParse(currentUserService.UserId, out Guid userId))
throw new AppException("UserId is wrong", ApiResultStatusCode.NotFound); throw new AppException("UserId is wrong", ApiResultStatusCode.NotFound);
IQueryable<Domain.Entities.Tasks.Activity> activities = _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>().TableNoTracking IQueryable<Domain.Entities.Tasks.Activity> activities = repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>().TableNoTracking
.Where(a=>a.IsActivity && a.ComplexId == complexId); .Where(a=>a.IsActivity && a.ComplexId == complexId);
if (_currentUserService is { Permissions: not null, RoleName: not null }) if (currentUserService is { Permissions: not null, RoleName: not null })
{ {
if (_currentUserService.Permissions.Contains(ApplicationPermission.ViewMineActivities) && _currentUserService.RoleName == ApplicationRoles.Staff) if (currentUserService.Permissions.Contains(ApplicationPermission.ViewMineActivities) && currentUserService.RoleName == ApplicationRoles.Staff)
activities = activities.Where(a => a.UserId == userId); activities = activities.Where(a => a.UserId == userId);
else
activities = activities.Where(c => c.UserId == request.UserId);
} }
if (request.DateQueryFilter != null) if (request.DateQueryFilter != null)
{ {
var date = DateTime.Now;
switch (request.DateQueryFilter) switch (request.DateQueryFilter)
{ {
case DateQueryFilter.Yesterday: case DateTimeQueryFilter.Yesterday:
activities = activities.Where(a => a.SetFor.Date == DateTime.Today.Date.AddDays(-1).Date); activities = activities.Where(a => a.SetFor.Date == DateTime.Today.Date.AddDays(-1).Date);
break; break;
case DateQueryFilter.Today: case DateTimeQueryFilter.Today:
activities = activities.Where(a => a.SetFor.Date == DateTime.Today.Date); activities = activities.Where(a => a.SetFor.Date == DateTime.Today.Date);
break; break;
case DateQueryFilter.Tomorrow: case DateTimeQueryFilter.Tomorrow:
activities = activities.Where(a => a.SetFor.Date == DateTime.Today.AddDays(1).Date); activities = activities.Where(a => a.SetFor.Date == DateTime.Today.AddDays(1).Date);
break; break;
case DateQueryFilter.ThisWeek: case DateTimeQueryFilter.ThisWeek:
activities = activities.Where(a => a.SetFor.Date >= DateTime.Today.AddDays(-1).Date && a.SetFor.Date <= DateTime.Today.AddDays(+6).Date); DateTime today = DateTime.Today;
int delta = DayOfWeek.Saturday - today.DayOfWeek;
if (delta > 0) delta -= 7;
DateTime startOfWeek = today.AddDays(delta);
DateTime endOfWeek = startOfWeek.AddDays(6);
activities = activities.Where(a => a.SetFor.Date >= startOfWeek.Date && a.SetFor.Date <= endOfWeek.Date);
break; break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();

View File

@ -1,16 +1,10 @@
namespace Brizco.Repository.Handlers.Activities; namespace Brizco.Repository.Handlers.Activities;
public class GetShiftPlanActivitiesQueryHandler : IRequestHandler<GetShiftPlanActivitiesQuery, List<ActivitySDto>> public class GetShiftPlanActivitiesQueryHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler<GetShiftPlanActivitiesQuery, List<ActivitySDto>>
{ {
private IRepositoryWrapper _repositoryWrapper;
public GetShiftPlanActivitiesQueryHandler(IRepositoryWrapper repositoryWrapper)
{
_repositoryWrapper = repositoryWrapper;
}
public async Task<List<ActivitySDto>> Handle(GetShiftPlanActivitiesQuery request, CancellationToken cancellationToken) public async Task<List<ActivitySDto>> Handle(GetShiftPlanActivitiesQuery request, CancellationToken cancellationToken)
{ {
var activities = await _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>() var activities = await repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>()
.TableNoTracking .TableNoTracking
.Where(a => a.ShiftPlanId == request.ShiftPlanId) .Where(a => a.ShiftPlanId == request.ShiftPlanId)
.Select(ActivityMapper.ProjectToSDto) .Select(ActivityMapper.ProjectToSDto)

View File

@ -2,24 +2,16 @@
namespace Brizco.Repository.Handlers.ShiftPlans; namespace Brizco.Repository.Handlers.ShiftPlans;
public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, List<ShiftPlanSDto>> public class GetShiftPlansQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler<GetShiftPlansQuery, List<ShiftPlanSDto>>
{ {
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ICurrentUserService _currentUserService;
public GetShiftPlansQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
{
_repositoryWrapper = repositoryWrapper;
_currentUserService = currentUserService;
}
public async Task<List<ShiftPlanSDto>> Handle(GetShiftPlansQuery request, CancellationToken cancellationToken) public async Task<List<ShiftPlanSDto>> Handle(GetShiftPlansQuery request, CancellationToken cancellationToken)
{ {
if (_currentUserService.ComplexId == null) if (currentUserService.ComplexId == null)
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
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<ShiftPlan> baseQuery = _repositoryWrapper.SetRepository<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);
@ -77,7 +69,7 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, Lis
break; break;
case DateTimeQueryFilter.NextWeek: case DateTimeQueryFilter.NextWeek:
DateTime startOfNextWeek = DateTime.Today.AddDays(7 - (int)DateTime.Today.DayOfWeek + 1); DateTime startOfNextWeek = DateTime.Today.AddDays(7 - (int)DateTime.Today.DayOfWeek + 1);
DateTime endOfNextWeek = startOfNextWeek.AddDays(5); DateTime endOfNextWeek = startOfNextWeek.AddDays(6);
shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= startOfNextWeek.Date && s.PlanFor.Date <= endOfNextWeek.Date) shiftPlans = await baseQuery.Where(s => s.PlanFor.Date >= startOfNextWeek.Date && s.PlanFor.Date <= endOfNextWeek.Date)
.OrderByDescending(s => s.CreatedAt) .OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15) .Skip(request.Page * 15).Take(15)
@ -138,13 +130,13 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, Lis
foreach (var shiftPlan in shiftPlans) foreach (var shiftPlan in shiftPlans)
{ {
var activitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>() var activitiesCount = await repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>()
.TableNoTracking .TableNoTracking
.CountAsync(a => a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftPlanId == shiftPlan.Id, cancellationToken); .CountAsync(a => a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftPlanId == shiftPlan.Id, cancellationToken);
var doneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>() var doneActivitiesCount = await repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>()
.TableNoTracking .TableNoTracking
.CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftPlanId == shiftPlan.Id, cancellationToken); .CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftPlanId == shiftPlan.Id, cancellationToken);
var undoneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>() var undoneActivitiesCount = await repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>()
.TableNoTracking .TableNoTracking
.CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftPlanId == shiftPlan.Id, cancellationToken); .CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == shiftPlan.PlanFor.Date && a.ShiftPlanId == shiftPlan.Id, cancellationToken);
shiftPlan.UndoneActivitiesCount = undoneActivitiesCount; shiftPlan.UndoneActivitiesCount = undoneActivitiesCount;
@ -155,7 +147,7 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftPlansQuery, Lis
foreach (var shiftPlan in shiftPlans) foreach (var shiftPlan in shiftPlans)
{ {
shiftPlan.StaffCount = await _repositoryWrapper.SetRepository<ShiftPlanUser>() shiftPlan.StaffCount = await repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking .TableNoTracking
.CountAsync(spu => spu.ShiftPlanId == shiftPlan.Id, cancellationToken); .CountAsync(spu => spu.ShiftPlanId == shiftPlan.Id, cancellationToken);

View File

@ -1,22 +1,13 @@
namespace Brizco.Repository.Handlers.Shifts; namespace Brizco.Repository.Handlers.Shifts;
public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<ShiftSDto>> public class GetShiftPlansQueryHandler(IRepositoryWrapper repositoryWrapper, UserManager<ApplicationUser> userManager, ICurrentUserService currentUserService)
: IRequestHandler<GetShiftsQuery, List<ShiftSDto>>
{ {
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly UserManager<ApplicationUser> _userManager;
private readonly ICurrentUserService _currentUserService;
public GetShiftPlansQueryHandler(IRepositoryWrapper repositoryWrapper,UserManager<ApplicationUser> userManager, ICurrentUserService currentUserService)
{
_repositoryWrapper = repositoryWrapper;
_userManager = userManager;
_currentUserService = currentUserService;
}
public async Task<List<ShiftSDto>> Handle(GetShiftsQuery request, CancellationToken cancellationToken) public async Task<List<ShiftSDto>> Handle(GetShiftsQuery request, CancellationToken cancellationToken)
{ {
if (_currentUserService.ComplexId == null) if (currentUserService.ComplexId == null)
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound); throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
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);
List<ShiftSDto> shifts; List<ShiftSDto> shifts;
@ -24,46 +15,46 @@ 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<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 orderby shift.StartAt
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<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)
continue; continue;
var supervisor = await _userManager.FindByIdAsync(existedShiftPlan.SupervisorId.ToString()); var supervisor = await userManager.FindByIdAsync(existedShiftPlan.SupervisorId.ToString());
if (supervisor != null) if (supervisor != null)
shift.CurrentSupervisorFullName = supervisor.FirstName + " " + supervisor.LastName; shift.CurrentSupervisorFullName = supervisor.FirstName + " " + supervisor.LastName;
var activitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>() var activitiesCount = await repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>()
.TableNoTracking .TableNoTracking
.CountAsync(a => a.SetFor.Date == selectedDate.Date && a.ShiftPlanId == existedShiftPlan.Id, cancellationToken); .CountAsync(a => a.SetFor.Date == selectedDate.Date && a.ShiftPlanId == existedShiftPlan.Id, cancellationToken);
var doneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>() var doneActivitiesCount = await repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>()
.TableNoTracking .TableNoTracking
.CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == selectedDate.Date && a.ShiftPlanId == existedShiftPlan.Id, cancellationToken); .CountAsync(a => a.Status == ActivityStatus.Done && a.SetFor.Date == selectedDate.Date && a.ShiftPlanId == existedShiftPlan.Id, cancellationToken);
var undoneActivitiesCount = await _repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>() var undoneActivitiesCount = await repositoryWrapper.SetRepository<Domain.Entities.Tasks.Activity>()
.TableNoTracking .TableNoTracking
.CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == selectedDate.Date && a.ShiftPlanId == existedShiftPlan.Id, cancellationToken); .CountAsync(a => a.Status == ActivityStatus.UnDone && a.SetFor.Date == selectedDate.Date && a.ShiftPlanId == existedShiftPlan.Id, cancellationToken);
shift.UndoneActivitiesCount = undoneActivitiesCount; shift.UndoneActivitiesCount = undoneActivitiesCount;
shift.DoneActivitiesCount = doneActivitiesCount; shift.DoneActivitiesCount = doneActivitiesCount;
shift.TotalActivitiesCount = activitiesCount; shift.TotalActivitiesCount = activitiesCount;
switch (_currentUserService.RoleName) switch (currentUserService.RoleName)
{ {
case null: case null:
continue; continue;
case ApplicationRoles.SuperVisor: case ApplicationRoles.SuperVisor:
{ {
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<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;
@ -84,9 +75,9 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<Sh
else else
{ {
shifts = await _repositoryWrapper.SetRepository<Shift>().TableNoTracking shifts = await repositoryWrapper.SetRepository<Shift>().TableNoTracking
.Where(s => s.ComplexId == complexId) .Where(s => s.ComplexId == complexId)
.OrderByDescending(s => s.StartAt) .OrderBy(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

@ -0,0 +1,106 @@
using MD.PersianDateTime.Standard;
using Activity = Brizco.Domain.Entities.Tasks.Activity;
namespace Brizco.Repository.Handlers.Users;
public class GetStaffQueryHandler(IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService) : IRequestHandler<GetStaffQuery,List<StaffResponseSDto>>
{
public async Task<List<StaffResponseSDto>> Handle(GetStaffQuery request, CancellationToken cancellationToken)
{
var count = request.Count ?? 10;
if (currentUserService.ComplexId == null)
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
var baseQuery = repositoryWrapper.SetRepository<Activity>()
.TableNoTracking
.OrderByDescending(s => s.CreatedAt)
.Where(s => s.ComplexId == complexId);
List<ActivitySDto> activities = new List<ActivitySDto>();
switch (request.DateTimeQuery)
{
case DateTimeQueryFilter.Today:
activities = await baseQuery.Where(s => s.SetFor.Date == DateTime.Now.Date)
.Skip(request.Page * count).Take(count)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.Yesterday:
activities = await baseQuery.Where(s => s.SetFor.Date == DateTime.Now.AddDays(-1).Date)
.Skip(request.Page * count).Take(count)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.PastWeek:
DateTime pastWeekToday = DateTime.Today;
int pastWeekDelta = DayOfWeek.Saturday - pastWeekToday.DayOfWeek;
if (pastWeekDelta > 0) pastWeekDelta -= 7;
DateTime startOfPastWeek = DateTime.Today.AddDays(pastWeekDelta).AddDays(-7);
DateTime endOfPastWeek = startOfPastWeek.AddDays(6);
activities = await baseQuery.Where(s => s.SetFor.Date >= startOfPastWeek.Date && s.SetFor.Date <= endOfPastWeek.Date)
.OrderByDescending(s => s.CreatedAt)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.NextWeek:
DateTime startOfNextWeek = DateTime.Today.AddDays(7 - (int)DateTime.Today.DayOfWeek + 1);
DateTime endOfNextWeek = startOfNextWeek.AddDays(6);
activities = await baseQuery.Where(s => s.SetFor.Date >= startOfNextWeek.Date && s.SetFor.Date <= endOfNextWeek.Date)
.OrderByDescending(s => s.CreatedAt)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.ThisWeek:
DateTime today = DateTime.Today;
int delta = DayOfWeek.Saturday - today.DayOfWeek;
if (delta > 0) delta -= 7;
DateTime startOfWeek = today.AddDays(delta);
DateTime endOfWeek = startOfWeek.AddDays(6);
activities = await baseQuery.Where(s => s.SetFor.Date >= startOfWeek.Date && s.SetFor.Date <= endOfWeek.Date)
.OrderByDescending(s => s.CreatedAt)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.PastMonth:
DateTime startOfPastMonth = new PersianDateTime(PersianDateTime.Today.AddMonths(-1).Year, PersianDateTime.Today.AddMonths(-1).Month, 1).ToDateTime();
DateTime endOfPastMonth = startOfPastMonth.AddMonths(1);
activities = await baseQuery.Where(s => s.SetFor.Date >= startOfPastMonth.Date && s.SetFor.Date < endOfPastMonth.Date)
.OrderByDescending(s => s.CreatedAt)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.NextMonth:
DateTime startOfNextMonth = new PersianDateTime(PersianDateTime.Today.AddMonths(1).Year, PersianDateTime.Today.AddMonths(1).Month, 1).ToDateTime();
DateTime endOfNextMonth = startOfNextMonth.AddMonths(1);
activities = await baseQuery.Where(s => s.SetFor.Date >= startOfNextMonth.Date && s.SetFor.Date < endOfNextMonth.Date)
.OrderByDescending(s => s.CreatedAt)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
case DateTimeQueryFilter.ThisMonth:
DateTime startOfThisMonth = new PersianDateTime(PersianDateTime.Today.Year, PersianDateTime.Today.Month, 1).ToDateTime();
DateTime endOfThisMonth = startOfThisMonth.AddMonths(1);
activities = await baseQuery.Where(s => s.SetFor.Date >= startOfThisMonth.Date && s.SetFor.Date < endOfThisMonth.Date)
.OrderByDescending(s => s.CreatedAt)
.Select(ActivityMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
break;
default:
throw new ArgumentOutOfRangeException();
}
var staffs = activities.Select(a => new StaffResponseSDto
{
FirstName = a.UserFirstName,
LastName = a.UserLastName,
Id = a.UserId
}).ToList();
return staffs.DistinctBy(d => d.Id).ToList();
}
}

View File

@ -0,0 +1,20 @@
namespace Brizco.Repository.MartenHandlers.NewsFeeds;
public class ChangeNewsFeedPinCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<ChangeNewsFeedPinCommand, bool>
{
public async Task<bool> Handle(ChangeNewsFeedPinCommand request, CancellationToken cancellationToken)
{
if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
var ent = await martenRepositoryWrapper.SetRepository<NewsFeed>().GetEntityAsync(request.Id, cancellationToken);
if (ent.ComplexId != complexId)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
ent.IsPin = request.IsPin;
await martenRepositoryWrapper.SetRepository<NewsFeed>().AddOrUpdateEntityAsync(ent, cancellationToken);
return true;
}
}

View File

@ -0,0 +1,23 @@
namespace Brizco.Repository.MartenHandlers.NewsFeeds;
public class CreateNewsFeedCommandHandler (IMartenRepositoryWrapper martenRepositoryWrapper , ICurrentUserService currentUserService)
: IRequestHandler<CreateNewsFeedCommand,Guid>
{
public async Task<Guid> Handle(CreateNewsFeedCommand request, CancellationToken cancellationToken)
{
if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
var newsFeed = new NewsFeed
{
ComplexId = complexId,
Content = request.Content,
Title = request.Title,
IsPin = request.IsPin
};
await martenRepositoryWrapper.SetRepository<NewsFeed>().AddOrUpdateEntityAsync(newsFeed, cancellationToken);
return newsFeed.Id;
}
}

View File

@ -0,0 +1,19 @@
namespace Brizco.Repository.MartenHandlers.NewsFeeds;
public class DeleteNewsFeedCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<DeleteNewsFeedCommand, bool>
{
public async Task<bool> Handle(DeleteNewsFeedCommand request, CancellationToken cancellationToken)
{
if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
var ent = await martenRepositoryWrapper.SetRepository<NewsFeed>().GetEntityAsync(request.Id, cancellationToken);
if (ent.ComplexId != complexId)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
await martenRepositoryWrapper.SetRepository<NewsFeed>().RemoveEntityAsync(ent, cancellationToken);
return true;
}
}

View File

@ -0,0 +1,22 @@
namespace Brizco.Repository.MartenHandlers.NewsFeeds;
public class GetNewsFeedsQueryHandler (IMartenRepositoryWrapper martenRepositoryWrapper,ICurrentUserService currentUserService) : IRequestHandler<GetNewsFeedsQuery,List<NewsFeed>>
{
public async Task<List<NewsFeed>> Handle(GetNewsFeedsQuery request, CancellationToken cancellationToken)
{
if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
var count = request.Count ?? 5;
var query = await martenRepositoryWrapper.SetRepository<NewsFeed>()
.GetQueryAsync(q=>q.ComplexId == complexId);
query = query.Skip(request.Page * count)
.Take(count)
.OrderByDescending(c=>c.CreatedAt);
return await query.ToListAsync(cancellationToken);
}
}

View File

@ -1,22 +1,13 @@
using Brizco.Domain.MartenEntities.Notifications; namespace Brizco.Repository.MartenHandlers.Notifications;
namespace Brizco.Repository.MartenHandlers.Notifications; public class CreateNotificationHandlerCommand(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<CreateNotificationCommand,Guid>
public class CreateNotificationHandlerCommand : IRequestHandler<CreateNotificationCommand,Guid>
{ {
private readonly IMartenRepositoryWrapper _martenRepositoryWrapper;
private readonly ICurrentUserService _currentUserService;
public CreateNotificationHandlerCommand(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService)
{
_martenRepositoryWrapper = martenRepositoryWrapper;
_currentUserService = currentUserService;
}
public async Task<Guid> Handle(CreateNotificationCommand request, CancellationToken cancellationToken) public async Task<Guid> Handle(CreateNotificationCommand request, CancellationToken cancellationToken)
{ {
if (_currentUserService.ComplexId == null) if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null"); throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong"); throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
var notification = new Notification var notification = new Notification
{ {
@ -26,7 +17,7 @@ public class CreateNotificationHandlerCommand : IRequestHandler<CreateNotificati
CreatedAt = DateTime.Now CreatedAt = DateTime.Now
}; };
await _martenRepositoryWrapper.SetRepository<Notification>() await martenRepositoryWrapper.SetRepository<Notification>()
.AddOrUpdateEntityAsync(notification, cancellationToken); .AddOrUpdateEntityAsync(notification, cancellationToken);
return notification.Id; return notification.Id;
} }

View File

@ -0,0 +1,25 @@
namespace Brizco.Repository.MartenHandlers.Notifications;
public class GetNotificationsCountQueryHandler(IMartenRepositoryWrapper martenRepositoryWrapper,ICurrentUserService currentUserService) : IRequestHandler<GetNotificationsCountQuery,int>
{
public async Task<int> Handle(GetNotificationsCountQuery request, CancellationToken cancellationToken)
{
if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
Guid userId;
if (currentUserService.UserId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is null");
if (!Guid.TryParse(currentUserService.UserId, out userId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is wrong");
var notifications = await martenRepositoryWrapper.SetRepository<Notification>()
.GetEntitiesAsync(n => n.ComplexId == complexId && n.UserId == userId && !n.IsRead, cancellationToken);
return notifications.Count;
}
}

View File

@ -1,44 +1,37 @@
using Brizco.Domain.MartenEntities.Notifications; namespace Brizco.Repository.MartenHandlers.Notifications;
namespace Brizco.Repository.MartenHandlers.Notifications; public class GetNotificationsQueryHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler<GetNotificationsQuery,List<Notification>>
public class GetNotificationsQueryHandler : IRequestHandler<GetNotificationsQuery,List<Notification>>
{ {
private readonly IMartenRepositoryWrapper _martenRepositoryWrapper;
private readonly ICurrentUserService _currentUserService;
public GetNotificationsQueryHandler(IMartenRepositoryWrapper martenRepositoryWrapper,ICurrentUserService currentUserService)
{
_martenRepositoryWrapper = martenRepositoryWrapper;
_currentUserService = currentUserService;
}
public async Task<List<Notification>> Handle(GetNotificationsQuery request, CancellationToken cancellationToken) public async Task<List<Notification>> Handle(GetNotificationsQuery request, CancellationToken cancellationToken)
{ {
if (_currentUserService.ComplexId == null) if (currentUserService.ComplexId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null"); throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is null");
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong"); throw new BaseApiException(ApiResultStatusCode.BadRequest, "Complex id is wrong");
if (request.UserId == default)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is null");
Guid userId; Guid userId;
if (request.UserId == null) if (request.UserId == null)
{ {
if (_currentUserService.UserId == null) if (currentUserService.UserId == null)
throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is null"); throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is null");
if (!Guid.TryParse(_currentUserService.UserId, out userId)) if (!Guid.TryParse(currentUserService.UserId, out userId))
throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is wrong"); throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is wrong");
} }
else else
userId = request.UserId.Value; userId = request.UserId.Value;
var notifications = await _martenRepositoryWrapper.SetRepository<Notification>() if (userId == default)
.GetQueryAsync(n => n.ComplexId == complexId && n.UserId == userId); throw new BaseApiException(ApiResultStatusCode.BadRequest, "User id is null");
var response = await notifications.Take(new Range(request.Page * request.Count, (request.Page * request.Count) + request.Count))
.ToListAsync(cancellationToken);
var count = request.Count ?? 10;
var notifications = await martenRepositoryWrapper.SetRepository<Notification>()
.GetEntitiesAsync(n => n.ComplexId == complexId && n.UserId == userId,cancellationToken);
var response = notifications.OrderByDescending(n=>n.CreatedAt)
.Take(new Range(request.Page * count, (request.Page * count) + count))
.ToList();
return response; return response;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Brizco.Repository.Migrations
{
/// <inheritdoc />
public partial class EditShiftPlanAddIsScheduled : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsScheduled",
schema: "public",
table: "ShiftPlans",
type: "boolean",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsScheduled",
schema: "public",
table: "ShiftPlans");
}
}
}

View File

@ -18,12 +18,12 @@ namespace Brizco.Repository.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasDefaultSchema("public") .HasDefaultSchema("public")
.HasAnnotation("ProductVersion", "8.0.4") .HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63); .HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Complex", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Complex", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -70,7 +70,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("Complexes", "public"); b.ToTable("Complexes", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.ComplexUser", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.ComplexUser", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -115,7 +115,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("ComplexUsers", "public"); b.ToTable("ComplexUsers", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.ComplexUserRole", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.ComplexUserRole", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -160,7 +160,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("ComplexUserRoles", "public"); b.ToTable("ComplexUserRoles", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Position", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Position", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -213,7 +213,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("Positions", "public"); b.ToTable("Positions", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.PositionPermission", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.PositionPermission", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -257,7 +257,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("PositionPermissions", "public"); b.ToTable("PositionPermissions", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Section", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Section", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -305,7 +305,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("Sections", "public"); b.ToTable("Sections", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Routine.Routine", b => modelBuilder.Entity("Brizco.Domain.Entities.Routines.Routine", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -353,7 +353,128 @@ namespace Brizco.Repository.Migrations
b.ToTable("Routines", "public"); b.ToTable("Routines", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.Shift", b => modelBuilder.Entity("Brizco.Domain.Entities.ShiftPlans.ShiftPlan", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("CompleteDescription")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CompletePercent")
.HasColumnType("integer");
b.Property<Guid>("ComplexId")
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsCompleted")
.HasColumnType("boolean");
b.Property<bool>("IsRemoved")
.HasColumnType("boolean");
b.Property<bool>("IsScheduled")
.HasColumnType("boolean");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("ModifiedBy")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PlanFor")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("RemovedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("RemovedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("RoutineId")
.HasColumnType("uuid");
b.Property<Guid>("ShiftId")
.HasColumnType("uuid");
b.Property<Guid>("SupervisorId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ComplexId");
b.HasIndex("RoutineId");
b.HasIndex("ShiftId");
b.HasIndex("SupervisorId");
b.ToTable("ShiftPlans", "public");
});
modelBuilder.Entity("Brizco.Domain.Entities.ShiftPlans.ShiftPlanUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsRemoved")
.HasColumnType("boolean");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("ModifiedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("PositionId")
.HasColumnType("uuid");
b.Property<DateTime>("RemovedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("RemovedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ShiftPlanId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("PositionId");
b.HasIndex("ShiftPlanId");
b.HasIndex("UserId");
b.ToTable("ShiftPlanUsers", "public");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shifts.Shift", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -407,7 +528,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("Shifts", "public"); b.ToTable("Shifts", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftDay", b => modelBuilder.Entity("Brizco.Domain.Entities.Shifts.ShiftDay", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -450,125 +571,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("ShiftDays", "public"); b.ToTable("ShiftDays", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftPlan", b => modelBuilder.Entity("Brizco.Domain.Entities.Shifts.ShiftRoutine", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("CompleteDescription")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CompletePercent")
.HasColumnType("integer");
b.Property<Guid>("ComplexId")
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsCompleted")
.HasColumnType("boolean");
b.Property<bool>("IsRemoved")
.HasColumnType("boolean");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("ModifiedBy")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("PlanFor")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("RemovedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("RemovedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("RoutineId")
.HasColumnType("uuid");
b.Property<Guid>("ShiftId")
.HasColumnType("uuid");
b.Property<Guid>("SupervisorId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ComplexId");
b.HasIndex("RoutineId");
b.HasIndex("ShiftId");
b.HasIndex("SupervisorId");
b.ToTable("ShiftPlans", "public");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftPlanUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsRemoved")
.HasColumnType("boolean");
b.Property<DateTime>("ModifiedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("ModifiedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("PositionId")
.HasColumnType("uuid");
b.Property<DateTime>("RemovedAt")
.HasColumnType("timestamp without time zone");
b.Property<string>("RemovedBy")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ShiftPlanId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("PositionId");
b.HasIndex("ShiftPlanId");
b.HasIndex("UserId");
b.ToTable("ShiftPlanUsers", "public");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftRoutine", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -613,7 +616,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("ShiftRoutines", "public"); b.ToTable("ShiftRoutines", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.Task", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.Task", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -694,7 +697,7 @@ namespace Brizco.Repository.Migrations
b.UseTphMappingStrategy(); b.UseTphMappingStrategy();
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskDay", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskDay", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -737,7 +740,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("TaskDays", "public"); b.ToTable("TaskDays", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskPosition", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskPosition", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -782,7 +785,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("TaskPositions", "public"); b.ToTable("TaskPositions", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskRoutine", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskRoutine", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -827,7 +830,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("TaskRoutines", "public"); b.ToTable("TaskRoutines", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskShift", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskShift", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -872,7 +875,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("TaskShifts", "public"); b.ToTable("TaskShifts", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.User.ApplicationRole", b => modelBuilder.Entity("Brizco.Domain.Entities.Users.ApplicationRole", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -916,7 +919,7 @@ namespace Brizco.Repository.Migrations
b.ToTable("Roles", "public"); b.ToTable("Roles", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.User.ApplicationUser", b => modelBuilder.Entity("Brizco.Domain.Entities.Users.ApplicationUser", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -1108,9 +1111,9 @@ namespace Brizco.Repository.Migrations
b.ToTable("Tokens", "public"); b.ToTable("Tokens", "public");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.Activity", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.Activity", b =>
{ {
b.HasBaseType("Brizco.Domain.Entities.Task.Task"); b.HasBaseType("Brizco.Domain.Entities.Tasks.Task");
b.Property<DateTime>("DoneAt") b.Property<DateTime>("DoneAt")
.HasColumnType("timestamp without time zone"); .HasColumnType("timestamp without time zone");
@ -1142,14 +1145,14 @@ namespace Brizco.Repository.Migrations
b.HasDiscriminator().HasValue("Activity"); b.HasDiscriminator().HasValue("Activity");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.ComplexUser", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.ComplexUser", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany("Users") .WithMany("Users")
.HasForeignKey("ComplexId") .HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", "User") b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", "User")
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1159,14 +1162,14 @@ namespace Brizco.Repository.Migrations
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.ComplexUserRole", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.ComplexUserRole", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.ComplexUser", "ComplexUser") b.HasOne("Brizco.Domain.Entities.Complexes.ComplexUser", "ComplexUser")
.WithMany("Roles") .WithMany("Roles")
.HasForeignKey("ComplexUserId") .HasForeignKey("ComplexUserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.User.ApplicationRole", "Role") b.HasOne("Brizco.Domain.Entities.Users.ApplicationRole", "Role")
.WithMany() .WithMany()
.HasForeignKey("RoleId") .HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1176,14 +1179,14 @@ namespace Brizco.Repository.Migrations
b.Navigation("Role"); b.Navigation("Role");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Position", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Position", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany() .WithMany()
.HasForeignKey("ComplexId") .HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Complex.Section", "Section") b.HasOne("Brizco.Domain.Entities.Complexes.Section", "Section")
.WithMany("Positions") .WithMany("Positions")
.HasForeignKey("SectionId") .HasForeignKey("SectionId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1193,9 +1196,9 @@ namespace Brizco.Repository.Migrations
b.Navigation("Section"); b.Navigation("Section");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.PositionPermission", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.PositionPermission", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Position", "Position") b.HasOne("Brizco.Domain.Entities.Complexes.Position", "Position")
.WithMany("Permissions") .WithMany("Permissions")
.HasForeignKey("PositionId") .HasForeignKey("PositionId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1203,9 +1206,9 @@ namespace Brizco.Repository.Migrations
b.Navigation("Position"); b.Navigation("Position");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Section", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Section", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany() .WithMany()
.HasForeignKey("ComplexId") .HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1213,9 +1216,9 @@ namespace Brizco.Repository.Migrations
b.Navigation("Complex"); b.Navigation("Complex");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Routine.Routine", b => modelBuilder.Entity("Brizco.Domain.Entities.Routines.Routine", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany() .WithMany()
.HasForeignKey("ComplexId") .HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1223,44 +1226,24 @@ namespace Brizco.Repository.Migrations
b.Navigation("Complex"); b.Navigation("Complex");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.Shift", b => modelBuilder.Entity("Brizco.Domain.Entities.ShiftPlans.ShiftPlan", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany("Shifts")
.HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Complex");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftDay", b =>
{
b.HasOne("Brizco.Domain.Entities.Shift.Shift", "Shift")
.WithMany("Days")
.HasForeignKey("ShiftId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Shift");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftPlan", b =>
{
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex")
.WithMany() .WithMany()
.HasForeignKey("ComplexId") .HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Routine.Routine", "Routine") b.HasOne("Brizco.Domain.Entities.Routines.Routine", "Routine")
.WithMany() .WithMany()
.HasForeignKey("RoutineId") .HasForeignKey("RoutineId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Shift.Shift", "Shift") b.HasOne("Brizco.Domain.Entities.Shifts.Shift", "Shift")
.WithMany("Plans") .WithMany("Plans")
.HasForeignKey("ShiftId") .HasForeignKey("ShiftId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", "Supervisor") b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", "Supervisor")
.WithMany() .WithMany()
.HasForeignKey("SupervisorId") .HasForeignKey("SupervisorId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1274,19 +1257,19 @@ namespace Brizco.Repository.Migrations
b.Navigation("Supervisor"); b.Navigation("Supervisor");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftPlanUser", b => modelBuilder.Entity("Brizco.Domain.Entities.ShiftPlans.ShiftPlanUser", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Position", "Position") b.HasOne("Brizco.Domain.Entities.Complexes.Position", "Position")
.WithMany() .WithMany()
.HasForeignKey("PositionId") .HasForeignKey("PositionId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Shift.ShiftPlan", "ShiftPlan") b.HasOne("Brizco.Domain.Entities.ShiftPlans.ShiftPlan", "ShiftPlan")
.WithMany("Users") .WithMany("Users")
.HasForeignKey("ShiftPlanId") .HasForeignKey("ShiftPlanId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", "User") b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", "User")
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1298,14 +1281,34 @@ namespace Brizco.Repository.Migrations
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftRoutine", b => modelBuilder.Entity("Brizco.Domain.Entities.Shifts.Shift", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Routine.Routine", "Routine") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany("Shifts")
.HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Complex");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shifts.ShiftDay", b =>
{
b.HasOne("Brizco.Domain.Entities.Shifts.Shift", "Shift")
.WithMany("Days")
.HasForeignKey("ShiftId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Shift");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shifts.ShiftRoutine", b =>
{
b.HasOne("Brizco.Domain.Entities.Routines.Routine", "Routine")
.WithMany("Shifts") .WithMany("Shifts")
.HasForeignKey("RoutineId") .HasForeignKey("RoutineId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Shift.Shift", "Shift") b.HasOne("Brizco.Domain.Entities.Shifts.Shift", "Shift")
.WithMany("Routines") .WithMany("Routines")
.HasForeignKey("ShiftId") .HasForeignKey("ShiftId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1315,9 +1318,9 @@ namespace Brizco.Repository.Migrations
b.Navigation("Shift"); b.Navigation("Shift");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.Task", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.Task", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany("Tasks") .WithMany("Tasks")
.HasForeignKey("ComplexId") .HasForeignKey("ComplexId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1325,9 +1328,9 @@ namespace Brizco.Repository.Migrations
b.Navigation("Complex"); b.Navigation("Complex");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskDay", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskDay", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Task.Task", "Task") b.HasOne("Brizco.Domain.Entities.Tasks.Task", "Task")
.WithMany("Days") .WithMany("Days")
.HasForeignKey("TaskId") .HasForeignKey("TaskId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1335,14 +1338,14 @@ namespace Brizco.Repository.Migrations
b.Navigation("Task"); b.Navigation("Task");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskPosition", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskPosition", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Position", "Position") b.HasOne("Brizco.Domain.Entities.Complexes.Position", "Position")
.WithMany() .WithMany()
.HasForeignKey("PositionId") .HasForeignKey("PositionId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Task.Task", "Task") b.HasOne("Brizco.Domain.Entities.Tasks.Task", "Task")
.WithMany("Positions") .WithMany("Positions")
.HasForeignKey("TaskId") .HasForeignKey("TaskId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1352,14 +1355,14 @@ namespace Brizco.Repository.Migrations
b.Navigation("Task"); b.Navigation("Task");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskRoutine", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskRoutine", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Routine.Routine", "Routine") b.HasOne("Brizco.Domain.Entities.Routines.Routine", "Routine")
.WithMany("Tasks") .WithMany("Tasks")
.HasForeignKey("RoutineId") .HasForeignKey("RoutineId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Task.Task", "Task") b.HasOne("Brizco.Domain.Entities.Tasks.Task", "Task")
.WithMany("Routines") .WithMany("Routines")
.HasForeignKey("TaskId") .HasForeignKey("TaskId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1369,14 +1372,14 @@ namespace Brizco.Repository.Migrations
b.Navigation("Task"); b.Navigation("Task");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.TaskShift", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.TaskShift", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Shift.Shift", "Shift") b.HasOne("Brizco.Domain.Entities.Shifts.Shift", "Shift")
.WithMany() .WithMany()
.HasForeignKey("ShiftId") .HasForeignKey("ShiftId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.Task.Task", "Task") b.HasOne("Brizco.Domain.Entities.Tasks.Task", "Task")
.WithMany("Shifts") .WithMany("Shifts")
.HasForeignKey("TaskId") .HasForeignKey("TaskId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1386,9 +1389,9 @@ namespace Brizco.Repository.Migrations
b.Navigation("Task"); b.Navigation("Task");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.User.ApplicationRole", b => modelBuilder.Entity("Brizco.Domain.Entities.Users.ApplicationRole", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Complex.Complex", "Complex") b.HasOne("Brizco.Domain.Entities.Complexes.Complex", "Complex")
.WithMany("Roles") .WithMany("Roles")
.HasForeignKey("ComplexId"); .HasForeignKey("ComplexId");
@ -1397,7 +1400,7 @@ namespace Brizco.Repository.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
{ {
b.HasOne("Brizco.Domain.Entities.User.ApplicationRole", null) b.HasOne("Brizco.Domain.Entities.Users.ApplicationRole", null)
.WithMany() .WithMany()
.HasForeignKey("RoleId") .HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1405,7 +1408,7 @@ namespace Brizco.Repository.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
{ {
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", null) b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1413,7 +1416,7 @@ namespace Brizco.Repository.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
{ {
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", null) b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1421,12 +1424,12 @@ namespace Brizco.Repository.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
{ {
b.HasOne("Brizco.Domain.Entities.User.ApplicationRole", null) b.HasOne("Brizco.Domain.Entities.Users.ApplicationRole", null)
.WithMany() .WithMany()
.HasForeignKey("RoleId") .HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", null) b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1434,20 +1437,20 @@ namespace Brizco.Repository.Migrations
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
{ {
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", null) b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", null)
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Task.Activity", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.Activity", b =>
{ {
b.HasOne("Brizco.Domain.Entities.Shift.ShiftPlan", "ShiftPlan") b.HasOne("Brizco.Domain.Entities.ShiftPlans.ShiftPlan", "ShiftPlan")
.WithMany() .WithMany()
.HasForeignKey("ShiftPlanId") .HasForeignKey("ShiftPlanId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", "User") b.HasOne("Brizco.Domain.Entities.Users.ApplicationUser", "User")
.WithMany() .WithMany()
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict); .OnDelete(DeleteBehavior.Restrict);
@ -1457,7 +1460,7 @@ namespace Brizco.Repository.Migrations
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Complex", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Complex", b =>
{ {
b.Navigation("Roles"); b.Navigation("Roles");
@ -1468,29 +1471,34 @@ namespace Brizco.Repository.Migrations
b.Navigation("Users"); b.Navigation("Users");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.ComplexUser", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.ComplexUser", b =>
{ {
b.Navigation("Roles"); b.Navigation("Roles");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Position", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Position", b =>
{ {
b.Navigation("Permissions"); b.Navigation("Permissions");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Complex.Section", b => modelBuilder.Entity("Brizco.Domain.Entities.Complexes.Section", b =>
{ {
b.Navigation("Positions"); b.Navigation("Positions");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Routine.Routine", b => modelBuilder.Entity("Brizco.Domain.Entities.Routines.Routine", b =>
{ {
b.Navigation("Shifts"); b.Navigation("Shifts");
b.Navigation("Tasks"); b.Navigation("Tasks");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.Shift", b => modelBuilder.Entity("Brizco.Domain.Entities.ShiftPlans.ShiftPlan", b =>
{
b.Navigation("Users");
});
modelBuilder.Entity("Brizco.Domain.Entities.Shifts.Shift", b =>
{ {
b.Navigation("Days"); b.Navigation("Days");
@ -1499,12 +1507,7 @@ namespace Brizco.Repository.Migrations
b.Navigation("Routines"); b.Navigation("Routines");
}); });
modelBuilder.Entity("Brizco.Domain.Entities.Shift.ShiftPlan", b => modelBuilder.Entity("Brizco.Domain.Entities.Tasks.Task", b =>
{
b.Navigation("Users");
});
modelBuilder.Entity("Brizco.Domain.Entities.Task.Task", b =>
{ {
b.Navigation("Days"); b.Navigation("Days");

28
NuGet.config 100644
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- <configuration>
<config>
<add key='maxHttpRequestsPerSource' value='10' />
</config>
<packageSources>
<clear />
<add key="VnfRepos" value="https://packages.vnfco.ir/repository/nuget-group/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSourceCredentials>
<VnfRepos>
<add key="Username" value="runner" />
<add key="ClearTextPassword" value="22102210aA" />
</VnfRepos>
</packageSourceCredentials>
</configuration> -->
<configuration>
<config>
<add key='maxHttpRequestsPerSource' value='10' />
</config>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>