From e067a5fe73b9a52d5e4a8b73dd6c3e1c438d9900 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Wed, 13 Dec 2023 12:05:04 +0330 Subject: [PATCH] add version 0.2.3.1 fix cores error in authorize , fix update shift plan and activity errors --- .version | 2 +- Brizco.Api/Brizco.Api.csproj | 4 +- Brizco.Api/Controllers/RoutineController.cs | 4 +- Brizco.Api/Controllers/ShiftPlanController.cs | 4 +- Brizco.Api/Program.cs | 10 ++- .../ConfigureJwtBearerOptions.cs | 2 +- .../PersianIdentityErrorDescriber.cs | 6 +- .../Configurations/ServiceExtensions.cs | 11 ++++ Brizco.Common/Brizco.Common.csproj | 1 - .../Extensions/ClassDisplayExtensions.cs | 8 +-- Brizco.Common/Extensions/EnumExtensions.cs | 4 +- Brizco.Common/Models/Entity/ApiEntity.cs | 4 +- Brizco.Core/CoreServices/AccountService.cs | 2 + .../Abstracts/IActivityService.cs | 1 + .../Abstracts/IShiftPlanService.cs | 1 + Brizco.Core/EntityServices/ActivityService.cs | 66 ++++++++++++++++++- .../EntityServices/ShiftPlanService.cs | 10 ++- .../Commands/ActivityCommands.cs | 5 +- .../CommandQueries/Queries/RoutineQueries.cs | 2 +- Brizco.Domain/Dtos/LargDtos/ActivityLDto.cs | 2 + Brizco.Domain/Mappers/ActivityMapper.g.cs | 10 +++ .../Activity/CreateActivityCommandHandler.cs | 7 +- .../Activity/UpdateActivityCommandHandler.cs | 3 + .../Routine/GetRoutineShiftsQueryHandler.cs | 16 ++++- .../UpdateShiftPlanCommandHandler.cs | 3 + 25 files changed, 151 insertions(+), 37 deletions(-) diff --git a/.version b/.version index ec34431..c8f5a9a 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.2.1.0 \ No newline at end of file +0.2.3.1 \ No newline at end of file diff --git a/Brizco.Api/Brizco.Api.csproj b/Brizco.Api/Brizco.Api.csproj index 05141b4..34f9939 100644 --- a/Brizco.Api/Brizco.Api.csproj +++ b/Brizco.Api/Brizco.Api.csproj @@ -6,8 +6,8 @@ enable Linux ..\docker-compose.dcproj - 0.2.1.0 - 0.2.1.0 + 0.2.3.1 + 0.2.3.1 diff --git a/Brizco.Api/Controllers/RoutineController.cs b/Brizco.Api/Controllers/RoutineController.cs index 65b3893..0d371c5 100644 --- a/Brizco.Api/Controllers/RoutineController.cs +++ b/Brizco.Api/Controllers/RoutineController.cs @@ -39,8 +39,8 @@ public class RoutineController : ICarterModule => TypedResults.Ok(await sender.Send(new GetRoutineQuery(id), cancellationToken)); // GET:Get Shifts By Id - public async Task GetShiftsAsync(Guid id, ISender sender, CancellationToken cancellationToken) - => TypedResults.Ok(await sender.Send(new GetRoutineShiftsQuery(id), cancellationToken)); + public async Task GetShiftsAsync(Guid id, [FromQuery]long? selectedDate, ISender sender, CancellationToken cancellationToken) + => TypedResults.Ok(await sender.Send(new GetRoutineShiftsQuery(id, selectedDate ?? 0), cancellationToken)); // POST:Create Entity public async Task Post([FromBody] CreateRoutineCommand ent, ISender mediator, CancellationToken cancellationToken) diff --git a/Brizco.Api/Controllers/ShiftPlanController.cs b/Brizco.Api/Controllers/ShiftPlanController.cs index 8068a1a..33fd7d7 100644 --- a/Brizco.Api/Controllers/ShiftPlanController.cs +++ b/Brizco.Api/Controllers/ShiftPlanController.cs @@ -49,8 +49,8 @@ public class ShiftPlanController : ICarterModule => TypedResults.Ok(await shiftPlanService.CreateAsync(ent, cancellationToken)); // PUT:Update Entity - public async Task Put([FromBody] UpdateShiftPlanCommand ent, ISender mediator, CancellationToken cancellationToken) - => TypedResults.Ok(await mediator.Send(ent, cancellationToken)); + public async Task Put([FromBody] UpdateShiftPlanCommand ent, IShiftPlanService shiftPlanService, CancellationToken cancellationToken) + => TypedResults.Ok(await shiftPlanService.UpdateAsync(ent, cancellationToken)); // DELETE:Delete Entity public async Task Delete(Guid id, ISender mediator, CancellationToken cancellationToken) diff --git a/Brizco.Api/Program.cs b/Brizco.Api/Program.cs index 97a57f6..88f111b 100644 --- a/Brizco.Api/Program.cs +++ b/Brizco.Api/Program.cs @@ -35,9 +35,10 @@ builder.Services.Configure(configuration.GetSection(nameof(SiteSet // Add services to the container. builder.Services.AddControllers(); +builder.Services.AddCustomCores(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddCustomSwagger(siteSetting.BaseUrl); +builder.Services.AddCustomSwagger(siteSetting!.BaseUrl); builder.Services.AddCustomApiVersioning(); builder.Services.AddCustomController(); builder.Services.AddControllers(); @@ -101,16 +102,13 @@ if (app.Environment.IsDevelopment()) //app.UseSwagger(); //app.UseSwaggerUI(); } +app.UseCors("CorsPolicy"); + app.UseCustomSwagger(siteSetting.BaseUrl); app.UseAuthorization(); app.UseAuthentication(); -app.UseCors(x => x - .SetIsOriginAllowed(origin => true) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials()); app.UseExceptionHandlerMiddleware(); diff --git a/Brizco.Api/WebFramework/Configurations/ConfigureJwtBearerOptions.cs b/Brizco.Api/WebFramework/Configurations/ConfigureJwtBearerOptions.cs index 4ef86c6..2511677 100644 --- a/Brizco.Api/WebFramework/Configurations/ConfigureJwtBearerOptions.cs +++ b/Brizco.Api/WebFramework/Configurations/ConfigureJwtBearerOptions.cs @@ -4,7 +4,7 @@ namespace Brizco.Api.WebFramework.Configurations; public class ConfigureJwtBearerOptions : IPostConfigureOptions { - public void PostConfigure(string name, JwtBearerOptions options) + public void PostConfigure(string? name, JwtBearerOptions options) { var originalOnMessageReceived = options.Events.OnMessageReceived; options.Events.OnMessageReceived = async context => diff --git a/Brizco.Api/WebFramework/Configurations/PersianIdentityErrorDescriber.cs b/Brizco.Api/WebFramework/Configurations/PersianIdentityErrorDescriber.cs index 05cf7a3..e32cad1 100644 --- a/Brizco.Api/WebFramework/Configurations/PersianIdentityErrorDescriber.cs +++ b/Brizco.Api/WebFramework/Configurations/PersianIdentityErrorDescriber.cs @@ -29,7 +29,7 @@ public class PersianIdentityErrorDescriber : IdentityErrorDescriber { Code = nameof(LoginAlreadyAssociated), Description = "یوزری با این مشخصات در حال حاضر لاگین کرده است" }; } - public override IdentityError InvalidUserName(string userName) + public override IdentityError InvalidUserName(string? userName) { return new IdentityError { @@ -38,7 +38,7 @@ public class PersianIdentityErrorDescriber : IdentityErrorDescriber }; } - public override IdentityError InvalidEmail(string email) + public override IdentityError InvalidEmail(string? email) { return new IdentityError { Code = nameof(InvalidEmail), Description = $"ایمیل '{email}' صحیح نمی باشد" }; } @@ -58,7 +58,7 @@ public class PersianIdentityErrorDescriber : IdentityErrorDescriber { Code = nameof(DuplicateEmail), Description = $"ایمیل '{email}' قبل استفاده شده است" }; } - public override IdentityError InvalidRoleName(string role) + public override IdentityError InvalidRoleName(string? role) { return new IdentityError { Code = nameof(InvalidRoleName), Description = $"نقش '{role}' موجود نمی باشد" }; } diff --git a/Brizco.Api/WebFramework/Configurations/ServiceExtensions.cs b/Brizco.Api/WebFramework/Configurations/ServiceExtensions.cs index cfa3fa4..00e377a 100644 --- a/Brizco.Api/WebFramework/Configurations/ServiceExtensions.cs +++ b/Brizco.Api/WebFramework/Configurations/ServiceExtensions.cs @@ -95,6 +95,7 @@ public static class ServiceExtensions .AllowAnyHeader() .SetIsOriginAllowed(_ => true) .AllowCredentials(); + })); } @@ -164,6 +165,16 @@ public static class ServiceExtensions context.Token = accessToken.ToString(); return Task.CompletedTask; }, + OnForbidden = context => + { + context.Response.StatusCode = StatusCodes.Status403Forbidden; + return Task.CompletedTask; + }, + OnAuthenticationFailed = context => + { + context.Response.StatusCode = StatusCodes.Status401Unauthorized; + return Task.CompletedTask; + }, OnChallenge = async context => { // Call this to skip the default logic and avoid using the default response diff --git a/Brizco.Common/Brizco.Common.csproj b/Brizco.Common/Brizco.Common.csproj index 75f79cb..ce92ab5 100644 --- a/Brizco.Common/Brizco.Common.csproj +++ b/Brizco.Common/Brizco.Common.csproj @@ -18,7 +18,6 @@ net5.0 10 enable - enable diff --git a/Brizco.Common/Extensions/ClassDisplayExtensions.cs b/Brizco.Common/Extensions/ClassDisplayExtensions.cs index b60357b..cd5a114 100644 --- a/Brizco.Common/Extensions/ClassDisplayExtensions.cs +++ b/Brizco.Common/Extensions/ClassDisplayExtensions.cs @@ -14,10 +14,10 @@ namespace Brizco.Common.Extensions var displayAttribute = attr as ClassDisplay; if (displayAttribute == null) continue; - return displayAttribute.GetName(); + return displayAttribute.GetName() ?? string.Empty; } - return null; + return string.Empty; } public static string GetDisplayAttributeDescription() @@ -30,10 +30,10 @@ namespace Brizco.Common.Extensions var displayAttribute = attr as ClassDisplay; if (displayAttribute == null) continue; - return displayAttribute.GetDescription(); + return displayAttribute.GetDescription() ?? string.Empty; } - return null; + return string.Empty; } } } \ No newline at end of file diff --git a/Brizco.Common/Extensions/EnumExtensions.cs b/Brizco.Common/Extensions/EnumExtensions.cs index 4c702ba..cc342b6 100644 --- a/Brizco.Common/Extensions/EnumExtensions.cs +++ b/Brizco.Common/Extensions/EnumExtensions.cs @@ -29,7 +29,7 @@ namespace Brizco.Common.Extensions throw new NotSupportedException(); foreach (var value in Enum.GetValues(input.GetType())) - if ((input as Enum).HasFlag(value as Enum)) + if (value is Enum valueEnum && ((input as Enum)!).HasFlag(valueEnum)) yield return (T)value; } @@ -37,7 +37,7 @@ namespace Brizco.Common.Extensions { AssertExtensions.NotNull(value, nameof(value)); - var attribute = value.GetType().GetField(value.ToString()) + var attribute = (value.GetType().GetField(value.ToString())) .GetCustomAttributes(false).FirstOrDefault(); if (attribute == null) diff --git a/Brizco.Common/Models/Entity/ApiEntity.cs b/Brizco.Common/Models/Entity/ApiEntity.cs index 5ed5db5..31e667b 100644 --- a/Brizco.Common/Models/Entity/ApiEntity.cs +++ b/Brizco.Common/Models/Entity/ApiEntity.cs @@ -27,14 +27,14 @@ public abstract class ApiEntity : IApiEntity , IEquatable - public bool Equals(ApiEntity? other) + public bool Equals(ApiEntity other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Id.Equals(other.Id); } - public override bool Equals(object? obj) + public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; diff --git a/Brizco.Core/CoreServices/AccountService.cs b/Brizco.Core/CoreServices/AccountService.cs index f3b564c..7a7bea2 100644 --- a/Brizco.Core/CoreServices/AccountService.cs +++ b/Brizco.Core/CoreServices/AccountService.cs @@ -174,6 +174,7 @@ public class AccountService : IAccountService jwt = await _jwtService.Generate(user, complexUser!.ComplexId, complexUserRole!.RoleId); jwt.User.SelectedComplexName = complexUser.ComplexName; jwt.User.SelectedRoleName = complexUserRole.RoleName; + jwt.User.SelectedRoleId = complexUserRole!.Id; jwt.Roles = userComplexRoles; } else @@ -204,6 +205,7 @@ public class AccountService : IAccountService jwt = (await _jwtService.Generate(user, complexUser.ComplexId, complexUserRole.RoleId)).Adapt>(); jwt.User.SelectedComplexName = complexUser.ComplexName; jwt.User.SelectedRoleName = complexUserRole.RoleName; + jwt.User.SelectedRoleId = complexUserRole!.Id; jwt.Roles = new List { complexUserRole }; } else diff --git a/Brizco.Core/EntityServices/Abstracts/IActivityService.cs b/Brizco.Core/EntityServices/Abstracts/IActivityService.cs index 5a571c8..5f09116 100644 --- a/Brizco.Core/EntityServices/Abstracts/IActivityService.cs +++ b/Brizco.Core/EntityServices/Abstracts/IActivityService.cs @@ -2,6 +2,7 @@ public interface IActivityService : IScopedDependency { + Task UpdateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken); Task CreateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken); Task DoneActivityAsync(Guid activityId, CancellationToken cancellationToken); Task CompleteActivitiesAsync(List requestDtos, CancellationToken cancellationToken); diff --git a/Brizco.Core/EntityServices/Abstracts/IShiftPlanService.cs b/Brizco.Core/EntityServices/Abstracts/IShiftPlanService.cs index bcece6c..6a47e3e 100644 --- a/Brizco.Core/EntityServices/Abstracts/IShiftPlanService.cs +++ b/Brizco.Core/EntityServices/Abstracts/IShiftPlanService.cs @@ -4,5 +4,6 @@ public interface IShiftPlanService : IScopedDependency { Task ChangeShiftPlanTaskStatusAsync(Guid shiftPlanId,bool isChangeToShift , bool isDisable); Task CreateAsync(CreateShiftPlanCommand createShiftPlanCommand,CancellationToken cancellationToken); + Task UpdateAsync(UpdateShiftPlanCommand createShiftPlanCommand,CancellationToken cancellationToken); Task CompleteShiftPlanAsync(Guid id,CompleteShiftPlanRequestDto requestDtos, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/Brizco.Core/EntityServices/ActivityService.cs b/Brizco.Core/EntityServices/ActivityService.cs index a86f750..edecafe 100644 --- a/Brizco.Core/EntityServices/ActivityService.cs +++ b/Brizco.Core/EntityServices/ActivityService.cs @@ -1,6 +1,8 @@ using Brizco.Domain.CommandQueries.Queries; using Brizco.Domain.Entities.Shift; using Brizco.Domain.Entities.Task; +using System.Threading.Tasks; +using Brizco.Domain.Mappers; namespace Brizco.Core.EntityServices; @@ -62,6 +64,66 @@ public class ActivityService : IActivityService return true; } + public async Task UpdateActivitiesByShiftPlan(Guid shiftPlanId, CancellationToken cancellationToken) + { + var shiftPlan = await _mediator.Send(new GetShiftPlanQuery(shiftPlanId), cancellationToken); + if (shiftPlan.Id == Guid.Empty) + return false; + + var tasks = await _repositoryWrapper.SetRepository() + .ExecuteCommand( + $@"SELECT t.""Id"", t.""Amount"", t.""AmountType"", t.""ComplexId"", +t.""CreatedAt"", t.""CreatedBy"", t.""Description"", t.""Discriminator"", t.""HasDisposed"", t.""IsDisposable"", t.""IsRemoved"", t.""ModifiedAt"", +t.""ModifiedBy"", t.""RemovedAt"", t.""RemovedBy"", t.""ScheduleType"", t.""SetFor"", t.""Title"", t.""Type"", t.""DoneAt"", t.""IsDone"", +t.""PerformanceDescription"", t.""ShiftId"", t.""Status"", t.""UserId"" , t.""IsActivity"" , t.""UnDoneReason"" +FROM public.""Tasks"" t +INNER JOIN public.""TaskShifts"" t1 ON t.""Id"" = t1.""TaskId"" +INNER JOIN public.""TaskDays"" t2 ON t.""Id"" = t1.""TaskId"" +INNER JOIN public.""TaskRoutines"" t3 ON t.""Id"" = t1.""TaskId"" +AND {shiftPlan.ShiftId} = t1.""ShiftId"" +AND {shiftPlan.RoutineId} = t3.""RoutineId"" +AND {shiftPlan.PlanFor.DayOfWeek} = t2.""DayOfWeek"" +GROUP BY t.""Id""").AsNoTracking().ToListAsync(cancellationToken); + + var shiftPlanPositions = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(spu => spu.ShiftPlanId == shiftPlan.Id) + .ToListAsync(cancellationToken); + + + var activities = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(a => a.ShiftId == shiftPlan.ShiftId && a.SetFor.Date == shiftPlan.PlanFor.Date) + .Select(ActivityMapper.ProjectToLDto) + .ToListAsync(cancellationToken); + foreach (var activity in activities) + { + var foundedTask = tasks.FirstOrDefault(t => t.Title == activity.Title); + if (foundedTask == null) + continue; + + var taskPositions = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(tp => tp.TaskId == foundedTask.Id) + .ToListAsync(cancellationToken); + + foreach (var taskPosition in taskPositions) + { + var foundedUser = shiftPlanPositions.FirstOrDefault(spu => spu.PositionId == taskPosition.PositionId); + if(foundedUser == null) + continue; + if (activity.UserId != foundedUser.UserId) + { + + 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.AmountType,activity.ScheduleType,shiftPlan.ShiftId,foundedUser.UserId), cancellationToken); + } + } + } + return true; + } + public async Task CreateActivitiesByShiftPlan(Guid shiftPlanId,CancellationToken cancellationToken) { var shiftPlan = await _mediator.Send(new GetShiftPlanQuery(shiftPlanId), cancellationToken); @@ -81,7 +143,7 @@ INNER JOIN public.""TaskRoutines"" t3 ON t.""Id"" = t1.""TaskId"" AND {shiftPlan.ShiftId} = t1.""ShiftId"" AND {shiftPlan.RoutineId} = t3.""RoutineId"" AND {shiftPlan.PlanFor.DayOfWeek} = t2.""DayOfWeek"" -GROUP BY t.""Id""").ToListAsync(cancellationToken); +GROUP BY t.""Id""").AsNoTracking().ToListAsync(cancellationToken); var shiftPlanPositions = await _repositoryWrapper.SetRepository() .TableNoTracking @@ -102,7 +164,7 @@ GROUP BY t.""Id""").ToListAsync(cancellationToken); { await _mediator.Send(new CreateActivityCommand(task.Type, task.Title, task.Description, task.IsDisposable, shiftPlan.PlanFor, task.HasDisposed, task.Amount, task.AmountType, - task.ScheduleType, shiftPlan.ShiftId, new List { fundedUser.UserId }),cancellationToken); + task.ScheduleType, shiftPlan.ShiftId, fundedUser.UserId),cancellationToken); } } } diff --git a/Brizco.Core/EntityServices/ShiftPlanService.cs b/Brizco.Core/EntityServices/ShiftPlanService.cs index 4bf1e59..4006135 100644 --- a/Brizco.Core/EntityServices/ShiftPlanService.cs +++ b/Brizco.Core/EntityServices/ShiftPlanService.cs @@ -1,4 +1,5 @@ -using Brizco.Domain.CommandQueries.Queries; +using Brizco.Domain.CommandQueries.Commands; +using Brizco.Domain.CommandQueries.Queries; using Brizco.Domain.Entities.Shift; namespace Brizco.Core.EntityServices; @@ -28,6 +29,13 @@ public class ShiftPlanService : IShiftPlanService return true; } + public async Task UpdateAsync(UpdateShiftPlanCommand updateShiftPlanCommand, CancellationToken cancellationToken) + { + await _sender.Send(updateShiftPlanCommand, cancellationToken); + await _activityService.UpdateActivitiesByShiftPlan(updateShiftPlanCommand.Id, cancellationToken); + return true; + } + public async Task CompleteShiftPlanAsync(Guid id, CompleteShiftPlanRequestDto requestDtos, CancellationToken cancellationToken) { var shiftPlan = await _repositoryWrapper.SetRepository() diff --git a/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs b/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs index cf76a78..4933254 100644 --- a/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs +++ b/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs @@ -11,7 +11,7 @@ public sealed record CreateActivityCommand( PurchaseAmountType AmountType, TaskScheduleType ScheduleType, Guid ShiftId, - List UserIds) : IRequest; + Guid UserId) : IRequest; public sealed record UpdateActivityCommand(Guid Id, ActivityStatus Status, @@ -26,7 +26,8 @@ public sealed record UpdateActivityCommand(Guid Id, int Amount, PurchaseAmountType AmountType, TaskScheduleType ScheduleType, - List UserIds) : IRequest; + Guid ShiftId, + Guid UserId) : IRequest; public sealed record DeleteActivityCommand(Guid Id) diff --git a/Brizco.Domain/CommandQueries/Queries/RoutineQueries.cs b/Brizco.Domain/CommandQueries/Queries/RoutineQueries.cs index f888925..d1baa5d 100644 --- a/Brizco.Domain/CommandQueries/Queries/RoutineQueries.cs +++ b/Brizco.Domain/CommandQueries/Queries/RoutineQueries.cs @@ -6,5 +6,5 @@ public sealed record GetRoutinesQuery(int Page = 0) : public sealed record GetRoutineQuery(Guid Id) : IRequest; -public sealed record GetRoutineShiftsQuery(Guid Id): +public sealed record GetRoutineShiftsQuery(Guid Id,long SelectedDate): IRequest>; \ No newline at end of file diff --git a/Brizco.Domain/Dtos/LargDtos/ActivityLDto.cs b/Brizco.Domain/Dtos/LargDtos/ActivityLDto.cs index e74f096..3f743bb 100644 --- a/Brizco.Domain/Dtos/LargDtos/ActivityLDto.cs +++ b/Brizco.Domain/Dtos/LargDtos/ActivityLDto.cs @@ -11,9 +11,11 @@ public class ActivityLDto : BaseDto public DateTime SetFor { get; set; } public bool HasDisposed { get; set; } public ActivityStatus Status { get; set; } + public TaskScheduleType ScheduleType { get; set; } public DateTime DoneAt { get; set; } public bool IsDone { get; set; } public string PerformanceDescription { get; set; } = string.Empty; + public Guid UserId { get; internal set; } public int Amount { get; set; } diff --git a/Brizco.Domain/Mappers/ActivityMapper.g.cs b/Brizco.Domain/Mappers/ActivityMapper.g.cs index 7bc777b..1e1dd9f 100644 --- a/Brizco.Domain/Mappers/ActivityMapper.g.cs +++ b/Brizco.Domain/Mappers/ActivityMapper.g.cs @@ -186,12 +186,14 @@ namespace Brizco.Domain.Mappers DoneAt = p13.DoneAt, IsDone = p13.IsDone, PerformanceDescription = p13.PerformanceDescription, + UserId = p13.UserId, Type = p13.Type, Title = p13.Title, Description = p13.Description, IsDisposable = p13.IsDisposable, SetFor = p13.SetFor, HasDisposed = p13.HasDisposed, + ScheduleType = p13.ScheduleType, Amount = p13.Amount, AmountType = p13.AmountType, Id = p13.Id @@ -209,12 +211,14 @@ namespace Brizco.Domain.Mappers result.DoneAt = p14.DoneAt; result.IsDone = p14.IsDone; result.PerformanceDescription = p14.PerformanceDescription; + result.UserId = p14.UserId; result.Type = p14.Type; result.Title = p14.Title; result.Description = p14.Description; result.IsDisposable = p14.IsDisposable; result.SetFor = p14.SetFor; result.HasDisposed = p14.HasDisposed; + result.ScheduleType = p14.ScheduleType; result.Amount = p14.Amount; result.AmountType = p14.AmountType; result.Id = p14.Id; @@ -232,9 +236,11 @@ namespace Brizco.Domain.Mappers SetFor = p16.SetFor, HasDisposed = p16.HasDisposed, Status = p16.Status, + ScheduleType = p16.ScheduleType, DoneAt = p16.DoneAt, IsDone = p16.IsDone, PerformanceDescription = p16.PerformanceDescription, + UserId = p16.UserId, Amount = p16.Amount, AmountType = p16.AmountType, Id = p16.Id @@ -255,9 +261,11 @@ namespace Brizco.Domain.Mappers result.SetFor = p17.SetFor; result.HasDisposed = p17.HasDisposed; result.Status = p17.Status; + result.ScheduleType = p17.ScheduleType; result.DoneAt = p17.DoneAt; result.IsDone = p17.IsDone; result.PerformanceDescription = p17.PerformanceDescription; + result.UserId = p17.UserId; result.Amount = p17.Amount; result.AmountType = p17.AmountType; result.Id = p17.Id; @@ -273,9 +281,11 @@ namespace Brizco.Domain.Mappers SetFor = p19.SetFor, HasDisposed = p19.HasDisposed, Status = p19.Status, + ScheduleType = p19.ScheduleType, DoneAt = p19.DoneAt, IsDone = p19.IsDone, PerformanceDescription = p19.PerformanceDescription, + UserId = p19.UserId, Amount = p19.Amount, AmountType = p19.AmountType, Id = p19.Id diff --git a/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs b/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs index 281a679..e0da337 100644 --- a/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs +++ b/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs @@ -5,7 +5,7 @@ public class CreateActivityCommandHandler : IRequestHandler() .Update(newTask); await _repositoryWrapper.SaveChangesAsync(cancellationToken); diff --git a/Brizco.Repository/Handlers/Routine/GetRoutineShiftsQueryHandler.cs b/Brizco.Repository/Handlers/Routine/GetRoutineShiftsQueryHandler.cs index 6162c6f..27b36ae 100644 --- a/Brizco.Repository/Handlers/Routine/GetRoutineShiftsQueryHandler.cs +++ b/Brizco.Repository/Handlers/Routine/GetRoutineShiftsQueryHandler.cs @@ -26,7 +26,9 @@ public class GetRoutineShiftsQueryHandler : IRequestHandler s.Id == shiftRoutine.ShiftId) .Select(ShiftMapper.ProjectToSDto) .FirstOrDefaultAsync(cancellationToken); - shift?.Days.ForEach(d => + if (shift == null) + continue; + shift.Days.ForEach(d => { var routineShiftRes = routineShiftResponse.FirstOrDefault(s => s.Day == d); if (routineShiftRes != null) @@ -42,6 +44,18 @@ public class GetRoutineShiftsQueryHandler : IRequestHandler 0) + { + var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate); + + var existedShiftPlan = await _repositoryWrapper.SetRepository() + .TableNoTracking + .FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date, cancellationToken); + shift.IsCompleted = existedShiftPlan?.IsCompleted ?? false; + shift.CurrentShiftPlanId = existedShiftPlan?.Id ?? default; + shift.HasCurrentShiftPlan = existedShiftPlan != null; + } + } return routineShiftResponse; diff --git a/Brizco.Repository/Handlers/ShiftPlan/UpdateShiftPlanCommandHandler.cs b/Brizco.Repository/Handlers/ShiftPlan/UpdateShiftPlanCommandHandler.cs index 92261bf..72afdd2 100644 --- a/Brizco.Repository/Handlers/ShiftPlan/UpdateShiftPlanCommandHandler.cs +++ b/Brizco.Repository/Handlers/ShiftPlan/UpdateShiftPlanCommandHandler.cs @@ -38,8 +38,11 @@ public class UpdateShiftPlanCommandHandler : IRequestHandler(shiftPlanUser.PositionId,shiftPlanUser.UserId))) request.UserAndPositionIds.Remove(new KeyValuePair(shiftPlanUser.PositionId, shiftPlanUser.UserId)); else + { _repositoryWrapper.SetRepository() .Delete(shiftPlanUser); + await _repositoryWrapper.SaveChangesAsync(cancellationToken); + } } foreach (var userId in request.UserAndPositionIds)