From 5b67533eee4af1acaf28ed3b8f6a7ed43701e6d9 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Thu, 25 Apr 2024 02:33:17 +0330 Subject: [PATCH] feat : add version 0.5.8.9 , edit roles and permissions , fix issues --- .version | 2 +- .../AppSettings/appsettings.Development.json | 2 +- Brizco.Api/Brizco.Api.csproj | 30 +- Brizco.Api/Properties/launchSettings.json | 2 +- Brizco.Common/Brizco.Common.csproj | 10 +- .../Models/Claims/ApplicationClaims.cs | 19 +- .../Models/Claims/ApplicationPermission.cs | 1 + .../Models/Claims/ApplicationRoles.cs | 9 + Brizco.Core/Brizco.Core.csproj | 4 +- Brizco.Core/CoreServices/PageService.cs | 18 +- Brizco.Core/EntityServices/ComplexService.cs | 16 +- Brizco.Domain/Brizco.Domain.csproj | 10 +- .../Dtos/PageDto/AppDashboardPageDto.cs | 2 + Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs | 15 +- Brizco.Domain/Mappers/ShiftPlanMapper.g.cs | 360 ++++++++++-------- Brizco.Domain/MapsterRegister.cs | 4 + Brizco.Repository/Brizco.Repository.csproj | 12 +- .../Activity/GetActivitiesQueryHandler.cs | 8 +- .../Handlers/Shift/GetShiftsQueryHandler.cs | 58 ++- Brizco.Repository/RepositoryConfig.cs | 1 + .../Contracts/IDbInitializerService.cs | 1 + .../Services/DbInitializerService.cs | 46 +-- 22 files changed, 355 insertions(+), 275 deletions(-) create mode 100644 Brizco.Common/Models/Claims/ApplicationRoles.cs diff --git a/.version b/.version index 3593c71..8cb1c72 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.4.8.8 \ No newline at end of file +0.5.8.9 \ No newline at end of file diff --git a/Brizco.Api/AppSettings/appsettings.Development.json b/Brizco.Api/AppSettings/appsettings.Development.json index bf839cb..7668ae8 100644 --- a/Brizco.Api/AppSettings/appsettings.Development.json +++ b/Brizco.Api/AppSettings/appsettings.Development.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "PostgresServer": "Host=185.220.227.160;port=5432;Username=postgres;Password=ub0J7sFFThkSBmkc0TzSKsCfheRnQpyu;Database=BrizcoDB", + "PostgresServer": "Host=185.220.227.123;port=5432;Username=postgres;Password=ub0J7sFFThkSBmkc0TzSKsCfheRnQpyu;Database=BrizcoDB", "Postgres": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS" }, "Logging": { diff --git a/Brizco.Api/Brizco.Api.csproj b/Brizco.Api/Brizco.Api.csproj index 7ff6e8d..c45e900 100644 --- a/Brizco.Api/Brizco.Api.csproj +++ b/Brizco.Api/Brizco.Api.csproj @@ -6,42 +6,42 @@ enable Linux ..\docker-compose.dcproj - 0.4.8.8 - 0.4.8.8 + 0.5.8.9 + 0.5.8.9 - + - - + + - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + - - + + - + @@ -51,7 +51,7 @@ - + diff --git a/Brizco.Api/Properties/launchSettings.json b/Brizco.Api/Properties/launchSettings.json index 240058c..a13897b 100644 --- a/Brizco.Api/Properties/launchSettings.json +++ b/Brizco.Api/Properties/launchSettings.json @@ -26,7 +26,7 @@ "ASPNETCORE_URLS": "http://+:80" }, "publishAllPorts": true, - "DockerfileRunArguments": " --network=mother -p 32769:80" + "DockerfileRunArguments": " --network=mother -p 32767:80" } }, "$schema": "https://json.schemastore.org/launchsettings.json", diff --git a/Brizco.Common/Brizco.Common.csproj b/Brizco.Common/Brizco.Common.csproj index 2bff86c..295d5ba 100644 --- a/Brizco.Common/Brizco.Common.csproj +++ b/Brizco.Common/Brizco.Common.csproj @@ -1,6 +1,6 @@  - + + - + diff --git a/Brizco.Common/Models/Claims/ApplicationClaims.cs b/Brizco.Common/Models/Claims/ApplicationClaims.cs index 537cca5..b108fb0 100644 --- a/Brizco.Common/Models/Claims/ApplicationClaims.cs +++ b/Brizco.Common/Models/Claims/ApplicationClaims.cs @@ -97,6 +97,13 @@ public static class ApplicationClaims Title = "مشاهده فعالیت ها", Detail = "دسترسی به مشاهده فعالیت ها فروشگاه شما" }; + public static ClaimDto ViewMineActivities { get; } = new ClaimDto + { + Type = CustomClaimType.Permission, + Value = ApplicationPermission.ViewMineActivities, + Title = "مشاهده فعالیت ها من", + Detail = "دسترسی به مشاهده فعالیت ها فروشگاه شما" + }; public static ClaimDto ManageRoutines { get; } = new ClaimDto @@ -217,6 +224,7 @@ public static class ApplicationClaims ManageComplexes, ViewActivities, + ViewMineActivities, ManageRoutines, ViewRoutines, @@ -257,6 +265,7 @@ public static class ApplicationClaims ManageActivities.GetClaim, ViewActivities.GetClaim, ChangeActivityStatus.GetClaim, + ViewMineActivities.GetClaim, ManageRoutines.GetClaim, ViewRoutines.GetClaim, @@ -339,7 +348,7 @@ public static class ApplicationClaims { ManageActivities.GetClaim, ChangeActivityStatus.GetClaim, - ViewActivities.GetClaim, + ViewMineActivities.GetClaim, ManageReports.GetClaim, ViewTasks.GetClaim, @@ -351,13 +360,17 @@ public static class ApplicationClaims ViewShifts.GetClaim, ManageShifts.GetClaim, - ViewDashboard.GetClaim + ViewDashboard.GetClaim, + + ViewRoutines.GetClaim, + ViewPositions.GetClaim, + ViewUsers.GetClaim, }; public static List StaffClaims = new List { ChangeActivityStatus.GetClaim, - ViewActivities.GetClaim, + ViewMineActivities.GetClaim, ViewTasks.GetClaim, diff --git a/Brizco.Common/Models/Claims/ApplicationPermission.cs b/Brizco.Common/Models/Claims/ApplicationPermission.cs index 3991d51..37083b5 100644 --- a/Brizco.Common/Models/Claims/ApplicationPermission.cs +++ b/Brizco.Common/Models/Claims/ApplicationPermission.cs @@ -27,6 +27,7 @@ public static class ApplicationPermission public const string ManageActivities = nameof(ManageActivities); public const string ChangeActivityStatus = nameof(ChangeActivityStatus); public const string ViewActivities = nameof(ViewActivities); + public const string ViewMineActivities = nameof(ViewActivities); public const string ManageRoutines = nameof(ManageRoutines); public const string ViewRoutines = nameof(ViewRoutines); diff --git a/Brizco.Common/Models/Claims/ApplicationRoles.cs b/Brizco.Common/Models/Claims/ApplicationRoles.cs new file mode 100644 index 0000000..31b8642 --- /dev/null +++ b/Brizco.Common/Models/Claims/ApplicationRoles.cs @@ -0,0 +1,9 @@ +namespace Brizco.Common.Models.Claims; + +public static class ApplicationRoles +{ + public const string Manager = nameof(Manager); + public const string ViewerOwner = nameof(ViewerOwner); + public const string SuperVisor = nameof(SuperVisor); + public const string Staff = nameof(Staff); +} \ No newline at end of file diff --git a/Brizco.Core/Brizco.Core.csproj b/Brizco.Core/Brizco.Core.csproj index 6d3ae84..270e93e 100644 --- a/Brizco.Core/Brizco.Core.csproj +++ b/Brizco.Core/Brizco.Core.csproj @@ -10,9 +10,9 @@ - + - + diff --git a/Brizco.Core/CoreServices/PageService.cs b/Brizco.Core/CoreServices/PageService.cs index 3401151..4aead5a 100644 --- a/Brizco.Core/CoreServices/PageService.cs +++ b/Brizco.Core/CoreServices/PageService.cs @@ -25,22 +25,32 @@ public class PageService : IPageService { if (_currentUserService.UserId == null) throw new AppException("User id is null "); - if (Guid.TryParse(_currentUserService.UserId, out Guid userId)!) + if (!Guid.TryParse(_currentUserService.UserId, out Guid userId)) throw new AppException("User id is wrong"); - if (Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)!) + if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId)) throw new AppException("Complex id is wrong"); var todayTasks = await _repositoryWrapper.SetRepository() .TableNoTracking .Where(a => a.UserId == userId) .ToListAsync(cancellationToken); + var todayShiftPlans = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(a => a.PlanFor.Date == DateTime.Today.Date) + .Select(ShiftPlanMapper.ProjectToSDto) + .ToListAsync(cancellationToken); + var names = new List(); + names.AddRange(todayShiftPlans.SelectMany(sp => sp.Users).Select(s => s.UserFullName).ToList()); var page = new AppDashboardPageDto { DoneActivitiesToday = todayTasks.Count(t => t.IsDone), TotalActivitiesToday = todayTasks.Count, - UnDoneActivitiesToday = todayTasks.Count(t => t.IsDone!) + UnDoneActivitiesToday = todayTasks.Count(t => t.IsDone!), + TotalShiftToday = todayShiftPlans.Count, + TodayStaffNames = names, + TotalStaffToday = todayShiftPlans.SelectMany(sp => sp.Users).Count() }; - + if (_currentUserService.Permissions != null) { int totalStepCount = 0; diff --git a/Brizco.Core/EntityServices/ComplexService.cs b/Brizco.Core/EntityServices/ComplexService.cs index 30cbe16..0b33104 100644 --- a/Brizco.Core/EntityServices/ComplexService.cs +++ b/Brizco.Core/EntityServices/ComplexService.cs @@ -24,10 +24,10 @@ public class ComplexService : IComplexService var managerRole = new ApplicationRole { ComplexId = complex.Id, - EnglishName = "Manager", + EnglishName = ApplicationRoles.Manager, PersianName = "مدیریت", Description = "مدیریت مجموعه", - Name = $"Manager_{complex.Id.ToString()}" + Name = $"{ApplicationRoles.Manager}_{complex.Id.ToString()}" }; var createRoleResult = await _roleManager.CreateAsync(managerRole); if (!createRoleResult.Succeeded) @@ -41,10 +41,10 @@ public class ComplexService : IComplexService var viewOwnerRole = new ApplicationRole { ComplexId = complex.Id, - EnglishName = "ViewerOwner", + EnglishName = ApplicationRoles.ViewerOwner, PersianName = "ناظر", Description = "ناظر مجموعه", - Name = $"ViewerOwner_{complex.Id.ToString()}" + Name = $"{ApplicationRoles.ViewerOwner}_{complex.Id.ToString()}" }; var createViewerResult = await _roleManager.CreateAsync(viewOwnerRole); if (!createViewerResult.Succeeded) @@ -56,10 +56,10 @@ public class ComplexService : IComplexService var superVisorRole = new ApplicationRole { ComplexId = complex.Id, - EnglishName = "SuperVisor", + EnglishName = ApplicationRoles.SuperVisor, PersianName = "سوپروایزر", Description = "انجام فعالیت مدیریت کارکنان و وظیفه ها", - Name = $"SuperVisor_{complex.Id.ToString()}" + Name = $"{ApplicationRoles.SuperVisor}_{complex.Id.ToString()}" }; var superVisorRoleResult = await _roleManager.CreateAsync(superVisorRole); if (!superVisorRoleResult.Succeeded) @@ -72,10 +72,10 @@ public class ComplexService : IComplexService var staffRole = new ApplicationRole { ComplexId = complex.Id, - EnglishName = "Staff", + EnglishName = ApplicationRoles.Staff, PersianName = "کارمند", Description = "انجام فعالیت ها و وظیفه ها", - Name = $"Staff_{complex.Id.ToString()}" + Name = $"{ApplicationRoles.Staff}_{complex.Id.ToString()}" }; var staffRoleResult = await _roleManager.CreateAsync(staffRole); if (!staffRoleResult.Succeeded) diff --git a/Brizco.Domain/Brizco.Domain.csproj b/Brizco.Domain/Brizco.Domain.csproj index 9176cdc..a9acb75 100644 --- a/Brizco.Domain/Brizco.Domain.csproj +++ b/Brizco.Domain/Brizco.Domain.csproj @@ -1,6 +1,6 @@  - + - + diff --git a/Brizco.Domain/Dtos/PageDto/AppDashboardPageDto.cs b/Brizco.Domain/Dtos/PageDto/AppDashboardPageDto.cs index 1bfd5cc..95f7f72 100644 --- a/Brizco.Domain/Dtos/PageDto/AppDashboardPageDto.cs +++ b/Brizco.Domain/Dtos/PageDto/AppDashboardPageDto.cs @@ -5,7 +5,9 @@ public class AppDashboardPageDto public int UnDoneActivitiesToday { get; set; } public int DoneActivitiesToday { get; set; } public int TotalActivitiesToday { get; set; } + public int TotalShiftToday { get; set; } public int TotalStaffToday { get; set; } + public List TodayStaffNames { get; set; } = new(); public string CurrentSignUpStep { get; set; } = string.Empty; public int SignUpCompletePercent { get; set; } diff --git a/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs b/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs index b6cadf7..f129675 100644 --- a/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs +++ b/Brizco.Domain/Dtos/SmallDtos/ShiftPlanSDto.cs @@ -1,19 +1,18 @@ -using Brizco.Domain.Entities.Shift; - -namespace Brizco.Domain.Dtos.SmallDtos; +namespace Brizco.Domain.Dtos.SmallDtos; public class ShiftPlanSDto : BaseDto { - public DateTime PlanFor { get; internal set; } - public bool IsCompleted { get; internal set; } + public DateTime PlanFor { get; set; } + public bool IsCompleted { get; set; } public int UndoneActivitiesCount { get; set; } public int DoneActivitiesCount { get; set; } public int TotalActivitiesCount { get; set; } public int StaffCount { get; set; } - public int CompletePercent { get; internal set; } - public string CompleteDescription { get; internal set; } = string.Empty; + public int CompletePercent { get; set; } + public string SupervisorFullName { get; set; } = string.Empty; + public string CompleteDescription { get; set; } = string.Empty; public Guid ShiftId { get; set; } - public string ShiftTitle { get; internal set; } = string.Empty; + public string ShiftTitle { get; set; } = string.Empty; public List Users { get; set; } = new(); } \ No newline at end of file diff --git a/Brizco.Domain/Mappers/ShiftPlanMapper.g.cs b/Brizco.Domain/Mappers/ShiftPlanMapper.g.cs index 1eb7ad3..3b63c1d 100644 --- a/Brizco.Domain/Mappers/ShiftPlanMapper.g.cs +++ b/Brizco.Domain/Mappers/ShiftPlanMapper.g.cs @@ -23,6 +23,11 @@ namespace Brizco.Domain.Mappers CompletePercent = p1.CompletePercent, CompleteDescription = p1.CompleteDescription, ShiftId = p1.ShiftId, + Shift = new Shift() + { + Title = p1.ShiftTitle, + Id = p1.ShiftId + }, Users = funcMain1(p1.Users), Id = p1.Id }; @@ -40,184 +45,193 @@ namespace Brizco.Domain.Mappers result.CompletePercent = p3.CompletePercent; result.CompleteDescription = p3.CompleteDescription; result.ShiftId = p3.ShiftId; - result.Users = funcMain2(p3.Users, result.Users); + result.Shift = funcMain2(new Never(), result.Shift, p3); + result.Users = funcMain3(p3.Users, result.Users); result.Id = p3.Id; return result; } - public static Expression> ProjectToShiftPlan => p7 => new ShiftPlan() + public static Expression> ProjectToShiftPlan => p9 => new ShiftPlan() { - PlanFor = p7.PlanFor, - IsCompleted = p7.IsCompleted, - CompletePercent = p7.CompletePercent, - CompleteDescription = p7.CompleteDescription, - ShiftId = p7.ShiftId, - Users = p7.Users.Select(p8 => new ShiftPlanUser() + PlanFor = p9.PlanFor, + IsCompleted = p9.IsCompleted, + CompletePercent = p9.CompletePercent, + CompleteDescription = p9.CompleteDescription, + ShiftId = p9.ShiftId, + Shift = new Shift() { - ShiftPlanId = p8.ShiftPlanId, - ShiftPlan = new ShiftPlan() {Id = p8.ShiftPlanId}, - PositionId = p8.PositionId, + Title = p9.ShiftTitle, + Id = p9.ShiftId + }, + Users = p9.Users.Select(p10 => new ShiftPlanUser() + { + ShiftPlanId = p10.ShiftPlanId, + ShiftPlan = new ShiftPlan() {Id = p10.ShiftPlanId}, + PositionId = p10.PositionId, Position = new Position() { - Name = p8.PositionName, - Id = p8.PositionId + Name = p10.PositionName, + Id = p10.PositionId }, - UserId = p8.UserId, - User = new ApplicationUser() {Id = p8.UserId}, - Id = p8.Id + UserId = p10.UserId, + User = new ApplicationUser() {Id = p10.UserId}, + Id = p10.Id }).ToList(), - Id = p7.Id + Id = p9.Id }; - public static ShiftPlanSDto AdaptToSDto(this ShiftPlan p9) + public static ShiftPlanSDto AdaptToSDto(this ShiftPlan p11) { - return p9 == null ? null : new ShiftPlanSDto() + return p11 == null ? null : new ShiftPlanSDto() { - PlanFor = p9.PlanFor, - IsCompleted = p9.IsCompleted, - CompletePercent = p9.CompletePercent, - CompleteDescription = p9.CompleteDescription, - ShiftId = p9.ShiftId, - ShiftTitle = p9.Shift == null ? null : p9.Shift.Title, - Users = funcMain3(p9.Users), - Id = p9.Id + PlanFor = p11.PlanFor, + IsCompleted = p11.IsCompleted, + CompletePercent = p11.CompletePercent, + SupervisorFullName = p11.Supervisor != null ? p11.Supervisor.FirstName + " " + p11.Supervisor.LastName : string.Empty, + CompleteDescription = p11.CompleteDescription, + ShiftId = p11.ShiftId, + ShiftTitle = p11.Shift == null ? null : p11.Shift.Title, + Users = funcMain4(p11.Users), + Id = p11.Id }; } - public static ShiftPlanSDto AdaptTo(this ShiftPlan p11, ShiftPlanSDto p12) + public static ShiftPlanSDto AdaptTo(this ShiftPlan p13, ShiftPlanSDto p14) { - if (p11 == null) + if (p13 == null) { return null; } - ShiftPlanSDto result = p12 ?? new ShiftPlanSDto(); + ShiftPlanSDto result = p14 ?? new ShiftPlanSDto(); - result.PlanFor = p11.PlanFor; - result.IsCompleted = p11.IsCompleted; - result.CompletePercent = p11.CompletePercent; - result.CompleteDescription = p11.CompleteDescription; - result.ShiftId = p11.ShiftId; - result.ShiftTitle = p11.Shift == null ? null : p11.Shift.Title; - result.Users = funcMain4(p11.Users, result.Users); - result.Id = p11.Id; + result.PlanFor = p13.PlanFor; + result.IsCompleted = p13.IsCompleted; + result.CompletePercent = p13.CompletePercent; + result.SupervisorFullName = p13.Supervisor != null ? p13.Supervisor.FirstName + " " + p13.Supervisor.LastName : string.Empty; + result.CompleteDescription = p13.CompleteDescription; + result.ShiftId = p13.ShiftId; + result.ShiftTitle = p13.Shift == null ? null : p13.Shift.Title; + result.Users = funcMain5(p13.Users, result.Users); + result.Id = p13.Id; return result; } - public static Expression> ProjectToSDto => p15 => new ShiftPlanSDto() + public static Expression> ProjectToSDto => p17 => new ShiftPlanSDto() { - PlanFor = p15.PlanFor, - IsCompleted = p15.IsCompleted, - CompletePercent = p15.CompletePercent, - CompleteDescription = p15.CompleteDescription, - ShiftId = p15.ShiftId, - ShiftTitle = p15.Shift.Title, - Users = p15.Users.Select(p16 => new ShiftPlanUserSDto() + PlanFor = p17.PlanFor, + IsCompleted = p17.IsCompleted, + CompletePercent = p17.CompletePercent, + SupervisorFullName = p17.Supervisor != null ? p17.Supervisor.FirstName + " " + p17.Supervisor.LastName : string.Empty, + CompleteDescription = p17.CompleteDescription, + ShiftId = p17.ShiftId, + ShiftTitle = p17.Shift.Title, + Users = p17.Users.Select(p18 => new ShiftPlanUserSDto() { - ShiftPlanId = p16.ShiftPlanId, - UserId = p16.UserId, - UserFullName = p16.User != null ? p16.User.FirstName + " " + p16.User.LastName : string.Empty, - PositionId = p16.PositionId, - PositionName = p16.Position != null ? p16.Position.Name : string.Empty, - Id = p16.Id + ShiftPlanId = p18.ShiftPlanId, + UserId = p18.UserId, + UserFullName = p18.User != null ? p18.User.FirstName + " " + p18.User.LastName : string.Empty, + PositionId = p18.PositionId, + PositionName = p18.Position != null ? p18.Position.Name : string.Empty, + Id = p18.Id }).ToList(), - Id = p15.Id + Id = p17.Id }; - public static ShiftPlan AdaptToShiftPlan(this ShiftPlanLDto p17) + public static ShiftPlan AdaptToShiftPlan(this ShiftPlanLDto p19) { - return p17 == null ? null : new ShiftPlan() + return p19 == null ? null : new ShiftPlan() { - PlanFor = p17.PlanFor, - IsCompleted = p17.IsCompleted, - CompletePercent = p17.CompletePercent, - CompleteDescription = p17.CompleteDescription, - ShiftId = p17.ShiftId, - Shift = new Shift() {Id = p17.ShiftId}, - RoutineId = p17.RoutineId, - Routine = new Routine() {Id = p17.RoutineId}, - SupervisorId = p17.SupervisorId, - Supervisor = new ApplicationUser() {Id = p17.SupervisorId}, - Users = funcMain5(p17.Users), - Id = p17.Id + PlanFor = p19.PlanFor, + IsCompleted = p19.IsCompleted, + CompletePercent = p19.CompletePercent, + CompleteDescription = p19.CompleteDescription, + ShiftId = p19.ShiftId, + Shift = new Shift() {Id = p19.ShiftId}, + RoutineId = p19.RoutineId, + Routine = new Routine() {Id = p19.RoutineId}, + SupervisorId = p19.SupervisorId, + Supervisor = new ApplicationUser() {Id = p19.SupervisorId}, + Users = funcMain6(p19.Users), + Id = p19.Id }; } - public static ShiftPlan AdaptTo(this ShiftPlanLDto p19, ShiftPlan p20) + public static ShiftPlan AdaptTo(this ShiftPlanLDto p21, ShiftPlan p22) { - if (p19 == null) + if (p21 == null) { return null; } - ShiftPlan result = p20 ?? new ShiftPlan(); + ShiftPlan result = p22 ?? new ShiftPlan(); - result.PlanFor = p19.PlanFor; - result.IsCompleted = p19.IsCompleted; - result.CompletePercent = p19.CompletePercent; - result.CompleteDescription = p19.CompleteDescription; - result.ShiftId = p19.ShiftId; - result.Shift = funcMain6(new Never(), result.Shift, p19); - result.RoutineId = p19.RoutineId; - result.Routine = funcMain7(new Never(), result.Routine, p19); - result.SupervisorId = p19.SupervisorId; - result.Supervisor = funcMain8(new Never(), result.Supervisor, p19); - result.Users = funcMain9(p19.Users, result.Users); - result.Id = p19.Id; + result.PlanFor = p21.PlanFor; + result.IsCompleted = p21.IsCompleted; + result.CompletePercent = p21.CompletePercent; + result.CompleteDescription = p21.CompleteDescription; + result.ShiftId = p21.ShiftId; + result.Shift = funcMain7(new Never(), result.Shift, p21); + result.RoutineId = p21.RoutineId; + result.Routine = funcMain8(new Never(), result.Routine, p21); + result.SupervisorId = p21.SupervisorId; + result.Supervisor = funcMain9(new Never(), result.Supervisor, p21); + result.Users = funcMain10(p21.Users, result.Users); + result.Id = p21.Id; return result; } - public static ShiftPlanLDto AdaptToLDto(this ShiftPlan p29) + public static ShiftPlanLDto AdaptToLDto(this ShiftPlan p31) { - return p29 == null ? null : new ShiftPlanLDto() + return p31 == null ? null : new ShiftPlanLDto() { - PlanFor = p29.PlanFor, - RoutineId = p29.RoutineId, - IsCompleted = p29.IsCompleted, - CompletePercent = p29.CompletePercent, - CompleteDescription = p29.CompleteDescription, - ShiftId = p29.ShiftId, - Users = funcMain10(p29.Users), - SupervisorId = p29.SupervisorId, - SupervisorFullName = p29.Supervisor != null ? p29.Supervisor.FirstName + " " + p29.Supervisor.LastName : string.Empty, - Id = p29.Id + PlanFor = p31.PlanFor, + RoutineId = p31.RoutineId, + IsCompleted = p31.IsCompleted, + CompletePercent = p31.CompletePercent, + CompleteDescription = p31.CompleteDescription, + ShiftId = p31.ShiftId, + Users = funcMain11(p31.Users), + SupervisorId = p31.SupervisorId, + SupervisorFullName = p31.Supervisor != null ? p31.Supervisor.FirstName + " " + p31.Supervisor.LastName : string.Empty, + Id = p31.Id }; } - public static ShiftPlanLDto AdaptTo(this ShiftPlan p31, ShiftPlanLDto p32) + public static ShiftPlanLDto AdaptTo(this ShiftPlan p33, ShiftPlanLDto p34) { - if (p31 == null) + if (p33 == null) { return null; } - ShiftPlanLDto result = p32 ?? new ShiftPlanLDto(); + ShiftPlanLDto result = p34 ?? new ShiftPlanLDto(); - result.PlanFor = p31.PlanFor; - result.RoutineId = p31.RoutineId; - result.IsCompleted = p31.IsCompleted; - result.CompletePercent = p31.CompletePercent; - result.CompleteDescription = p31.CompleteDescription; - result.ShiftId = p31.ShiftId; - result.Users = funcMain11(p31.Users, result.Users); - result.SupervisorId = p31.SupervisorId; - result.SupervisorFullName = p31.Supervisor != null ? p31.Supervisor.FirstName + " " + p31.Supervisor.LastName : string.Empty; - result.Id = p31.Id; + result.PlanFor = p33.PlanFor; + result.RoutineId = p33.RoutineId; + result.IsCompleted = p33.IsCompleted; + result.CompletePercent = p33.CompletePercent; + result.CompleteDescription = p33.CompleteDescription; + result.ShiftId = p33.ShiftId; + result.Users = funcMain12(p33.Users, result.Users); + result.SupervisorId = p33.SupervisorId; + result.SupervisorFullName = p33.Supervisor != null ? p33.Supervisor.FirstName + " " + p33.Supervisor.LastName : string.Empty; + result.Id = p33.Id; return result; } - public static Expression> ProjectToLDto => p35 => new ShiftPlanLDto() + public static Expression> ProjectToLDto => p37 => new ShiftPlanLDto() { - PlanFor = p35.PlanFor, - RoutineId = p35.RoutineId, - IsCompleted = p35.IsCompleted, - CompletePercent = p35.CompletePercent, - CompleteDescription = p35.CompleteDescription, - ShiftId = p35.ShiftId, - Users = p35.Users.Select(p36 => new ShiftPlanUserSDto() + PlanFor = p37.PlanFor, + RoutineId = p37.RoutineId, + IsCompleted = p37.IsCompleted, + CompletePercent = p37.CompletePercent, + CompleteDescription = p37.CompleteDescription, + ShiftId = p37.ShiftId, + Users = p37.Users.Select(p38 => new ShiftPlanUserSDto() { - ShiftPlanId = p36.ShiftPlanId, - UserId = p36.UserId, - UserFullName = p36.User != null ? p36.User.FirstName + " " + p36.User.LastName : string.Empty, - PositionId = p36.PositionId, - PositionName = p36.Position != null ? p36.Position.Name : string.Empty, - Id = p36.Id + ShiftPlanId = p38.ShiftPlanId, + UserId = p38.UserId, + UserFullName = p38.User != null ? p38.User.FirstName + " " + p38.User.LastName : string.Empty, + PositionId = p38.PositionId, + PositionName = p38.Position != null ? p38.Position.Name : string.Empty, + Id = p38.Id }).ToList(), - SupervisorId = p35.SupervisorId, - SupervisorFullName = p35.Supervisor != null ? p35.Supervisor.FirstName + " " + p35.Supervisor.LastName : string.Empty, - Id = p35.Id + SupervisorId = p37.SupervisorId, + SupervisorFullName = p37.Supervisor != null ? p37.Supervisor.FirstName + " " + p37.Supervisor.LastName : string.Empty, + Id = p37.Id }; private static List funcMain1(List p2) @@ -254,20 +268,30 @@ namespace Brizco.Domain.Mappers } - private static List funcMain2(List p5, List p6) + private static Shift funcMain2(Never p5, Shift p6, ShiftPlanSDto p3) { - if (p5 == null) + Shift result = p6 ?? new Shift(); + + result.Title = p3.ShiftTitle; + result.Id = p3.ShiftId; + return result; + + } + + private static List funcMain3(List p7, List p8) + { + if (p7 == null) { return null; } - List result = new List(p5.Count); + List result = new List(p7.Count); int i = 0; - int len = p5.Count; + int len = p7.Count; while (i < len) { - ShiftPlanUserSDto item = p5[i]; + ShiftPlanUserSDto item = p7[i]; result.Add(item == null ? null : new ShiftPlanUser() { ShiftPlanId = item.ShiftPlanId, @@ -288,20 +312,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain3(List p10) + private static List funcMain4(List p12) { - if (p10 == null) + if (p12 == null) { return null; } - List result = new List(p10.Count); + List result = new List(p12.Count); int i = 0; - int len = p10.Count; + int len = p12.Count; while (i < len) { - ShiftPlanUser item = p10[i]; + ShiftPlanUser item = p12[i]; result.Add(item == null ? null : new ShiftPlanUserSDto() { ShiftPlanId = item.ShiftPlanId, @@ -317,20 +341,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain4(List p13, List p14) + private static List funcMain5(List p15, List p16) { - if (p13 == null) + if (p15 == null) { return null; } - List result = new List(p13.Count); + List result = new List(p15.Count); int i = 0; - int len = p13.Count; + int len = p15.Count; while (i < len) { - ShiftPlanUser item = p13[i]; + ShiftPlanUser item = p15[i]; result.Add(item == null ? null : new ShiftPlanUserSDto() { ShiftPlanId = item.ShiftPlanId, @@ -346,20 +370,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain5(List p18) + private static List funcMain6(List p20) { - if (p18 == null) + if (p20 == null) { return null; } - List result = new List(p18.Count); + List result = new List(p20.Count); int i = 0; - int len = p18.Count; + int len = p20.Count; while (i < len) { - ShiftPlanUserSDto item = p18[i]; + ShiftPlanUserSDto item = p20[i]; result.Add(item == null ? null : new ShiftPlanUser() { ShiftPlanId = item.ShiftPlanId, @@ -380,47 +404,47 @@ namespace Brizco.Domain.Mappers } - private static Shift funcMain6(Never p21, Shift p22, ShiftPlanLDto p19) + private static Shift funcMain7(Never p23, Shift p24, ShiftPlanLDto p21) { - Shift result = p22 ?? new Shift(); + Shift result = p24 ?? new Shift(); - result.Id = p19.ShiftId; + result.Id = p21.ShiftId; return result; } - private static Routine funcMain7(Never p23, Routine p24, ShiftPlanLDto p19) + private static Routine funcMain8(Never p25, Routine p26, ShiftPlanLDto p21) { - Routine result = p24 ?? new Routine(); + Routine result = p26 ?? new Routine(); - result.Id = p19.RoutineId; + result.Id = p21.RoutineId; return result; } - private static ApplicationUser funcMain8(Never p25, ApplicationUser p26, ShiftPlanLDto p19) + private static ApplicationUser funcMain9(Never p27, ApplicationUser p28, ShiftPlanLDto p21) { - ApplicationUser result = p26 ?? new ApplicationUser(); + ApplicationUser result = p28 ?? new ApplicationUser(); - result.Id = p19.SupervisorId; + result.Id = p21.SupervisorId; return result; } - private static List funcMain9(List p27, List p28) + private static List funcMain10(List p29, List p30) { - if (p27 == null) + if (p29 == null) { return null; } - List result = new List(p27.Count); + List result = new List(p29.Count); int i = 0; - int len = p27.Count; + int len = p29.Count; while (i < len) { - ShiftPlanUserSDto item = p27[i]; + ShiftPlanUserSDto item = p29[i]; result.Add(item == null ? null : new ShiftPlanUser() { ShiftPlanId = item.ShiftPlanId, @@ -441,20 +465,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain10(List p30) + private static List funcMain11(List p32) { - if (p30 == null) + if (p32 == null) { return null; } - List result = new List(p30.Count); + List result = new List(p32.Count); int i = 0; - int len = p30.Count; + int len = p32.Count; while (i < len) { - ShiftPlanUser item = p30[i]; + ShiftPlanUser item = p32[i]; result.Add(item == null ? null : new ShiftPlanUserSDto() { ShiftPlanId = item.ShiftPlanId, @@ -470,20 +494,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain11(List p33, List p34) + private static List funcMain12(List p35, List p36) { - if (p33 == null) + if (p35 == null) { return null; } - List result = new List(p33.Count); + List result = new List(p35.Count); int i = 0; - int len = p33.Count; + int len = p35.Count; while (i < len) { - ShiftPlanUser item = p33[i]; + ShiftPlanUser item = p35[i]; result.Add(item == null ? null : new ShiftPlanUserSDto() { ShiftPlanId = item.ShiftPlanId, diff --git a/Brizco.Domain/MapsterRegister.cs b/Brizco.Domain/MapsterRegister.cs index 4f5951c..5a64664 100644 --- a/Brizco.Domain/MapsterRegister.cs +++ b/Brizco.Domain/MapsterRegister.cs @@ -44,6 +44,10 @@ public class MapsterRegister : IRegister .Map("SupervisorFullName", o => o.Supervisor != null ? o.Supervisor.FirstName + " " + o.Supervisor.LastName : string.Empty) .TwoWays(); + config.NewConfig() + .Map("SupervisorFullName", o => o.Supervisor != null ? o.Supervisor.FirstName + " " + o.Supervisor.LastName : string.Empty) + .TwoWays(); + config.NewConfig() .Map("UserFullName", o => o.User != null ? o.User.FirstName + " " + o.User.LastName : string.Empty) .Map("PositionName", o => o.Position != null ? o.Position.Name : string.Empty) diff --git a/Brizco.Repository/Brizco.Repository.csproj b/Brizco.Repository/Brizco.Repository.csproj index 65a1def..3ba8c5d 100644 --- a/Brizco.Repository/Brizco.Repository.csproj +++ b/Brizco.Repository/Brizco.Repository.csproj @@ -8,21 +8,21 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/Brizco.Repository/Handlers/Activity/GetActivitiesQueryHandler.cs b/Brizco.Repository/Handlers/Activity/GetActivitiesQueryHandler.cs index 9e6f67c..4bd2f88 100644 --- a/Brizco.Repository/Handlers/Activity/GetActivitiesQueryHandler.cs +++ b/Brizco.Repository/Handlers/Activity/GetActivitiesQueryHandler.cs @@ -25,6 +25,11 @@ public class GetActivitiesQueryHandler : IRequestHandler activities = _repositoryWrapper.SetRepository().TableNoTracking .Where(a=>a.IsActivity); + if (_currentUserService.Permissions != null) + { + if (_currentUserService.Permissions.Contains(ApplicationPermission.ViewMineActivities)) + activities = activities.Where(a => a.UserId == userId); + } if (request.DateQueryFilter != null) { @@ -53,9 +58,6 @@ public class GetActivitiesQueryHandler : IRequestHandler a.ComplexId == complexId && a.ShiftId == request.SelectedShift); - if (request.SelectedDate == 0 && request.SelectedShift == default) - activities = activities.Where(a => a.UserId == userId); - return await activities.OrderBy(s => s.ScheduleType) diff --git a/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs b/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs index af88c99..301a2c7 100644 --- a/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs +++ b/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs @@ -1,4 +1,5 @@ using Brizco.Domain.Entities.Shift; +using Guid = System.Guid; namespace Brizco.Repository.Handlers.Shift; @@ -18,15 +19,15 @@ public class GetShiftPlansQueryHandler : IRequestHandler shifts = new List(); + List shifts; if (request.SelectedDate > 0) { var selectedDate = DateTimeExtensions.UnixTimeStampToDateTime(request.SelectedDate); var originalShifts = from shiftDay in _repositoryWrapper.SetRepository().Entities - join shift in _repositoryWrapper.SetRepository().Entities on shiftDay .ShiftId equals shift.Id - where shiftDay.DayOfWeek == selectedDate.DayOfWeek && shift.ComplexId == complexId - select shift; + join shift in _repositoryWrapper.SetRepository().Entities on shiftDay.ShiftId equals shift.Id + where shiftDay.DayOfWeek == selectedDate.DayOfWeek && shift.ComplexId == complexId + select shift; shifts = await originalShifts.AsNoTracking().Select(ShiftMapper.ProjectToSDto).ToListAsync(cancellationToken); foreach (var shift in shifts) @@ -44,12 +45,33 @@ public class GetShiftPlansQueryHandler : IRequestHandler() - .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; + switch (_currentUserService.RoleName) + { + case null: + continue; + case ApplicationRoles.SuperVisor: + { + if (!Guid.TryParse(_currentUserService.UserId, out Guid userId)) + throw new AppException("User id is wrong"); + var existedShiftPlan = await _repositoryWrapper.SetRepository() + .TableNoTracking + .FirstOrDefaultAsync(s => s.ShiftId == shift.Id && s.PlanFor.Date == selectedDate.Date && s.SupervisorId == userId, cancellationToken); + shift.IsCompleted = existedShiftPlan?.IsCompleted ?? false; + shift.CurrentShiftPlanId = existedShiftPlan?.Id ?? default; + shift.HasCurrentShiftPlan = existedShiftPlan != null; + break; + } + case ApplicationRoles.Manager: + { + 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; + break; + } + } } } else @@ -61,18 +83,20 @@ public class GetShiftPlansQueryHandler : IRequestHandler(); - shift.Days.OrderBy(d=>d).ToList().ForEach(d => + shift.Days.OrderBy(d => d).ToList().ForEach(d => { - if(d==DayOfWeek.Saturday) - shiftDays.Insert(0,d); - else{ - shiftDays.Add(d);} + if (d == DayOfWeek.Saturday) + shiftDays.Insert(0, d); + else + { + shiftDays.Add(d); + } }); shift.Days = shiftDays; diff --git a/Brizco.Repository/RepositoryConfig.cs b/Brizco.Repository/RepositoryConfig.cs index a539c6a..3c446c0 100644 --- a/Brizco.Repository/RepositoryConfig.cs +++ b/Brizco.Repository/RepositoryConfig.cs @@ -14,6 +14,7 @@ public static class RepositoryConfig { identityDbInitialize.Initialize(); await identityDbInitialize.SeedDate(); + await identityDbInitialize.Refactor(); } } } diff --git a/Brizco.Repository/Services/Contracts/IDbInitializerService.cs b/Brizco.Repository/Services/Contracts/IDbInitializerService.cs index d650264..91554a7 100644 --- a/Brizco.Repository/Services/Contracts/IDbInitializerService.cs +++ b/Brizco.Repository/Services/Contracts/IDbInitializerService.cs @@ -8,4 +8,5 @@ public interface IDbInitializerService : IScopedDependency void Initialize(); Task SeedDate(bool force = false); Task SeedRoles(); + Task Refactor(); } \ No newline at end of file diff --git a/Brizco.Repository/Services/DbInitializerService.cs b/Brizco.Repository/Services/DbInitializerService.cs index bd0e11c..1a9877d 100644 --- a/Brizco.Repository/Services/DbInitializerService.cs +++ b/Brizco.Repository/Services/DbInitializerService.cs @@ -89,54 +89,44 @@ public class DbInitializerService : IDbInitializerService foreach (var claim in ApplicationClaims.AllClaims) await _roleManager.AddClaimAsync(managerRole, claim); } + } + public async Task Refactor() + { //var roles = await _roleManager.Roles.ToListAsync(); //foreach (var role in roles) //{ - // if (role.EnglishName == "Manager") + // if (role.EnglishName == ApplicationRoles.Manager) // { // var claims = await _roleManager.GetClaimsAsync(role); - + // foreach (var claim in claims) + // await _roleManager.RemoveClaimAsync(role,claim); // foreach (var claim in ApplicationClaims.ManagerClaims) - // { - // if(!claims.Contains(claim)) // await _roleManager.AddClaimAsync(role, claim); - // } // } - // else if (role.EnglishName == "ViewerOwner") + // if (role.EnglishName == ApplicationRoles.ViewerOwner) // { - // var claims = await _roleManager.GetClaimsAsync(role); - + // foreach (var claim in claims) + // await _roleManager.RemoveClaimAsync(role, claim); // foreach (var claim in ApplicationClaims.ViewerOwnerClaims) - // { - // if (!claims.Contains(claim)) - // await _roleManager.AddClaimAsync(role, claim); - // } + // await _roleManager.AddClaimAsync(role, claim); // } - // else if (role.EnglishName == "SuperVisor") + // if (role.EnglishName == ApplicationRoles.SuperVisor) // { - - // var claims = await _roleManager.GetClaimsAsync(role); - + // foreach (var claim in claims) + // await _roleManager.RemoveClaimAsync(role, claim); // foreach (var claim in ApplicationClaims.SuperVisorClaims) - // { - // if (!claims.Contains(claim)) - // await _roleManager.AddClaimAsync(role, claim); - // } + // await _roleManager.AddClaimAsync(role, claim); // } - // else if (role.EnglishName == "Staff") + // if (role.EnglishName == ApplicationRoles.Staff) // { - - // var claims = await _roleManager.GetClaimsAsync(role); - + // foreach (var claim in claims) + // await _roleManager.RemoveClaimAsync(role, claim); // foreach (var claim in ApplicationClaims.StaffClaims) - // { - // if (!claims.Contains(claim)) - // await _roleManager.AddClaimAsync(role, claim); - // } + // await _roleManager.AddClaimAsync(role, claim); // } //} }