From 56ee887fab508dbc16643c88a2f4442ba1da0e78 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Sat, 18 Nov 2023 22:23:23 +0330 Subject: [PATCH] add version 0.1.2.0 complete change db for position and section , complete createing task --- .version | 2 +- Brizco.Api/Brizco.Api.csproj | 4 +- Brizco.Core/EntityServices/UserService.cs | 10 +- .../Commands/ActivityCommands.cs | 4 + .../Commands/PositionCommands.cs | 7 +- .../CommandQueries/Commands/ShiftCommands.cs | 4 +- .../CommandQueries/Commands/TaskCommands.cs | 8 +- .../CommandQueries/Queries/ShiftQueries.cs | 6 +- Brizco.Domain/Dtos/LargDtos/ShiftLDto.cs | 3 +- Brizco.Domain/Dtos/LargDtos/TaskLDto.cs | 5 + .../Dtos/RequestDtos/UserActionRequestDto.cs | 1 - .../Dtos/SmallDtos/ShiftRoutineSDto.cs | 7 + Brizco.Domain/Dtos/SmallDtos/TaskDaySDto.cs | 8 + .../Dtos/SmallDtos/TaskRoutineSDto.cs | 7 + Brizco.Domain/Dtos/SmallDtos/TaskSDto.cs | 1 + .../Entities/Complex/Aggregate.Complex.cs | 8 +- .../Entities/Complex/PositionUser.cs | 6 +- .../Entities/Shift/Aggregate.Shift.cs | 7 + Brizco.Domain/Entities/Shift/ShiftRoutine.cs | 8 +- Brizco.Domain/Entities/Task/Activity.cs | 10 +- Brizco.Domain/Entities/Task/Aggregate.Task.cs | 27 +- Brizco.Domain/Entities/Task/Task.cs | 9 +- Brizco.Domain/Entities/Task/TaskDay.cs | 2 + Brizco.Domain/Enums/TaskScheduleType.cs | 11 + Brizco.Domain/Mappers/ShiftMapper.g.cs | 267 +++++++--- Brizco.Domain/Mappers/ShiftRoutineMapper.g.cs | 63 +++ Brizco.Domain/Mappers/TaskDayMapper.g.cs | 69 +++ Brizco.Domain/Mappers/TaskMapper.g.cs | 470 ++++++++++++++---- Brizco.Domain/Mappers/TaskRoutineMapper.g.cs | 63 +++ Brizco.Domain/MapsterRegister.cs | 3 + .../Activity/CreateActivityCommandHandler.cs | 14 +- .../Activity/UpdateActivityCommandHandler.cs | 3 +- .../CreatePositionUserCommandHandler.cs | 2 +- .../UpdatePositionUserCommandHandler.cs | 2 +- .../Section/DeleteSectionCommandHandler.cs | 10 +- .../Shift/CreateShiftCommandHandler.cs | 6 +- .../Handlers/Shift/GetShiftQueryHandler.cs | 10 +- .../Handlers/Shift/GetShiftsQueryHandler.cs | 2 +- .../Shift/UpdateShiftCommandHandler.cs | 27 +- .../Handlers/Task/CreateTaskCommandHandler.cs | 16 +- .../Handlers/Task/UpdateTaskCommandHandler.cs | 84 +++- ...ner.cs => 20231116063836_init.Designer.cs} | 34 +- ...3110204_init.cs => 20231116063836_init.cs} | 257 +++++----- .../ApplicationContextModelSnapshot.cs | 32 ++ 44 files changed, 1214 insertions(+), 385 deletions(-) create mode 100644 Brizco.Domain/Dtos/SmallDtos/ShiftRoutineSDto.cs create mode 100644 Brizco.Domain/Dtos/SmallDtos/TaskDaySDto.cs create mode 100644 Brizco.Domain/Dtos/SmallDtos/TaskRoutineSDto.cs create mode 100644 Brizco.Domain/Enums/TaskScheduleType.cs create mode 100644 Brizco.Domain/Mappers/TaskDayMapper.g.cs rename Brizco.Repository/Migrations/{20231113110204_init.Designer.cs => 20231116063836_init.Designer.cs} (97%) rename Brizco.Repository/Migrations/{20231113110204_init.cs => 20231116063836_init.cs} (97%) diff --git a/.version b/.version index 9d3e2f6..57d102a 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.1.1.0 \ No newline at end of file +0.1.2.0 \ No newline at end of file diff --git a/Brizco.Api/Brizco.Api.csproj b/Brizco.Api/Brizco.Api.csproj index 70bd10b..ecbbf87 100644 --- a/Brizco.Api/Brizco.Api.csproj +++ b/Brizco.Api/Brizco.Api.csproj @@ -6,8 +6,8 @@ enable Linux ..\docker-compose.dcproj - 0.1.1.0 - 0.1.1.0 + 0.1.2.0 + 0.1.2.0 diff --git a/Brizco.Core/EntityServices/UserService.cs b/Brizco.Core/EntityServices/UserService.cs index fdbe4df..1013d90 100644 --- a/Brizco.Core/EntityServices/UserService.cs +++ b/Brizco.Core/EntityServices/UserService.cs @@ -114,12 +114,6 @@ public class UserService : IUserService if (role != null) dto.RoleIds.Add(role.Id); } - - var positionUser = await _repositoryWrapper.SetRepository() - .TableNoTracking - .FirstOrDefaultAsync(f => f.ApplicationUserId == userId); - if (positionUser != null) - dto.PositionId = positionUser.PositionId; return dto; } @@ -168,7 +162,6 @@ public class UserService : IUserService throw new AppException(string.Join('|', result.Errors.Select(e => e.Description))); } - await _sender.Send(new CreatePositionUserCommand(request.PositionId, user.Id), cancellationToken); await _sender.Send(new CreateComplexUserCommand(complexId, user.Id, request.RoleIds), cancellationToken); return user; } @@ -207,8 +200,7 @@ public class UserService : IUserService if (!addPassResult.Succeeded) throw new AppException(string.Join('|', addPassResult.Errors.Select(e => e.Description))); } - - await _sender.Send(new UpdatePositionUserCommand(request.PositionId, user.Id), cancellationToken); + await _sender.Send(new UpdateComplexUserCommand(user.Id, complexId, request.RoleIds), cancellationToken); return true; } diff --git a/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs b/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs index d05cb4f..0a6711c 100644 --- a/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs +++ b/Brizco.Domain/CommandQueries/Commands/ActivityCommands.cs @@ -12,6 +12,8 @@ public sealed record CreateActivityCommand( bool HasDisposed, int Amount, PurchaseAmountType AmountType, + TaskScheduleType ScheduleType, + List Routines, List Shifts, List Positions) : IRequest; @@ -27,6 +29,8 @@ public sealed record UpdateActivityCommand(Guid Id, bool HasDisposed, int Amount, PurchaseAmountType AmountType, + TaskScheduleType ScheduleType, + List Routines, List Shifts, List Positions) : IRequest; diff --git a/Brizco.Domain/CommandQueries/Commands/PositionCommands.cs b/Brizco.Domain/CommandQueries/Commands/PositionCommands.cs index 1b1c933..27c763e 100644 --- a/Brizco.Domain/CommandQueries/Commands/PositionCommands.cs +++ b/Brizco.Domain/CommandQueries/Commands/PositionCommands.cs @@ -9,8 +9,11 @@ public sealed record UpdatePositionCommand(Guid Id, string Title, string Descrip public sealed record DeletePositionCommand(Guid Id) : IRequest; -public sealed record CreatePositionUserCommand(Guid PositionId,Guid UserId) +public sealed record CreatePositionUserCommand(Guid PositionId,Guid UserId, Guid ShiftPlanId) : IRequest; -public sealed record UpdatePositionUserCommand(Guid PositionId, Guid UserId) +public sealed record UpdatePositionUserCommand(Guid PositionId, Guid UserId, Guid ShiftPlanId) + : IRequest; + +public sealed record DeletePositionUserCommand(Guid PositionId, Guid UserId, Guid ShiftPlanId) : IRequest; \ No newline at end of file diff --git a/Brizco.Domain/CommandQueries/Commands/ShiftCommands.cs b/Brizco.Domain/CommandQueries/Commands/ShiftCommands.cs index fc5a610..fe10666 100644 --- a/Brizco.Domain/CommandQueries/Commands/ShiftCommands.cs +++ b/Brizco.Domain/CommandQueries/Commands/ShiftCommands.cs @@ -2,10 +2,10 @@ namespace Brizco.Domain.CommandQueries.Commands; -public sealed record CreateShiftCommand(string Title, TimeSpan StartAt, TimeSpan EndAt, string Description, List DayOfWeeks) +public sealed record CreateShiftCommand(string Title, TimeSpan StartAt, TimeSpan EndAt, string Description, List DayOfWeeks, List Routines) : IRequest; -public sealed record UpdateShiftCommand(Guid Id,string Title, TimeSpan StartAt, TimeSpan EndAt, string Description, List DayOfWeeks) +public sealed record UpdateShiftCommand(Guid Id,string Title, TimeSpan StartAt, TimeSpan EndAt, string Description, List DayOfWeeks, List Routines) : IRequest; public sealed record DeleteShiftCommand(Guid Id) diff --git a/Brizco.Domain/CommandQueries/Commands/TaskCommands.cs b/Brizco.Domain/CommandQueries/Commands/TaskCommands.cs index ac63dfb..ca7baa9 100644 --- a/Brizco.Domain/CommandQueries/Commands/TaskCommands.cs +++ b/Brizco.Domain/CommandQueries/Commands/TaskCommands.cs @@ -4,10 +4,12 @@ public sealed record CreateTaskCommand(TaskType Type, string Title, string Description, bool IsDisposable, -DateTime SetFor, +long SetFor, bool HasDisposed, int Amount, PurchaseAmountType AmountType, +TaskScheduleType ScheduleType, +List Routines, List Shifts, List Positions, List Days) : IRequest; @@ -17,10 +19,12 @@ public sealed record UpdateTaskCommand(Guid Id, string Title, string Description, bool IsDisposable, - DateTime SetFor, + long SetFor, bool HasDisposed, int Amount, PurchaseAmountType AmountType, + TaskScheduleType ScheduleType, + List Routines, List Shifts, List Positions, List Days) : IRequest; diff --git a/Brizco.Domain/CommandQueries/Queries/ShiftQueries.cs b/Brizco.Domain/CommandQueries/Queries/ShiftQueries.cs index 4c4abde..c33f490 100644 --- a/Brizco.Domain/CommandQueries/Queries/ShiftQueries.cs +++ b/Brizco.Domain/CommandQueries/Queries/ShiftQueries.cs @@ -1,7 +1,7 @@ namespace Brizco.Domain.CommandQueries.Queries; -public sealed record GetShiftsQuery(int page = 0) : +public sealed record GetShiftsQuery(int Page = 0) : IRequest>; -public sealed record GetShiftQuery(Guid id) : - IRequest; \ No newline at end of file +public sealed record GetShiftQuery(Guid Id) : + IRequest; \ No newline at end of file diff --git a/Brizco.Domain/Dtos/LargDtos/ShiftLDto.cs b/Brizco.Domain/Dtos/LargDtos/ShiftLDto.cs index dfca844..09b3fe4 100644 --- a/Brizco.Domain/Dtos/LargDtos/ShiftLDto.cs +++ b/Brizco.Domain/Dtos/LargDtos/ShiftLDto.cs @@ -7,5 +7,6 @@ public class ShiftLDto : BaseDto public TimeSpan StartAt { get; set; } public TimeSpan EndAt { get; set; } public Guid ComplexId { get; set; } - public List Days { get; set; } = new(); + public List Days { get; set; } = new(); + public List Routines { get; set; } = new(); } \ No newline at end of file diff --git a/Brizco.Domain/Dtos/LargDtos/TaskLDto.cs b/Brizco.Domain/Dtos/LargDtos/TaskLDto.cs index b70c5a1..537579a 100644 --- a/Brizco.Domain/Dtos/LargDtos/TaskLDto.cs +++ b/Brizco.Domain/Dtos/LargDtos/TaskLDto.cs @@ -10,6 +10,7 @@ public class TaskLDto : BaseDto public bool IsDisposable { get; set; } public DateTime SetFor { get; set; } public bool HasDisposed { get; set; } + public TaskScheduleType ScheduleType { get; set; } public int Amount { get; set; } @@ -20,4 +21,8 @@ public class TaskLDto : BaseDto public List Shifts { get; set; } = new(); public List Positions { get; set; } = new(); + + public List Days { get; internal set; } = new(); + + public List Routines { get; internal set; } = new(); } \ No newline at end of file diff --git a/Brizco.Domain/Dtos/RequestDtos/UserActionRequestDto.cs b/Brizco.Domain/Dtos/RequestDtos/UserActionRequestDto.cs index 4a21d12..dabb287 100644 --- a/Brizco.Domain/Dtos/RequestDtos/UserActionRequestDto.cs +++ b/Brizco.Domain/Dtos/RequestDtos/UserActionRequestDto.cs @@ -11,7 +11,6 @@ public class UserActionRequestDto public string NationalId { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; public List RoleIds { get; set; } = new(); - public Guid PositionId { get; set; } public string SelectedRoleName { get; set; } = string.Empty; diff --git a/Brizco.Domain/Dtos/SmallDtos/ShiftRoutineSDto.cs b/Brizco.Domain/Dtos/SmallDtos/ShiftRoutineSDto.cs new file mode 100644 index 0000000..d68393c --- /dev/null +++ b/Brizco.Domain/Dtos/SmallDtos/ShiftRoutineSDto.cs @@ -0,0 +1,7 @@ +namespace Brizco.Domain.Dtos.SmallDtos; + +public class ShiftRoutineSDto : BaseDto +{ + public Guid RoutineId { get; set; } + public Guid ShiftId { get; set; } +} \ No newline at end of file diff --git a/Brizco.Domain/Dtos/SmallDtos/TaskDaySDto.cs b/Brizco.Domain/Dtos/SmallDtos/TaskDaySDto.cs new file mode 100644 index 0000000..07d1dd5 --- /dev/null +++ b/Brizco.Domain/Dtos/SmallDtos/TaskDaySDto.cs @@ -0,0 +1,8 @@ +namespace Brizco.Domain.Dtos.SmallDtos; + +public class TaskDaySDto : BaseDto +{ + public DayOfWeek DayOfWeek { get; internal set; } + + public Guid TaskId { get; internal set; } +} \ No newline at end of file diff --git a/Brizco.Domain/Dtos/SmallDtos/TaskRoutineSDto.cs b/Brizco.Domain/Dtos/SmallDtos/TaskRoutineSDto.cs new file mode 100644 index 0000000..13c3156 --- /dev/null +++ b/Brizco.Domain/Dtos/SmallDtos/TaskRoutineSDto.cs @@ -0,0 +1,7 @@ +namespace Brizco.Domain.Dtos.SmallDtos; + +public class TaskRoutineSDto : BaseDto +{ + public Guid TaskId { get; set; } + public Guid RoutineId { get; set; } +} \ No newline at end of file diff --git a/Brizco.Domain/Dtos/SmallDtos/TaskSDto.cs b/Brizco.Domain/Dtos/SmallDtos/TaskSDto.cs index fe95cfa..c0bf67e 100644 --- a/Brizco.Domain/Dtos/SmallDtos/TaskSDto.cs +++ b/Brizco.Domain/Dtos/SmallDtos/TaskSDto.cs @@ -9,6 +9,7 @@ public class TaskSDto : BaseDto public DateTime SetFor { get; set; } public bool HasDisposed { get; set; } public Guid ComplexId { get; set; } + public TaskScheduleType ScheduleType { get; set; } public int Amount { get; set; } diff --git a/Brizco.Domain/Entities/Complex/Aggregate.Complex.cs b/Brizco.Domain/Entities/Complex/Aggregate.Complex.cs index 6e051d9..7d512ba 100644 --- a/Brizco.Domain/Entities/Complex/Aggregate.Complex.cs +++ b/Brizco.Domain/Entities/Complex/Aggregate.Complex.cs @@ -51,9 +51,9 @@ public partial class Position return new Position(name, description, complexId, sectionId); } - public PositionUser AddUser(Guid userId) + public PositionUser AddUser(Guid userId , Guid shiftPlanId) { - var positionUser = PositionUser.Create(this.Id, userId); + var positionUser = PositionUser.Create(this.Id, userId, shiftPlanId); this.Users.Add(positionUser); return positionUser; } @@ -61,8 +61,8 @@ public partial class Position public partial class PositionUser { - public static PositionUser Create(Guid positionId, Guid userId) + public static PositionUser Create(Guid positionId, Guid userId, Guid shiftPlanId) { - return new PositionUser(positionId, userId); + return new PositionUser(positionId, userId, shiftPlanId); } } diff --git a/Brizco.Domain/Entities/Complex/PositionUser.cs b/Brizco.Domain/Entities/Complex/PositionUser.cs index 190701f..0ff135f 100644 --- a/Brizco.Domain/Entities/Complex/PositionUser.cs +++ b/Brizco.Domain/Entities/Complex/PositionUser.cs @@ -9,9 +9,10 @@ public partial class PositionUser : ApiEntity { } - public PositionUser(Guid positionId,Guid applicationUserId) + public PositionUser(Guid positionId,Guid applicationUserId ,Guid shiftPlanId) { ApplicationUserId = applicationUserId; + ShiftPlanId = shiftPlanId; PositionId = positionId; } @@ -20,4 +21,7 @@ public partial class PositionUser : ApiEntity public Guid PositionId { get; set; } public Position? Position { get; set; } + + public Guid ShiftPlanId { get; set; } + public ShiftPlan? ShiftPlan { get; set; } } \ No newline at end of file diff --git a/Brizco.Domain/Entities/Shift/Aggregate.Shift.cs b/Brizco.Domain/Entities/Shift/Aggregate.Shift.cs index 8a8379b..c3997a5 100644 --- a/Brizco.Domain/Entities/Shift/Aggregate.Shift.cs +++ b/Brizco.Domain/Entities/Shift/Aggregate.Shift.cs @@ -20,6 +20,13 @@ public partial class Shift Plans.Add(plan); return plan; } + + public ShiftRoutine AddRoutine(Guid routineId) + { + var routine = new ShiftRoutine(routineId, this.Id); + Routines.Add(routine); + return routine; + } } public partial class ShiftPlan diff --git a/Brizco.Domain/Entities/Shift/ShiftRoutine.cs b/Brizco.Domain/Entities/Shift/ShiftRoutine.cs index 0ed79b0..67a8fba 100644 --- a/Brizco.Domain/Entities/Shift/ShiftRoutine.cs +++ b/Brizco.Domain/Entities/Shift/ShiftRoutine.cs @@ -13,9 +13,9 @@ public class ShiftRoutine : ApiEntity RoutineId = routineId; ShiftId = shiftId; } - public Guid RoutineId { get; set; } - public Routine.Routine? Routine { get; set; } + public Guid RoutineId { get; internal set; } + public Routine.Routine? Routine { get; internal set; } - public Guid ShiftId { get; set; } - public Shift? Shift { get; set; } + public Guid ShiftId { get; internal set; } + public Shift? Shift { get; internal set; } } \ No newline at end of file diff --git a/Brizco.Domain/Entities/Task/Activity.cs b/Brizco.Domain/Entities/Task/Activity.cs index 3b1067c..056d5ba 100644 --- a/Brizco.Domain/Entities/Task/Activity.cs +++ b/Brizco.Domain/Entities/Task/Activity.cs @@ -1,4 +1,4 @@ -using System; +using Brizco.Domain.Entities.User; namespace Brizco.Domain.Entities.Task; @@ -22,15 +22,19 @@ public partial class Activity : Task PurchaseAmountType amountType, string title, string description, - Guid complexId) : base( - type, isDisposable, setFor, hasDisposed, amount, amountType, title, description, complexId) + Guid complexId, + TaskScheduleType scheduleType) : base( + type, isDisposable, setFor, hasDisposed, amount, amountType, title, description, complexId, scheduleType) { Status = status; DoneAt = doneAt; PerformanceDescription = performanceDescription; } + public ActivityStatus Status { get; internal set; } public DateTime DoneAt { get; internal set; } public bool IsDone { get; internal set; } public string PerformanceDescription { get; internal set; } = string.Empty; + public Guid UserId { get; internal set; } + public ApplicationUser? User { get; internal set; } } \ No newline at end of file diff --git a/Brizco.Domain/Entities/Task/Aggregate.Task.cs b/Brizco.Domain/Entities/Task/Aggregate.Task.cs index db1c6bc..3493928 100644 --- a/Brizco.Domain/Entities/Task/Aggregate.Task.cs +++ b/Brizco.Domain/Entities/Task/Aggregate.Task.cs @@ -1,4 +1,5 @@ -using Brizco.Domain.Entities.Routine; +using Brizco.Common.Models.Exception; +using Brizco.Domain.Entities.Routine; namespace Brizco.Domain.Entities.Task; @@ -15,8 +16,13 @@ public partial class Task bool hasDisposed, int amount, PurchaseAmountType amountType, - Guid complexId) + Guid complexId, + TaskScheduleType scheduleType) { + if (scheduleType == TaskScheduleType.Custom && setFor == DateTime.MinValue) + throw new AppException("اگر تکرار وظیفه یک روز خاص باشد باید ان روز را انتخاب کنید"); + if (scheduleType == TaskScheduleType.Custom) + isDisposable = true; return new Task( type, isDisposable, @@ -26,7 +32,8 @@ public partial class Task amountType, title, description, - complexId); + complexId, + scheduleType); } @@ -58,13 +65,13 @@ public partial class Task { foreach (var positionId in positionIds) { - var position = new TaskPosition(Id, positionId); + var position = new TaskPosition(positionId,Id); Positions.Add(position); } } public TaskPosition AddPosition(Guid positionId) { - var position = new TaskPosition(Id, positionId); + var position = new TaskPosition(positionId,Id); Positions.Add(position); return position; } @@ -75,13 +82,13 @@ public partial class Task { foreach (var routineId in routineIds) { - var routine = new TaskRoutine(Id, routineId); + var routine = new TaskRoutine(routineId,Id); Routines.Add(routine); } } public TaskRoutine AddRoutine(Guid routineId) { - var routine = new TaskRoutine(Id, routineId); + var routine = new TaskRoutine(routineId,Id); Routines.Add(routine); return routine; } @@ -102,7 +109,8 @@ public partial class Activity bool hasDisposed, int amount, PurchaseAmountType amountType, - Guid complexId) + Guid complexId, + TaskScheduleType scheduleType) { return new Activity( status, @@ -116,7 +124,8 @@ public partial class Activity amountType, title, description, - complexId); + complexId, + scheduleType); } public void DoneActivity() diff --git a/Brizco.Domain/Entities/Task/Task.cs b/Brizco.Domain/Entities/Task/Task.cs index f501a29..4b2faba 100644 --- a/Brizco.Domain/Entities/Task/Task.cs +++ b/Brizco.Domain/Entities/Task/Task.cs @@ -19,7 +19,8 @@ public partial class Task : ApiEntity PurchaseAmountType amountType, string title, string description, - Guid complexId) + Guid complexId, + TaskScheduleType scheduleType) { Type = type; IsDisposable = isDisposable; @@ -30,6 +31,7 @@ public partial class Task : ApiEntity Title = title; Description = description; ComplexId = complexId; + ScheduleType = scheduleType; } public TaskType Type { get; internal set; } @@ -38,6 +40,7 @@ public partial class Task : ApiEntity public bool IsDisposable { get; internal set; } public DateTime SetFor { get; internal set; } public bool HasDisposed { get; internal set; } + public TaskScheduleType ScheduleType { get; set; } public Guid ComplexId { get; set; } public Complex.Complex? Complex { get; set; } @@ -47,12 +50,12 @@ public partial class Task : ApiEntity public PurchaseAmountType AmountType { get; internal set; } - public List Shifts { get; internal set; } = new(); public List Days { get; internal set; } = new(); + public List Routines { get; internal set; } = new(); + public List Positions { get; internal set; } = new(); - public List Routines { get; internal set; } = new(); } diff --git a/Brizco.Domain/Entities/Task/TaskDay.cs b/Brizco.Domain/Entities/Task/TaskDay.cs index 49b335b..dda3a6a 100644 --- a/Brizco.Domain/Entities/Task/TaskDay.cs +++ b/Brizco.Domain/Entities/Task/TaskDay.cs @@ -1,5 +1,7 @@ namespace Brizco.Domain.Entities.Task; +[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)] +[GenerateMapper] public class TaskDay : ApiEntity { public TaskDay() diff --git a/Brizco.Domain/Enums/TaskScheduleType.cs b/Brizco.Domain/Enums/TaskScheduleType.cs new file mode 100644 index 0000000..e3c6745 --- /dev/null +++ b/Brizco.Domain/Enums/TaskScheduleType.cs @@ -0,0 +1,11 @@ +namespace Brizco.Domain.Enums; + +public enum TaskScheduleType +{ + [Display(Name = "روزانه")] + Daily, + [Display(Name = "هفتگی")] + Weekly, + [Display(Name = "روز مشخص")] + Custom +} \ No newline at end of file diff --git a/Brizco.Domain/Mappers/ShiftMapper.g.cs b/Brizco.Domain/Mappers/ShiftMapper.g.cs index 682d9ec..f9e8923 100644 --- a/Brizco.Domain/Mappers/ShiftMapper.g.cs +++ b/Brizco.Domain/Mappers/ShiftMapper.g.cs @@ -106,88 +106,97 @@ namespace Brizco.Domain.Mappers EndAt = p18.EndAt, Description = p18.Description, ComplexId = p18.ComplexId, + Complex = new Complex() {Id = p18.ComplexId}, Days = funcMain7(p18.Days), + Routines = funcMain8(p18.Routines), Id = p18.Id }; } - public static Shift AdaptTo(this ShiftLDto p20, Shift p21) + public static Shift AdaptTo(this ShiftLDto p21, Shift p22) { - if (p20 == null) + if (p21 == null) { return null; } - Shift result = p21 ?? new Shift(); + Shift result = p22 ?? new Shift(); - result.Title = p20.Title; - result.StartAt = p20.StartAt; - result.EndAt = p20.EndAt; - result.Description = p20.Description; - result.ComplexId = p20.ComplexId; - result.Days = funcMain8(p20.Days, result.Days); - result.Id = p20.Id; + result.Title = p21.Title; + result.StartAt = p21.StartAt; + result.EndAt = p21.EndAt; + result.Description = p21.Description; + result.ComplexId = p21.ComplexId; + result.Complex = funcMain9(new Never(), result.Complex, p21); + result.Days = funcMain10(p21.Days, result.Days); + result.Routines = funcMain11(p21.Routines, result.Routines); + result.Id = p21.Id; return result; } - public static Expression> ProjectLDtoToShift => p24 => new Shift() + public static Expression> ProjectLDtoToShift => p29 => new Shift() { - Title = p24.Title, - StartAt = p24.StartAt, - EndAt = p24.EndAt, - Description = p24.Description, - ComplexId = p24.ComplexId, - Days = p24.Days.Select(p25 => new ShiftDay() + Title = p29.Title, + StartAt = p29.StartAt, + EndAt = p29.EndAt, + Description = p29.Description, + ComplexId = p29.ComplexId, + Complex = new Complex() {Id = p29.ComplexId}, + Days = p29.Days.Select(p30 => new ShiftDay() {}).ToList(), + Routines = p29.Routines.Select(p31 => new ShiftRoutine() { - DayOfWeek = p25.DayOfWeek, - ShiftId = p25.ShiftId, - Id = p25.Id - }).ToList(), - Id = p24.Id + RoutineId = p31.RoutineId, + ShiftId = p31.ShiftId, + Id = p31.Id + }).ToList(), + Id = p29.Id }; - public static ShiftLDto AdaptToLDto(this Shift p26) + public static ShiftLDto AdaptToLDto(this Shift p32) { - return p26 == null ? null : new ShiftLDto() + return p32 == null ? null : new ShiftLDto() { - Title = p26.Title, - Description = p26.Description, - StartAt = p26.StartAt, - EndAt = p26.EndAt, - ComplexId = p26.ComplexId, - Days = funcMain9(p26.Days), - Id = p26.Id + Title = p32.Title, + Description = p32.Description, + StartAt = p32.StartAt, + EndAt = p32.EndAt, + ComplexId = p32.ComplexId, + Days = funcMain12(p32.Days.Select(funcMain13).ToList()), + Routines = funcMain14(p32.Routines), + Id = p32.Id }; } - public static ShiftLDto AdaptTo(this Shift p28, ShiftLDto p29) + public static ShiftLDto AdaptTo(this Shift p35, ShiftLDto p36) { - if (p28 == null) + if (p35 == null) { return null; } - ShiftLDto result = p29 ?? new ShiftLDto(); + ShiftLDto result = p36 ?? new ShiftLDto(); - result.Title = p28.Title; - result.Description = p28.Description; - result.StartAt = p28.StartAt; - result.EndAt = p28.EndAt; - result.ComplexId = p28.ComplexId; - result.Days = funcMain10(p28.Days, result.Days); - result.Id = p28.Id; + result.Title = p35.Title; + result.Description = p35.Description; + result.StartAt = p35.StartAt; + result.EndAt = p35.EndAt; + result.ComplexId = p35.ComplexId; + result.Days = funcMain15(p35.Days.Select(funcMain13).ToList(), result.Days); + result.Routines = funcMain16(p35.Routines, result.Routines); + result.Id = p35.Id; return result; } - public static Expression> ProjectToLDto => p32 => new ShiftLDto() + public static Expression> ProjectToLDto => p41 => new ShiftLDto() { - Title = p32.Title, - Description = p32.Description, - StartAt = p32.StartAt, - EndAt = p32.EndAt, - ComplexId = p32.ComplexId, - Days = p32.Days.Select(p33 => new ShiftDaySDto() + Title = p41.Title, + Description = p41.Description, + StartAt = p41.StartAt, + EndAt = p41.EndAt, + ComplexId = p41.ComplexId, + Days = p41.Days.Select(d => d.DayOfWeek).ToList(), + Routines = p41.Routines.Select(p42 => new ShiftRoutineSDto() { - DayOfWeek = p33.DayOfWeek, - ShiftId = p33.ShiftId, - Id = p33.Id - }).ToList(), - Id = p32.Id + RoutineId = p42.RoutineId, + ShiftId = p42.ShiftId, + Id = p42.Id + }).ToList(), + Id = p41.Id }; private static List funcMain1(List p2) @@ -288,7 +297,7 @@ namespace Brizco.Domain.Mappers } - private static List funcMain7(List p19) + private static List funcMain7(List p19) { if (p19 == null) { @@ -301,36 +310,31 @@ namespace Brizco.Domain.Mappers while (i < len) { - ShiftDaySDto item = p19[i]; - result.Add(item == null ? null : new ShiftDay() - { - DayOfWeek = item.DayOfWeek, - ShiftId = item.ShiftId, - Id = item.Id - }); + DayOfWeek item = p19[i]; + result.Add(new ShiftDay() {}); i++; } return result; } - private static List funcMain8(List p22, List p23) + private static List funcMain8(List p20) { - if (p22 == null) + if (p20 == null) { return null; } - List result = new List(p22.Count); + List result = new List(p20.Count); int i = 0; - int len = p22.Count; + int len = p20.Count; while (i < len) { - ShiftDaySDto item = p22[i]; - result.Add(item == null ? null : new ShiftDay() + ShiftRoutineSDto item = p20[i]; + result.Add(item == null ? null : new ShiftRoutine() { - DayOfWeek = item.DayOfWeek, + RoutineId = item.RoutineId, ShiftId = item.ShiftId, Id = item.Id }); @@ -340,23 +344,53 @@ namespace Brizco.Domain.Mappers } - private static List funcMain9(List p27) + private static Complex funcMain9(Never p23, Complex p24, ShiftLDto p21) + { + Complex result = p24 ?? new Complex(); + + result.Id = p21.ComplexId; + return result; + + } + + private static List funcMain10(List p25, List p26) + { + if (p25 == null) + { + return null; + } + List result = new List(p25.Count); + + int i = 0; + int len = p25.Count; + + while (i < len) + { + DayOfWeek item = p25[i]; + result.Add(new ShiftDay() {}); + i++; + } + return result; + + } + + private static List funcMain11(List p27, List p28) { if (p27 == null) { return null; } - List result = new List(p27.Count); + List result = new List(p27.Count); int i = 0; int len = p27.Count; while (i < len) { - ShiftDay item = p27[i]; - result.Add(item == null ? null : new ShiftDaySDto() + ShiftRoutineSDto item = p27[i]; + result.Add(item == null ? null : new ShiftRoutine() { - DayOfWeek = item.DayOfWeek, + RoutineId = item.RoutineId, ShiftId = item.ShiftId, Id = item.Id }); @@ -366,23 +400,96 @@ namespace Brizco.Domain.Mappers } - private static List funcMain10(List p30, List p31) + private static List funcMain12(List p33) { - if (p30 == null) + if (p33 == null) { return null; } - List result = new List(p30.Count); + List result = new List(p33.Count); int i = 0; - int len = p30.Count; + int len = p33.Count; while (i < len) { - ShiftDay item = p30[i]; - result.Add(item == null ? null : new ShiftDaySDto() + DayOfWeek item = p33[i]; + result.Add(item); + i++; + } + return result; + + } + + private static DayOfWeek funcMain13(ShiftDay d) + { + return d.DayOfWeek; + } + + private static List funcMain14(List p34) + { + if (p34 == null) + { + return null; + } + List result = new List(p34.Count); + + int i = 0; + int len = p34.Count; + + while (i < len) + { + ShiftRoutine item = p34[i]; + result.Add(item == null ? null : new ShiftRoutineSDto() { - DayOfWeek = item.DayOfWeek, + RoutineId = item.RoutineId, + ShiftId = item.ShiftId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain15(List p37, List p38) + { + if (p37 == null) + { + return null; + } + List result = new List(p37.Count); + + int i = 0; + int len = p37.Count; + + while (i < len) + { + DayOfWeek item = p37[i]; + result.Add(item); + i++; + } + return result; + + } + + private static List funcMain16(List p39, List p40) + { + if (p39 == null) + { + return null; + } + List result = new List(p39.Count); + + int i = 0; + int len = p39.Count; + + while (i < len) + { + ShiftRoutine item = p39[i]; + result.Add(item == null ? null : new ShiftRoutineSDto() + { + RoutineId = item.RoutineId, ShiftId = item.ShiftId, Id = item.Id }); diff --git a/Brizco.Domain/Mappers/ShiftRoutineMapper.g.cs b/Brizco.Domain/Mappers/ShiftRoutineMapper.g.cs index 913f999..11d91f1 100644 --- a/Brizco.Domain/Mappers/ShiftRoutineMapper.g.cs +++ b/Brizco.Domain/Mappers/ShiftRoutineMapper.g.cs @@ -1,6 +1,69 @@ +using System; +using System.Linq.Expressions; +using Brizco.Domain.Dtos.SmallDtos; +using Brizco.Domain.Entities.Shift; + namespace Brizco.Domain.Mappers { public static partial class ShiftRoutineMapper { + public static ShiftRoutine AdaptToShiftRoutine(this ShiftRoutineSDto p1) + { + return p1 == null ? null : new ShiftRoutine() + { + RoutineId = p1.RoutineId, + ShiftId = p1.ShiftId, + Id = p1.Id + }; + } + public static ShiftRoutine AdaptTo(this ShiftRoutineSDto p2, ShiftRoutine p3) + { + if (p2 == null) + { + return null; + } + ShiftRoutine result = p3 ?? new ShiftRoutine(); + + result.RoutineId = p2.RoutineId; + result.ShiftId = p2.ShiftId; + result.Id = p2.Id; + return result; + + } + public static Expression> ProjectToShiftRoutine => p4 => new ShiftRoutine() + { + RoutineId = p4.RoutineId, + ShiftId = p4.ShiftId, + Id = p4.Id + }; + public static ShiftRoutineSDto AdaptToSDto(this ShiftRoutine p5) + { + return p5 == null ? null : new ShiftRoutineSDto() + { + RoutineId = p5.RoutineId, + ShiftId = p5.ShiftId, + Id = p5.Id + }; + } + public static ShiftRoutineSDto AdaptTo(this ShiftRoutine p6, ShiftRoutineSDto p7) + { + if (p6 == null) + { + return null; + } + ShiftRoutineSDto result = p7 ?? new ShiftRoutineSDto(); + + result.RoutineId = p6.RoutineId; + result.ShiftId = p6.ShiftId; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new ShiftRoutineSDto() + { + RoutineId = p8.RoutineId, + ShiftId = p8.ShiftId, + Id = p8.Id + }; } } \ No newline at end of file diff --git a/Brizco.Domain/Mappers/TaskDayMapper.g.cs b/Brizco.Domain/Mappers/TaskDayMapper.g.cs new file mode 100644 index 0000000..1744b23 --- /dev/null +++ b/Brizco.Domain/Mappers/TaskDayMapper.g.cs @@ -0,0 +1,69 @@ +using System; +using System.Linq.Expressions; +using Brizco.Domain.Dtos.SmallDtos; +using Brizco.Domain.Entities.Task; + +namespace Brizco.Domain.Mappers +{ + public static partial class TaskDayMapper + { + public static TaskDay AdaptToTaskDay(this TaskDaySDto p1) + { + return p1 == null ? null : new TaskDay() + { + DayOfWeek = p1.DayOfWeek, + TaskId = p1.TaskId, + Id = p1.Id + }; + } + public static TaskDay AdaptTo(this TaskDaySDto p2, TaskDay p3) + { + if (p2 == null) + { + return null; + } + TaskDay result = p3 ?? new TaskDay(); + + result.DayOfWeek = p2.DayOfWeek; + result.TaskId = p2.TaskId; + result.Id = p2.Id; + return result; + + } + public static Expression> ProjectToTaskDay => p4 => new TaskDay() + { + DayOfWeek = p4.DayOfWeek, + TaskId = p4.TaskId, + Id = p4.Id + }; + public static TaskDaySDto AdaptToSDto(this TaskDay p5) + { + return p5 == null ? null : new TaskDaySDto() + { + DayOfWeek = p5.DayOfWeek, + TaskId = p5.TaskId, + Id = p5.Id + }; + } + public static TaskDaySDto AdaptTo(this TaskDay p6, TaskDaySDto p7) + { + if (p6 == null) + { + return null; + } + TaskDaySDto result = p7 ?? new TaskDaySDto(); + + result.DayOfWeek = p6.DayOfWeek; + result.TaskId = p6.TaskId; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new TaskDaySDto() + { + DayOfWeek = p8.DayOfWeek, + TaskId = p8.TaskId, + Id = p8.Id + }; + } +} \ No newline at end of file diff --git a/Brizco.Domain/Mappers/TaskMapper.g.cs b/Brizco.Domain/Mappers/TaskMapper.g.cs index fb56d77..b89d5d2 100644 --- a/Brizco.Domain/Mappers/TaskMapper.g.cs +++ b/Brizco.Domain/Mappers/TaskMapper.g.cs @@ -21,6 +21,7 @@ namespace Brizco.Domain.Mappers IsDisposable = p1.IsDisposable, SetFor = p1.SetFor, HasDisposed = p1.HasDisposed, + ScheduleType = p1.ScheduleType, ComplexId = p1.ComplexId, Amount = p1.Amount, AmountType = p1.AmountType, @@ -41,6 +42,7 @@ namespace Brizco.Domain.Mappers result.IsDisposable = p2.IsDisposable; result.SetFor = p2.SetFor; result.HasDisposed = p2.HasDisposed; + result.ScheduleType = p2.ScheduleType; result.ComplexId = p2.ComplexId; result.Amount = p2.Amount; result.AmountType = p2.AmountType; @@ -56,6 +58,7 @@ namespace Brizco.Domain.Mappers IsDisposable = p4.IsDisposable, SetFor = p4.SetFor, HasDisposed = p4.HasDisposed, + ScheduleType = p4.ScheduleType, ComplexId = p4.ComplexId, Amount = p4.Amount, AmountType = p4.AmountType, @@ -72,6 +75,7 @@ namespace Brizco.Domain.Mappers SetFor = p5.SetFor, HasDisposed = p5.HasDisposed, ComplexId = p5.ComplexId, + ScheduleType = p5.ScheduleType, Amount = p5.Amount, AmountType = p5.AmountType, Id = p5.Id @@ -92,6 +96,7 @@ namespace Brizco.Domain.Mappers result.SetFor = p6.SetFor; result.HasDisposed = p6.HasDisposed; result.ComplexId = p6.ComplexId; + result.ScheduleType = p6.ScheduleType; result.Amount = p6.Amount; result.AmountType = p6.AmountType; result.Id = p6.Id; @@ -107,6 +112,7 @@ namespace Brizco.Domain.Mappers SetFor = p8.SetFor, HasDisposed = p8.HasDisposed, ComplexId = p8.ComplexId, + ScheduleType = p8.ScheduleType, Amount = p8.Amount, AmountType = p8.AmountType, Id = p8.Id @@ -121,119 +127,157 @@ namespace Brizco.Domain.Mappers IsDisposable = p9.IsDisposable, SetFor = p9.SetFor, HasDisposed = p9.HasDisposed, + ScheduleType = p9.ScheduleType, Amount = p9.Amount, AmountType = p9.AmountType, Shifts = funcMain1(p9.Shifts), - Positions = funcMain2(p9.Positions), + Days = funcMain2(p9.Days), + Routines = funcMain3(p9.Routines), + Positions = funcMain4(p9.Positions), Id = p9.Id }; } - public static Task AdaptTo(this TaskLDto p12, Task p13) + public static Task AdaptTo(this TaskLDto p14, Task p15) { - if (p12 == null) + if (p14 == null) { return null; } - Task result = p13 ?? new Task(); + Task result = p15 ?? new Task(); - result.Type = p12.Type; - result.Title = p12.Title; - result.Description = p12.Description; - result.IsDisposable = p12.IsDisposable; - result.SetFor = p12.SetFor; - result.HasDisposed = p12.HasDisposed; - result.Amount = p12.Amount; - result.AmountType = p12.AmountType; - result.Shifts = funcMain3(p12.Shifts, result.Shifts); - result.Positions = funcMain4(p12.Positions, result.Positions); - result.Id = p12.Id; + 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.Shifts = funcMain5(p14.Shifts, result.Shifts); + result.Days = funcMain6(p14.Days, result.Days); + result.Routines = funcMain7(p14.Routines, result.Routines); + result.Positions = funcMain8(p14.Positions, result.Positions); + result.Id = p14.Id; return result; } - public static Expression> ProjectLDtoToTask => p18 => new Task() + public static Expression> ProjectLDtoToTask => p24 => new Task() { - Type = p18.Type, - Title = p18.Title, - Description = p18.Description, - IsDisposable = p18.IsDisposable, - SetFor = p18.SetFor, - HasDisposed = p18.HasDisposed, - Amount = p18.Amount, - AmountType = p18.AmountType, - Shifts = p18.Shifts.Select(p19 => new TaskShift() + Type = p24.Type, + Title = p24.Title, + Description = p24.Description, + IsDisposable = p24.IsDisposable, + SetFor = p24.SetFor, + HasDisposed = p24.HasDisposed, + ScheduleType = p24.ScheduleType, + Amount = p24.Amount, + AmountType = p24.AmountType, + Shifts = p24.Shifts.Select(p25 => new TaskShift() { - TaskId = p19.TaskId, - ShiftId = p19.ShiftId + TaskId = p25.TaskId, + ShiftId = p25.ShiftId }).ToList(), - Positions = p18.Positions.Select(p20 => new TaskPosition() + Days = p24.Days.Select(p26 => new TaskDay() { - PositionId = p20.PositionId, - TaskId = p20.TaskId, - Id = p20.Id + DayOfWeek = p26.DayOfWeek, + TaskId = p26.TaskId, + Id = p26.Id + }).ToList(), + Routines = p24.Routines.Select(p27 => new TaskRoutine() + { + TaskId = p27.TaskId, + RoutineId = p27.RoutineId, + Id = p27.Id + }).ToList(), + Positions = p24.Positions.Select(p28 => new TaskPosition() + { + PositionId = p28.PositionId, + TaskId = p28.TaskId, + Id = p28.Id }).ToList(), - Id = p18.Id + Id = p24.Id }; - public static TaskLDto AdaptToLDto(this Task p21) + public static TaskLDto AdaptToLDto(this Task p29) { - return p21 == null ? null : new TaskLDto() + return p29 == null ? null : new TaskLDto() { - Type = p21.Type, - Title = p21.Title, - Description = p21.Description, - IsDisposable = p21.IsDisposable, - SetFor = p21.SetFor, - HasDisposed = p21.HasDisposed, - Amount = p21.Amount, - AmountType = p21.AmountType, - Shifts = funcMain5(p21.Shifts), - Positions = funcMain6(p21.Positions), - Id = p21.Id + Type = p29.Type, + Title = p29.Title, + Description = p29.Description, + IsDisposable = p29.IsDisposable, + SetFor = p29.SetFor, + HasDisposed = p29.HasDisposed, + ScheduleType = p29.ScheduleType, + Amount = p29.Amount, + AmountType = p29.AmountType, + Shifts = funcMain9(p29.Shifts), + Positions = funcMain10(p29.Positions), + Days = funcMain11(p29.Days), + Routines = funcMain12(p29.Routines), + Id = p29.Id }; } - public static TaskLDto AdaptTo(this Task p24, TaskLDto p25) + public static TaskLDto AdaptTo(this Task p34, TaskLDto p35) { - if (p24 == null) + if (p34 == null) { return null; } - TaskLDto result = p25 ?? new TaskLDto(); + TaskLDto result = p35 ?? new TaskLDto(); - result.Type = p24.Type; - result.Title = p24.Title; - result.Description = p24.Description; - result.IsDisposable = p24.IsDisposable; - result.SetFor = p24.SetFor; - result.HasDisposed = p24.HasDisposed; - result.Amount = p24.Amount; - result.AmountType = p24.AmountType; - result.Shifts = funcMain7(p24.Shifts, result.Shifts); - result.Positions = funcMain8(p24.Positions, result.Positions); - result.Id = p24.Id; + result.Type = p34.Type; + result.Title = p34.Title; + result.Description = p34.Description; + result.IsDisposable = p34.IsDisposable; + result.SetFor = p34.SetFor; + result.HasDisposed = p34.HasDisposed; + result.ScheduleType = p34.ScheduleType; + result.Amount = p34.Amount; + result.AmountType = p34.AmountType; + result.Shifts = funcMain13(p34.Shifts, result.Shifts); + result.Positions = funcMain14(p34.Positions, result.Positions); + result.Days = funcMain15(p34.Days, result.Days); + result.Routines = funcMain16(p34.Routines, result.Routines); + result.Id = p34.Id; return result; } - public static Expression> ProjectToLDto => p30 => new TaskLDto() + public static Expression> ProjectToLDto => p44 => new TaskLDto() { - Type = p30.Type, - Title = p30.Title, - Description = p30.Description, - IsDisposable = p30.IsDisposable, - SetFor = p30.SetFor, - HasDisposed = p30.HasDisposed, - Amount = p30.Amount, - AmountType = p30.AmountType, - Shifts = p30.Shifts.Select(p31 => new TaskShiftSDto() + Type = p44.Type, + Title = p44.Title, + Description = p44.Description, + IsDisposable = p44.IsDisposable, + SetFor = p44.SetFor, + HasDisposed = p44.HasDisposed, + ScheduleType = p44.ScheduleType, + Amount = p44.Amount, + AmountType = p44.AmountType, + Shifts = p44.Shifts.Select(p45 => new TaskShiftSDto() { - ShiftId = p31.ShiftId, - TaskId = p31.TaskId + ShiftId = p45.ShiftId, + TaskId = p45.TaskId }).ToList(), - Positions = p30.Positions.Select(p32 => new TaskPositionSDto() + Positions = p44.Positions.Select(p46 => new TaskPositionSDto() { - PositionId = p32.PositionId, - TaskId = p32.TaskId, - Id = p32.Id + PositionId = p46.PositionId, + TaskId = p46.TaskId, + Id = p46.Id }).ToList(), - Id = p30.Id + Days = p44.Days.Select(p47 => new TaskDaySDto() + { + DayOfWeek = p47.DayOfWeek, + TaskId = p47.TaskId, + Id = p47.Id + }).ToList(), + Routines = p44.Routines.Select(p48 => new TaskRoutineSDto() + { + TaskId = p48.TaskId, + RoutineId = p48.RoutineId, + Id = p48.Id + }).ToList(), + Id = p44.Id }; private static List funcMain1(List p10) @@ -261,20 +305,72 @@ namespace Brizco.Domain.Mappers } - private static List funcMain2(List p11) + private static List funcMain2(List p11) { if (p11 == null) { return null; } - List result = new List(p11.Count); + List result = new List(p11.Count); int i = 0; int len = p11.Count; while (i < len) { - TaskPositionSDto item = p11[i]; + TaskDaySDto item = p11[i]; + result.Add(item == null ? null : new TaskDay() + { + DayOfWeek = item.DayOfWeek, + TaskId = item.TaskId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain3(List p12) + { + if (p12 == null) + { + return null; + } + List result = new List(p12.Count); + + int i = 0; + int len = p12.Count; + + while (i < len) + { + TaskRoutineSDto item = p12[i]; + result.Add(item == null ? null : new TaskRoutine() + { + TaskId = item.TaskId, + RoutineId = item.RoutineId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain4(List p13) + { + if (p13 == null) + { + return null; + } + List result = new List(p13.Count); + + int i = 0; + int len = p13.Count; + + while (i < len) + { + TaskPositionSDto item = p13[i]; result.Add(item == null ? null : new TaskPosition() { PositionId = item.PositionId, @@ -287,20 +383,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain3(List p14, List p15) + private static List funcMain5(List p16, List p17) { - if (p14 == null) + if (p16 == null) { return null; } - List result = new List(p14.Count); + List result = new List(p16.Count); int i = 0; - int len = p14.Count; + int len = p16.Count; while (i < len) { - TaskShiftSDto item = p14[i]; + TaskShiftSDto item = p16[i]; result.Add(item == null ? null : new TaskShift() { TaskId = item.TaskId, @@ -312,20 +408,72 @@ namespace Brizco.Domain.Mappers } - private static List funcMain4(List p16, List p17) + private static List funcMain6(List p18, List p19) { - if (p16 == null) + if (p18 == null) { return null; } - List result = new List(p16.Count); + List result = new List(p18.Count); int i = 0; - int len = p16.Count; + int len = p18.Count; while (i < len) { - TaskPositionSDto item = p16[i]; + TaskDaySDto item = p18[i]; + result.Add(item == null ? null : new TaskDay() + { + DayOfWeek = item.DayOfWeek, + TaskId = item.TaskId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain7(List p20, List p21) + { + if (p20 == null) + { + return null; + } + List result = new List(p20.Count); + + int i = 0; + int len = p20.Count; + + while (i < len) + { + TaskRoutineSDto item = p20[i]; + result.Add(item == null ? null : new TaskRoutine() + { + TaskId = item.TaskId, + RoutineId = item.RoutineId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain8(List p22, List p23) + { + if (p22 == null) + { + return null; + } + List result = new List(p22.Count); + + int i = 0; + int len = p22.Count; + + while (i < len) + { + TaskPositionSDto item = p22[i]; result.Add(item == null ? null : new TaskPosition() { PositionId = item.PositionId, @@ -338,20 +486,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain5(List p22) + private static List funcMain9(List p30) { - if (p22 == null) + if (p30 == null) { return null; } - List result = new List(p22.Count); + List result = new List(p30.Count); int i = 0; - int len = p22.Count; + int len = p30.Count; while (i < len) { - TaskShift item = p22[i]; + TaskShift item = p30[i]; result.Add(item == null ? null : new TaskShiftSDto() { ShiftId = item.ShiftId, @@ -363,20 +511,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain6(List p23) + private static List funcMain10(List p31) { - if (p23 == null) + if (p31 == null) { return null; } - List result = new List(p23.Count); + List result = new List(p31.Count); int i = 0; - int len = p23.Count; + int len = p31.Count; while (i < len) { - TaskPosition item = p23[i]; + TaskPosition item = p31[i]; result.Add(item == null ? null : new TaskPositionSDto() { PositionId = item.PositionId, @@ -389,20 +537,72 @@ namespace Brizco.Domain.Mappers } - private static List funcMain7(List p26, List p27) + private static List funcMain11(List p32) { - if (p26 == null) + if (p32 == null) { return null; } - List result = new List(p26.Count); + List result = new List(p32.Count); int i = 0; - int len = p26.Count; + int len = p32.Count; while (i < len) { - TaskShift item = p26[i]; + TaskDay item = p32[i]; + result.Add(item == null ? null : new TaskDaySDto() + { + DayOfWeek = item.DayOfWeek, + TaskId = item.TaskId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain12(List p33) + { + if (p33 == null) + { + return null; + } + List result = new List(p33.Count); + + int i = 0; + int len = p33.Count; + + while (i < len) + { + TaskRoutine item = p33[i]; + result.Add(item == null ? null : new TaskRoutineSDto() + { + TaskId = item.TaskId, + RoutineId = item.RoutineId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain13(List p36, List p37) + { + if (p36 == null) + { + return null; + } + List result = new List(p36.Count); + + int i = 0; + int len = p36.Count; + + while (i < len) + { + TaskShift item = p36[i]; result.Add(item == null ? null : new TaskShiftSDto() { ShiftId = item.ShiftId, @@ -414,20 +614,20 @@ namespace Brizco.Domain.Mappers } - private static List funcMain8(List p28, List p29) + private static List funcMain14(List p38, List p39) { - if (p28 == null) + if (p38 == null) { return null; } - List result = new List(p28.Count); + List result = new List(p38.Count); int i = 0; - int len = p28.Count; + int len = p38.Count; while (i < len) { - TaskPosition item = p28[i]; + TaskPosition item = p38[i]; result.Add(item == null ? null : new TaskPositionSDto() { PositionId = item.PositionId, @@ -439,5 +639,57 @@ namespace Brizco.Domain.Mappers return result; } + + private static List funcMain15(List p40, List p41) + { + if (p40 == null) + { + return null; + } + List result = new List(p40.Count); + + int i = 0; + int len = p40.Count; + + while (i < len) + { + TaskDay item = p40[i]; + result.Add(item == null ? null : new TaskDaySDto() + { + DayOfWeek = item.DayOfWeek, + TaskId = item.TaskId, + Id = item.Id + }); + i++; + } + return result; + + } + + private static List funcMain16(List p42, List p43) + { + if (p42 == null) + { + return null; + } + List result = new List(p42.Count); + + int i = 0; + int len = p42.Count; + + while (i < len) + { + TaskRoutine item = p42[i]; + result.Add(item == null ? null : new TaskRoutineSDto() + { + TaskId = item.TaskId, + RoutineId = item.RoutineId, + Id = item.Id + }); + i++; + } + return result; + + } } } \ No newline at end of file diff --git a/Brizco.Domain/Mappers/TaskRoutineMapper.g.cs b/Brizco.Domain/Mappers/TaskRoutineMapper.g.cs index 83c0b94..f73f33d 100644 --- a/Brizco.Domain/Mappers/TaskRoutineMapper.g.cs +++ b/Brizco.Domain/Mappers/TaskRoutineMapper.g.cs @@ -1,6 +1,69 @@ +using System; +using System.Linq.Expressions; +using Brizco.Domain.Dtos.SmallDtos; +using Brizco.Domain.Entities.Task; + namespace Brizco.Domain.Mappers { public static partial class TaskRoutineMapper { + public static TaskRoutine AdaptToTaskRoutine(this TaskRoutineSDto p1) + { + return p1 == null ? null : new TaskRoutine() + { + TaskId = p1.TaskId, + RoutineId = p1.RoutineId, + Id = p1.Id + }; + } + public static TaskRoutine AdaptTo(this TaskRoutineSDto p2, TaskRoutine p3) + { + if (p2 == null) + { + return null; + } + TaskRoutine result = p3 ?? new TaskRoutine(); + + result.TaskId = p2.TaskId; + result.RoutineId = p2.RoutineId; + result.Id = p2.Id; + return result; + + } + public static Expression> ProjectToTaskRoutine => p4 => new TaskRoutine() + { + TaskId = p4.TaskId, + RoutineId = p4.RoutineId, + Id = p4.Id + }; + public static TaskRoutineSDto AdaptToSDto(this TaskRoutine p5) + { + return p5 == null ? null : new TaskRoutineSDto() + { + TaskId = p5.TaskId, + RoutineId = p5.RoutineId, + Id = p5.Id + }; + } + public static TaskRoutineSDto AdaptTo(this TaskRoutine p6, TaskRoutineSDto p7) + { + if (p6 == null) + { + return null; + } + TaskRoutineSDto result = p7 ?? new TaskRoutineSDto(); + + result.TaskId = p6.TaskId; + result.RoutineId = p6.RoutineId; + result.Id = p6.Id; + return result; + + } + public static Expression> ProjectToSDto => p8 => new TaskRoutineSDto() + { + TaskId = p8.TaskId, + RoutineId = p8.RoutineId, + Id = p8.Id + }; } } \ No newline at end of file diff --git a/Brizco.Domain/MapsterRegister.cs b/Brizco.Domain/MapsterRegister.cs index 13e11ba..ba85234 100644 --- a/Brizco.Domain/MapsterRegister.cs +++ b/Brizco.Domain/MapsterRegister.cs @@ -12,6 +12,9 @@ public class MapsterRegister : IRegister .Map("Days",o=>o.Days.Select(d=>d.DayOfWeek).ToList()) .TwoWays(); + config.NewConfig() + .Map("Days", o => o.Days.Select(d => d.DayOfWeek).ToList()) + .TwoWays(); config.NewConfig() .Map("RoleName", org => org.Role!.PersianName) diff --git a/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs b/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs index c16f63e..95d3cb2 100644 --- a/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs +++ b/Brizco.Repository/Handlers/Activity/CreateActivityCommandHandler.cs @@ -33,21 +33,11 @@ public class CreateActivityCommandHandler : IRequestHandler().Add(task); await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken); diff --git a/Brizco.Repository/Handlers/Activity/UpdateActivityCommandHandler.cs b/Brizco.Repository/Handlers/Activity/UpdateActivityCommandHandler.cs index 875d6b1..2be29e9 100644 --- a/Brizco.Repository/Handlers/Activity/UpdateActivityCommandHandler.cs +++ b/Brizco.Repository/Handlers/Activity/UpdateActivityCommandHandler.cs @@ -37,7 +37,8 @@ public class UpdateActivityCommandHandler : IRequestHandler p.Id == request.PositionId, cancellationToken); if (entity == null) throw new AppException("Position not found"); - entity.AddUser(request.UserId); + entity.AddUser(request.UserId,request.ShiftPlanId); _repositoryWrapper.SetRepository().Update(entity); await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken); diff --git a/Brizco.Repository/Handlers/Position/UpdatePositionUserCommandHandler.cs b/Brizco.Repository/Handlers/Position/UpdatePositionUserCommandHandler.cs index 7c8c2bc..ad69121 100644 --- a/Brizco.Repository/Handlers/Position/UpdatePositionUserCommandHandler.cs +++ b/Brizco.Repository/Handlers/Position/UpdatePositionUserCommandHandler.cs @@ -20,7 +20,7 @@ public class UpdatePositionUserCommandHandler : IRequestHandler p.ApplicationUserId == request.UserId , cancellationToken); if (entity == null) throw new AppException("PositionUser not found"); - var newEntity = PositionUser.Create(request.PositionId, request.UserId); + var newEntity = PositionUser.Create(request.PositionId, request.UserId, request.ShiftPlanId); newEntity.Id = entity.Id; _repositoryWrapper.SetRepository().Update(newEntity); diff --git a/Brizco.Repository/Handlers/Section/DeleteSectionCommandHandler.cs b/Brizco.Repository/Handlers/Section/DeleteSectionCommandHandler.cs index 1b9f27a..2ce6218 100644 --- a/Brizco.Repository/Handlers/Section/DeleteSectionCommandHandler.cs +++ b/Brizco.Repository/Handlers/Section/DeleteSectionCommandHandler.cs @@ -14,7 +14,15 @@ public class DeleteSectionCommandHandler : IRequestHandler s.Id == request.Id, cancellationToken); if (section == null) - throw new AppException("Postion not found", ApiResultStatusCode.NotFound); + throw new AppException("Section not found", ApiResultStatusCode.NotFound); + + var positions = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(p => p.SectionId == section.Id) + .CountAsync(cancellationToken); + if (positions > 0) + throw new AppException("این سکشن پوزیشن فعال دارد ، نخست پوزیشن های سکشن را حذف کرده یا منتقل کنید"); + _repositoryWrapper.SetRepository() .Delete(section); diff --git a/Brizco.Repository/Handlers/Shift/CreateShiftCommandHandler.cs b/Brizco.Repository/Handlers/Shift/CreateShiftCommandHandler.cs index e39de57..7c3eb51 100644 --- a/Brizco.Repository/Handlers/Shift/CreateShiftCommandHandler.cs +++ b/Brizco.Repository/Handlers/Shift/CreateShiftCommandHandler.cs @@ -27,8 +27,12 @@ public class CreateShiftCommandHandler : IRequestHandler shift.SetDay(d)); + if (request.Routines.Count == 0) + throw new AppException("روتین شیفت را انتخاب کنید"); + request.Routines.ForEach(r=>shift.AddRoutine(r)); _repositoryWrapper.SetRepository().Add(shift); await _repositoryWrapper.SaveChangesAsync(cancellationToken); diff --git a/Brizco.Repository/Handlers/Shift/GetShiftQueryHandler.cs b/Brizco.Repository/Handlers/Shift/GetShiftQueryHandler.cs index a220582..fe037c0 100644 --- a/Brizco.Repository/Handlers/Shift/GetShiftQueryHandler.cs +++ b/Brizco.Repository/Handlers/Shift/GetShiftQueryHandler.cs @@ -2,7 +2,7 @@ namespace Brizco.Repository.Handlers.Shift; -public class GetShiftPlanQueryHandler : IRequestHandler +public class GetShiftPlanQueryHandler : IRequestHandler { private readonly IRepositoryWrapper _repositoryWrapper; @@ -10,19 +10,19 @@ public class GetShiftPlanQueryHandler : IRequestHandler Handle(GetShiftQuery request, CancellationToken cancellationToken) + public async Task Handle(GetShiftQuery request, CancellationToken cancellationToken) { var shift = await _repositoryWrapper.SetRepository() .TableNoTracking - .Where(s => s.Id == request.id) - .Select(ShiftMapper.ProjectToSDto) + .Where(s => s.Id == request.Id) + .Select(ShiftMapper.ProjectToLDto) .FirstOrDefaultAsync(cancellationToken); if (shift == null) throw new AppException("Shift not found", ApiResultStatusCode.NotFound); //var shiftDays = await _repositoryWrapper.SetRepository() // .TableNoTracking - // .Where(sd => sd.ShiftId == request.id) + // .Where(sd => sd.ShiftId == request.Id) // .ToListAsync(cancellationToken); //shift.Days = shiftDays.Select(s => s.DayOfWeek).ToList(); diff --git a/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs b/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs index d894dd2..32b0920 100644 --- a/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs +++ b/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs @@ -20,7 +20,7 @@ public class GetShiftPlansQueryHandler : IRequestHandler().TableNoTracking .Where(s=>s.ComplexId==complexId) .OrderByDescending(s => s.CreatedAt) - .Skip(request.page * 15).Take(15) + .Skip(request.Page * 15).Take(15) .Select(ShiftMapper.ProjectToSDto) .ToListAsync(cancellationToken); diff --git a/Brizco.Repository/Handlers/Shift/UpdateShiftCommandHandler.cs b/Brizco.Repository/Handlers/Shift/UpdateShiftCommandHandler.cs index b45e36c..baa23de 100644 --- a/Brizco.Repository/Handlers/Shift/UpdateShiftCommandHandler.cs +++ b/Brizco.Repository/Handlers/Shift/UpdateShiftCommandHandler.cs @@ -32,6 +32,8 @@ public class UpdatePositionCommandHandler : IRequestHandler() .TableNoTracking.Where(sd => sd.ShiftId == request.Id) .ToListAsync(cancellationToken); @@ -43,11 +45,28 @@ public class UpdatePositionCommandHandler : IRequestHandler sf.DayOfWeek == dayOfWeek) where findDay == null select dayOfWeek) { - var findDay = shiftDays.FirstOrDefault(sf => sf.DayOfWeek == dayOfWeek); - if (findDay == null) - newShift.SetDay(dayOfWeek); + newShift.SetDay(dayOfWeek); + } + + + if (request.Routines.Count == 0) + throw new AppException("روتین شیفت را انتخاب کنید"); + var shiftRoutines = await _repositoryWrapper.SetRepository() + .TableNoTracking.Where(sd => sd.ShiftId == request.Id) + .ToListAsync(cancellationToken); + + foreach (var shiftRoutine in shiftRoutines.Where(shiftRoutine => !request.Routines.Contains(shiftRoutine.RoutineId))) + { + _repositoryWrapper.SetRepository() + .Delete(shiftRoutine); + await _repositoryWrapper.SaveChangesAsync(cancellationToken); + } + + foreach (var routine in request.Routines.Where(r=>!shiftRoutines.Exists(routine=>routine.RoutineId==r))) + { + newShift.AddRoutine(routine); } _repositoryWrapper.SetRepository() diff --git a/Brizco.Repository/Handlers/Task/CreateTaskCommandHandler.cs b/Brizco.Repository/Handlers/Task/CreateTaskCommandHandler.cs index 449c39b..295e653 100644 --- a/Brizco.Repository/Handlers/Task/CreateTaskCommandHandler.cs +++ b/Brizco.Repository/Handlers/Task/CreateTaskCommandHandler.cs @@ -21,13 +21,16 @@ public class CreateActivityCommandHandler : IRequestHandlertask.SetDay(d)); + _repositoryWrapper.SetRepository().Add(task); await _repositoryWrapper.SaveChangesAsync(cancellationToken); diff --git a/Brizco.Repository/Handlers/Task/UpdateTaskCommandHandler.cs b/Brizco.Repository/Handlers/Task/UpdateTaskCommandHandler.cs index db6bb92..83194b4 100644 --- a/Brizco.Repository/Handlers/Task/UpdateTaskCommandHandler.cs +++ b/Brizco.Repository/Handlers/Task/UpdateTaskCommandHandler.cs @@ -1,4 +1,6 @@ -namespace Brizco.Repository.Handlers.Task; +using Brizco.Domain.Entities.Task; + +namespace Brizco.Repository.Handlers.Task; public class UpdateActivityCommandHandler : IRequestHandler { @@ -27,13 +29,89 @@ public class UpdateActivityCommandHandler : IRequestHandler() + .TableNoTracking + .Where(tr => tr.TaskId == newTask.Id) + .ToListAsync(cancellationToken); + foreach (var taskRoutine in routines.Where(taskR => !request.Routines.Exists(r=>r== taskR.RoutineId))) + { + _repositoryWrapper.SetRepository() + .Delete(taskRoutine); + await _repositoryWrapper.SaveChangesAsync(cancellationToken); + } + + foreach (var routine in request.Routines.Where(requestRoutine => !routines.Exists(r=>r.RoutineId==requestRoutine))) + { + newTask.AddRoutine(routine); + } + + if (request.Shifts.Count == 0) + throw new AppException("اگر فعالیت برای یک گروه نقش انتخاب شده باشد باید لیست نقش ها را ارسال نمایید"); + var shifts = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(tr => tr.TaskId == newTask.Id) + .ToListAsync(cancellationToken); + foreach (var taskShift in shifts.Where(taskS => !request.Shifts.Exists(r => r == taskS.ShiftId))) + { + _repositoryWrapper.SetRepository() + .Delete(taskShift); + await _repositoryWrapper.SaveChangesAsync(cancellationToken); + } + + foreach (var shift in request.Shifts.Where(requestShift => !shifts.Exists(r => r.ShiftId == requestShift))) + { + newTask.AddShift(shift); + } + + if (request.Positions.Count == 0) + throw new AppException("اگر فعالیت برای یک گروه نقش انتخاب شده باشد باید لیست نقش ها را ارسال نمایید"); + var positions = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(tr => tr.TaskId == newTask.Id) + .ToListAsync(cancellationToken); + foreach (var taskPosition in positions.Where(taskP => !request.Positions.Exists(r => r == taskP.PositionId))) + { + _repositoryWrapper.SetRepository() + .Delete(taskPosition); + await _repositoryWrapper.SaveChangesAsync(cancellationToken); + } + + foreach (var position in request.Positions.Where(requestP => !positions.Exists(r => r.PositionId == requestP))) + { + newTask.AddPosition(position); + } + + if (task.ScheduleType == TaskScheduleType.Weekly && request.Days.Count == 0) + throw new AppException("اگر تکرار فعالیت به صورت هفتگی باشد باید روزهای ان هفته را انتخاب کنید"); + request.Days.ForEach(d => task.SetDay(d)); + var days = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(tr => tr.TaskId == newTask.Id) + .ToListAsync(cancellationToken); + foreach (var taskDay in days.Where(taskD => !request.Days.Exists(r => r == taskD.DayOfWeek))) + { + _repositoryWrapper.SetRepository() + .Delete(taskDay); + await _repositoryWrapper.SaveChangesAsync(cancellationToken); + } + + foreach (var day in request.Days.Where(requestP => !days.Exists(r => r.DayOfWeek == requestP))) + { + newTask.SetDay(day); + } + _repositoryWrapper.SetRepository() .Update(newTask); await _repositoryWrapper.SaveChangesAsync(cancellationToken); diff --git a/Brizco.Repository/Migrations/20231113110204_init.Designer.cs b/Brizco.Repository/Migrations/20231116063836_init.Designer.cs similarity index 97% rename from Brizco.Repository/Migrations/20231113110204_init.Designer.cs rename to Brizco.Repository/Migrations/20231116063836_init.Designer.cs index 51dd3b8..65610a1 100644 --- a/Brizco.Repository/Migrations/20231113110204_init.Designer.cs +++ b/Brizco.Repository/Migrations/20231116063836_init.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace Brizco.Repository.Migrations { [DbContext(typeof(ApplicationContext))] - [Migration("20231113110204_init")] + [Migration("20231116063836_init")] partial class init { /// @@ -252,12 +252,17 @@ namespace Brizco.Repository.Migrations .IsRequired() .HasColumnType("text"); + b.Property("ShiftPlanId") + .HasColumnType("uuid"); + b.HasKey("Id"); b.HasIndex("ApplicationUserId"); b.HasIndex("PositionId"); + b.HasIndex("ShiftPlanId"); + b.ToTable("PositionUsers", "public"); }); @@ -640,6 +645,9 @@ namespace Brizco.Repository.Migrations .IsRequired() .HasColumnType("text"); + b.Property("ScheduleType") + .HasColumnType("integer"); + b.Property("SetFor") .HasColumnType("timestamp without time zone"); @@ -1092,6 +1100,11 @@ namespace Brizco.Repository.Migrations b.Property("Status") .HasColumnType("integer"); + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasIndex("UserId"); + b.HasDiscriminator().HasValue("Activity"); }); @@ -1166,9 +1179,17 @@ namespace Brizco.Repository.Migrations .OnDelete(DeleteBehavior.Restrict) .IsRequired(); + b.HasOne("Brizco.Domain.Entities.Shift.ShiftPlan", "ShiftPlan") + .WithMany() + .HasForeignKey("ShiftPlanId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + b.Navigation("ApplicationUser"); b.Navigation("Position"); + + b.Navigation("ShiftPlan"); }); modelBuilder.Entity("Brizco.Domain.Entities.Complex.Section", b => @@ -1403,6 +1424,17 @@ namespace Brizco.Repository.Migrations .IsRequired(); }); + modelBuilder.Entity("Brizco.Domain.Entities.Task.Activity", b => + { + b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("User"); + }); + modelBuilder.Entity("Brizco.Domain.Entities.Complex.Complex", b => { b.Navigation("Roles"); diff --git a/Brizco.Repository/Migrations/20231113110204_init.cs b/Brizco.Repository/Migrations/20231116063836_init.cs similarity index 97% rename from Brizco.Repository/Migrations/20231113110204_init.cs rename to Brizco.Repository/Migrations/20231116063836_init.cs index 36ae38e..30d2ccb 100644 --- a/Brizco.Repository/Migrations/20231113110204_init.cs +++ b/Brizco.Repository/Migrations/20231116063836_init.cs @@ -184,46 +184,6 @@ namespace Brizco.Repository.Migrations onDelete: ReferentialAction.Restrict); }); - migrationBuilder.CreateTable( - name: "Tasks", - schema: "public", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Type = table.Column(type: "integer", nullable: false), - Title = table.Column(type: "text", nullable: false), - Description = table.Column(type: "text", nullable: false), - IsDisposable = table.Column(type: "boolean", nullable: false), - SetFor = table.Column(type: "timestamp without time zone", nullable: false), - HasDisposed = table.Column(type: "boolean", nullable: false), - ComplexId = table.Column(type: "uuid", nullable: false), - Amount = table.Column(type: "integer", nullable: false), - AmountType = table.Column(type: "integer", nullable: false), - Discriminator = table.Column(type: "text", nullable: false), - Status = table.Column(type: "integer", nullable: true), - DoneAt = table.Column(type: "timestamp without time zone", nullable: true), - IsDone = table.Column(type: "boolean", nullable: true), - PerformanceDescription = table.Column(type: "text", nullable: true), - RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), - CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), - CreatedBy = table.Column(type: "text", nullable: false), - IsRemoved = table.Column(type: "boolean", nullable: false), - RemovedBy = table.Column(type: "text", nullable: false), - ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), - ModifiedBy = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Tasks", x => x.Id); - table.ForeignKey( - name: "FK_Tasks_Complexes_ComplexId", - column: x => x.ComplexId, - principalSchema: "public", - principalTable: "Complexes", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - migrationBuilder.CreateTable( name: "Claims", schema: "public", @@ -304,6 +264,55 @@ namespace Brizco.Repository.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "Tasks", + schema: "public", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Type = table.Column(type: "integer", nullable: false), + Title = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + IsDisposable = table.Column(type: "boolean", nullable: false), + SetFor = table.Column(type: "timestamp without time zone", nullable: false), + HasDisposed = table.Column(type: "boolean", nullable: false), + ScheduleType = table.Column(type: "integer", nullable: false), + ComplexId = table.Column(type: "uuid", nullable: false), + Amount = table.Column(type: "integer", nullable: false), + AmountType = table.Column(type: "integer", nullable: false), + Discriminator = table.Column(type: "text", nullable: false), + Status = table.Column(type: "integer", nullable: true), + DoneAt = table.Column(type: "timestamp without time zone", nullable: true), + IsDone = table.Column(type: "boolean", nullable: true), + PerformanceDescription = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "uuid", nullable: true), + RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), + CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), + CreatedBy = table.Column(type: "text", nullable: false), + IsRemoved = table.Column(type: "boolean", nullable: false), + RemovedBy = table.Column(type: "text", nullable: false), + ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), + ModifiedBy = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tasks", x => x.Id); + table.ForeignKey( + name: "FK_Tasks_Complexes_ComplexId", + column: x => x.ComplexId, + principalSchema: "public", + principalTable: "Complexes", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Tasks_Users_UserId", + column: x => x.UserId, + principalSchema: "public", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "Tokens", schema: "public", @@ -504,6 +513,41 @@ namespace Brizco.Repository.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "ComplexUserRoles", + schema: "public", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ComplexUserId = table.Column(type: "uuid", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), + CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), + CreatedBy = table.Column(type: "text", nullable: false), + IsRemoved = table.Column(type: "boolean", nullable: false), + RemovedBy = table.Column(type: "text", nullable: false), + ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), + ModifiedBy = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ComplexUserRoles", x => x.Id); + table.ForeignKey( + name: "FK_ComplexUserRoles_ComplexUsers_ComplexUserId", + column: x => x.ComplexUserId, + principalSchema: "public", + principalTable: "ComplexUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_ComplexUserRoles_Roles_RoleId", + column: x => x.RoleId, + principalSchema: "public", + principalTable: "Roles", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "TaskDays", schema: "public", @@ -602,76 +646,6 @@ namespace Brizco.Repository.Migrations onDelete: ReferentialAction.Restrict); }); - migrationBuilder.CreateTable( - name: "ComplexUserRoles", - schema: "public", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - ComplexUserId = table.Column(type: "uuid", nullable: false), - RoleId = table.Column(type: "uuid", nullable: false), - RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), - CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), - CreatedBy = table.Column(type: "text", nullable: false), - IsRemoved = table.Column(type: "boolean", nullable: false), - RemovedBy = table.Column(type: "text", nullable: false), - ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), - ModifiedBy = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ComplexUserRoles", x => x.Id); - table.ForeignKey( - name: "FK_ComplexUserRoles_ComplexUsers_ComplexUserId", - column: x => x.ComplexUserId, - principalSchema: "public", - principalTable: "ComplexUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_ComplexUserRoles_Roles_RoleId", - column: x => x.RoleId, - principalSchema: "public", - principalTable: "Roles", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "PositionUsers", - schema: "public", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - ApplicationUserId = table.Column(type: "uuid", nullable: false), - PositionId = table.Column(type: "uuid", nullable: false), - RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), - CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), - CreatedBy = table.Column(type: "text", nullable: false), - IsRemoved = table.Column(type: "boolean", nullable: false), - RemovedBy = table.Column(type: "text", nullable: false), - ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), - ModifiedBy = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PositionUsers", x => x.Id); - table.ForeignKey( - name: "FK_PositionUsers_Positions_PositionId", - column: x => x.PositionId, - principalSchema: "public", - principalTable: "Positions", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_PositionUsers_Users_ApplicationUserId", - column: x => x.ApplicationUserId, - principalSchema: "public", - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - migrationBuilder.CreateTable( name: "TaskPositions", schema: "public", @@ -707,6 +681,49 @@ namespace Brizco.Repository.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "PositionUsers", + schema: "public", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ApplicationUserId = table.Column(type: "uuid", nullable: false), + PositionId = table.Column(type: "uuid", nullable: false), + ShiftPlanId = table.Column(type: "uuid", nullable: false), + RemovedAt = table.Column(type: "timestamp without time zone", nullable: false), + CreatedAt = table.Column(type: "timestamp without time zone", nullable: false), + CreatedBy = table.Column(type: "text", nullable: false), + IsRemoved = table.Column(type: "boolean", nullable: false), + RemovedBy = table.Column(type: "text", nullable: false), + ModifiedAt = table.Column(type: "timestamp without time zone", nullable: false), + ModifiedBy = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PositionUsers", x => x.Id); + table.ForeignKey( + name: "FK_PositionUsers_Positions_PositionId", + column: x => x.PositionId, + principalSchema: "public", + principalTable: "Positions", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PositionUsers_ShiftPlans_ShiftPlanId", + column: x => x.ShiftPlanId, + principalSchema: "public", + principalTable: "ShiftPlans", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_PositionUsers_Users_ApplicationUserId", + column: x => x.ApplicationUserId, + principalSchema: "public", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "ShiftPlanUsers", schema: "public", @@ -802,6 +819,12 @@ namespace Brizco.Repository.Migrations table: "PositionUsers", column: "PositionId"); + migrationBuilder.CreateIndex( + name: "IX_PositionUsers_ShiftPlanId", + schema: "public", + table: "PositionUsers", + column: "ShiftPlanId"); + migrationBuilder.CreateIndex( name: "IX_RoleClaims_RoleId", schema: "public", @@ -911,6 +934,12 @@ namespace Brizco.Repository.Migrations table: "Tasks", column: "ComplexId"); + migrationBuilder.CreateIndex( + name: "IX_Tasks_UserId", + schema: "public", + table: "Tasks", + column: "UserId"); + migrationBuilder.CreateIndex( name: "IX_TaskShifts_ShiftId", schema: "public", @@ -1026,10 +1055,6 @@ namespace Brizco.Repository.Migrations name: "Roles", schema: "public"); - migrationBuilder.DropTable( - name: "Users", - schema: "public"); - migrationBuilder.DropTable( name: "Shifts", schema: "public"); @@ -1038,6 +1063,10 @@ namespace Brizco.Repository.Migrations name: "Sections", schema: "public"); + migrationBuilder.DropTable( + name: "Users", + schema: "public"); + migrationBuilder.DropTable( name: "Complexes", schema: "public"); diff --git a/Brizco.Repository/Migrations/ApplicationContextModelSnapshot.cs b/Brizco.Repository/Migrations/ApplicationContextModelSnapshot.cs index a693af5..15c2305 100644 --- a/Brizco.Repository/Migrations/ApplicationContextModelSnapshot.cs +++ b/Brizco.Repository/Migrations/ApplicationContextModelSnapshot.cs @@ -249,12 +249,17 @@ namespace Brizco.Repository.Migrations .IsRequired() .HasColumnType("text"); + b.Property("ShiftPlanId") + .HasColumnType("uuid"); + b.HasKey("Id"); b.HasIndex("ApplicationUserId"); b.HasIndex("PositionId"); + b.HasIndex("ShiftPlanId"); + b.ToTable("PositionUsers", "public"); }); @@ -637,6 +642,9 @@ namespace Brizco.Repository.Migrations .IsRequired() .HasColumnType("text"); + b.Property("ScheduleType") + .HasColumnType("integer"); + b.Property("SetFor") .HasColumnType("timestamp without time zone"); @@ -1089,6 +1097,11 @@ namespace Brizco.Repository.Migrations b.Property("Status") .HasColumnType("integer"); + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasIndex("UserId"); + b.HasDiscriminator().HasValue("Activity"); }); @@ -1163,9 +1176,17 @@ namespace Brizco.Repository.Migrations .OnDelete(DeleteBehavior.Restrict) .IsRequired(); + b.HasOne("Brizco.Domain.Entities.Shift.ShiftPlan", "ShiftPlan") + .WithMany() + .HasForeignKey("ShiftPlanId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + b.Navigation("ApplicationUser"); b.Navigation("Position"); + + b.Navigation("ShiftPlan"); }); modelBuilder.Entity("Brizco.Domain.Entities.Complex.Section", b => @@ -1400,6 +1421,17 @@ namespace Brizco.Repository.Migrations .IsRequired(); }); + modelBuilder.Entity("Brizco.Domain.Entities.Task.Activity", b => + { + b.HasOne("Brizco.Domain.Entities.User.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("User"); + }); + modelBuilder.Entity("Brizco.Domain.Entities.Complex.Complex", b => { b.Navigation("Roles");