From ecfae75010fc95d86d2191f93909b54fe394986d Mon Sep 17 00:00:00 2001 From: MahanCh Date: Mon, 7 Apr 2025 19:44:22 +0330 Subject: [PATCH] add task schedule --- .../Task/CreateTask.cs | 19 +- .../Task/EditTask.cs | 1 + .../Task/ITaskApplication.cs | 32 +- .../Task/TaskViewModel.cs | 4 +- .../TaskSchedule/ITaskScheduleApplication.cs | 9 +- .../TaskScheduleDetailsViewModel.cs | 20 + .../TaskApplication.cs | 29 +- .../TaskScheduleApplication.cs | 489 +++-- .../TaskSubjectApplication.cs | 4 +- .../AccountManagementBootstrapper.cs | 4 + AccountManagement.Domain/AssignAgg/Assign.cs | 10 +- .../TaskAgg/ITaskRepository.cs | 47 +- .../ITaskScheduleRepository.cs | 9 +- .../TaskScheduleAgg/TaskSchedule.cs | 15 +- .../AccountContext.cs | 4 + .../Mappings/TaskScheduleMapping.cs | 5 +- ...0250407150638_add TaskSchedule.Designer.cs | 1274 ++++++++++++ .../20250407150638_add TaskSchedule.cs | 74 + .../Migrations/AccountContextModelSnapshot.cs | 7 + .../Repository/TaskRepository.cs | 370 +++- .../Repository/TaskScheduleRepository.cs | 66 + ServiceHost/Areas/Admin/Pages/Index.cshtml.cs | 4 +- .../Pages/Company/Task/Create.cshtml.cs | 16 +- .../Company/Task/CreateScheduleModal.cshtml | 445 ++++ .../Company/Task/DetailsScheduleModal.cshtml | 255 +++ .../AdminNew/Pages/Company/Task/Index.cshtml | 54 +- .../Pages/Company/Task/Index.cshtml.cs | 64 +- .../Areas/AdminNew/Pages/Index.cshtml.cs | 2 +- .../AdminNew/Pages/Shared/_Layout.cshtml | 271 +-- .../AssetsAdminNew/Tasks/css/Index.css | 174 +- .../AssetsAdminNew/Tasks/css/create.css | 10 +- .../Tasks/css/createScheduleModal.css | 176 ++ .../Tasks/js/CreateScheduleModal.js | 1793 +++++++++++++++++ .../Tasks/js/DetailsScheduleModal.js | 158 ++ .../wwwroot/AssetsAdminNew/Tasks/js/Edit.js | 4 +- .../wwwroot/AssetsAdminNew/Tasks/js/Index.js | 586 +++++- .../wwwroot/AssetsAdminNew/Tasks/js/create.js | 8 +- .../pages/RollCall/js/Grouping.js | 63 +- 38 files changed, 6011 insertions(+), 564 deletions(-) create mode 100644 AccountManagement.Application.Contracts/TaskSchedule/TaskScheduleDetailsViewModel.cs create mode 100644 AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.Designer.cs create mode 100644 AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.cs create mode 100644 AccountMangement.Infrastructure.EFCore/Repository/TaskScheduleRepository.cs create mode 100644 ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateScheduleModal.cshtml create mode 100644 ServiceHost/Areas/AdminNew/Pages/Company/Task/DetailsScheduleModal.cshtml create mode 100644 ServiceHost/wwwroot/AssetsAdminNew/Tasks/css/createScheduleModal.css create mode 100644 ServiceHost/wwwroot/AssetsAdminNew/Tasks/js/CreateScheduleModal.js create mode 100644 ServiceHost/wwwroot/AssetsAdminNew/Tasks/js/DetailsScheduleModal.js diff --git a/AccountManagement.Application.Contracts/Task/CreateTask.cs b/AccountManagement.Application.Contracts/Task/CreateTask.cs index 954aa43e..89729e8a 100644 --- a/AccountManagement.Application.Contracts/Task/CreateTask.cs +++ b/AccountManagement.Application.Contracts/Task/CreateTask.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using IPE.SmsIrClient.Models.Results; using Microsoft.AspNetCore.Http; namespace AccountManagement.Application.Contracts.Task; @@ -19,9 +20,9 @@ public class CreateTask #region Task Schedule public string ScheduleCount { get; set; } - public string ScheduleType{ get; set; } + public TaskScheduleType ScheduleType { get; set; } public bool HasSchedule { get; set; } - public string ScheduleUnitType { get; set; } + public TaskScheduleUnitType ScheduleUnitType { get; set; } public string ScheduleUnitNumber { get; set; } public long TaskScheduleId { get; set; } @@ -30,4 +31,18 @@ public class CreateTask +} + +public enum TaskScheduleType +{ + Limited, + Unlimited +} + +public enum TaskScheduleUnitType +{ + Day, + Week, + Month, + Year } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Task/EditTask.cs b/AccountManagement.Application.Contracts/Task/EditTask.cs index f47de8c4..7769c629 100644 --- a/AccountManagement.Application.Contracts/Task/EditTask.cs +++ b/AccountManagement.Application.Contracts/Task/EditTask.cs @@ -20,4 +20,5 @@ public class EditTask:CreateTask public long? TicketId { get; set; } public List AssignsLists { get; set; } public bool HasTicket { get; set; } + public long TaskScheduleId { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Task/ITaskApplication.cs b/AccountManagement.Application.Contracts/Task/ITaskApplication.cs index 8391d3f1..7cf7e078 100644 --- a/AccountManagement.Application.Contracts/Task/ITaskApplication.cs +++ b/AccountManagement.Application.Contracts/Task/ITaskApplication.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Application; using AccountManagement.Application.Contracts.Assign; using AccountManagement.Application.Contracts.TaskMessage; @@ -24,6 +25,13 @@ public interface ITaskApplication List GetSentTasks(TaskSearchModel searchModel); List GetTasksHaveTicket(TaskSearchModel searchModel); + /// + /// لیست تسک های دوره ای ایجاد شده توسط کاربر + /// + /// + /// + List GetTaskScheduleList(TaskSearchModel searchModel); + // گرفتن مهلت برای یک وظیفه OperationResult CreateRequestTime(CreateTaskTimeRequest command); List GetRequestTaskHasTicket(TaskSearchModel searchModel); @@ -46,10 +54,10 @@ public interface ITaskApplication OperationResult CreateTaskByPosition(CreateTask command, List positionIds); List GetRequestedTasks(TaskSearchModel searchModel); List AllRequestedTasks(TaskSearchModel searchModel); - int GetRequestedTasksCount(); + Task GetRequestedTasksCount(); - int TasksHaveTicketCounts(long userId); - int TasksHaveTicketRequestsCount(long userId); + Task TasksHaveTicketCounts(long userId); + Task TasksHaveTicketRequestsCount(long userId); List GetTaskMessages(long assignId); @@ -63,16 +71,14 @@ public interface ITaskApplication List GetAssignsByTaskId(long taskId); - int RequestedAndOverdueTasksCount(long userId); + Task RequestedAndOverdueTasksCount(long userId); - /// - ///تعداد تسک های شخصی و دریافتی برای امروز و یا عقب افتاده - /// - /// - /// - int OverdueTasksCount(long userId); + /// + /// تعداد تسک های شخصی و دریافتی برای امروز و یا عقب افتاده + /// + /// + /// + Task OverdueTasksCount(long userId); - //متد انتقال داده از تسک به ارجاعی ها - //OperationResult MoveDataFRomTaskToAssign(); -} \ No newline at end of file +} diff --git a/AccountManagement.Application.Contracts/Task/TaskViewModel.cs b/AccountManagement.Application.Contracts/Task/TaskViewModel.cs index f66b07a2..30c4562b 100644 --- a/AccountManagement.Application.Contracts/Task/TaskViewModel.cs +++ b/AccountManagement.Application.Contracts/Task/TaskViewModel.cs @@ -50,5 +50,7 @@ public class TaskViewModel public bool CanCheckRequests { get; set; } public AssignViewModel AssignedReceiverViewModel { get; set; } - + public TaskScheduleType ScheduleType { get; set; } + public TaskScheduleUnitType ScheduleUnitType { get; set; } + public long TaskScheduleId { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/TaskSchedule/ITaskScheduleApplication.cs b/AccountManagement.Application.Contracts/TaskSchedule/ITaskScheduleApplication.cs index a67e9ac8..02119f47 100644 --- a/AccountManagement.Application.Contracts/TaskSchedule/ITaskScheduleApplication.cs +++ b/AccountManagement.Application.Contracts/TaskSchedule/ITaskScheduleApplication.cs @@ -1,4 +1,6 @@ -using _0_Framework.Application; +using System; +using System.Threading.Tasks; +using _0_Framework.Application; using AccountManagement.Application.Contracts.Task; namespace AccountManagement.Application.Contracts.TaskSchedule; @@ -6,7 +8,8 @@ namespace AccountManagement.Application.Contracts.TaskSchedule; public interface ITaskScheduleApplication { OperationResult Create(CreateTask command); - OperationResult CreateLimitedTasks(CreateTask command); - OperationResult CreateUnlimitedTasks(CreateTask command); + Task GetDetails(long id); + + OperationResult Remove(long taskScheduleId); } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/TaskSchedule/TaskScheduleDetailsViewModel.cs b/AccountManagement.Application.Contracts/TaskSchedule/TaskScheduleDetailsViewModel.cs new file mode 100644 index 00000000..637f1fbb --- /dev/null +++ b/AccountManagement.Application.Contracts/TaskSchedule/TaskScheduleDetailsViewModel.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using AccountManagement.Application.Contracts.Media; +using AccountManagement.Application.Contracts.Task; + +namespace AccountManagement.Application.Contracts.TaskSchedule; + +public class TaskScheduleDetailsViewModel +{ + public string SenderName { get; set; } + public List AssignedName { get; set; } + public TaskScheduleType TaskScheduleType { get; set; } + public TaskScheduleUnitType TaskScheduleUnitType { get; set; } + public string UnitNumber { get; set; } + public string CreationDateFa { get; set; } + public string ContractingPartyName { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public List Medias { get; set; } + +} \ No newline at end of file diff --git a/AccountManagement.Application/TaskApplication.cs b/AccountManagement.Application/TaskApplication.cs index bd527766..a3da6bd2 100644 --- a/AccountManagement.Application/TaskApplication.cs +++ b/AccountManagement.Application/TaskApplication.cs @@ -16,6 +16,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using System.Threading.Tasks; namespace AccountManagement.Application; @@ -508,6 +509,11 @@ public class TaskApplication : ITaskApplication return _taskRepository.GetTasksHaveTicket(searchModel); } + public List GetTaskScheduleList(TaskSearchModel searchModel) + { + return _taskRepository.GetTaskScheduleList(searchModel); + } + //ساخت درخواست مهلت public OperationResult CreateRequestTime(CreateTaskTimeRequest command) { @@ -589,6 +595,9 @@ public class TaskApplication : ITaskApplication { return operation.Failed("تاریخی برای درخواست وظیفه ثبت نشده است"); } + + + assign.AcceptTimeRequest(); message = string.IsNullOrWhiteSpace(message) ? "درخواست شما مورد تایید قرار گرفت" : message; var messageEntity = new TaskMessage(message, "تایید درخواست مهلت", assign.id); @@ -865,14 +874,14 @@ public class TaskApplication : ITaskApplication return _taskRepository.AllRequestedTasks(searchModel); } - public int TasksHaveTicketCounts(long userId) + public async Task TasksHaveTicketCounts(long userId) { - return _taskRepository.TasksHaveTicketCounts(userId); + return await _taskRepository.TasksHaveTicketCounts(userId); } - public int TasksHaveTicketRequestsCount(long userId) + public async Task TasksHaveTicketRequestsCount(long userId) { - return _taskRepository.TasksHaveTicketRequestsCount(userId); + return await _taskRepository.TasksHaveTicketRequestsCount(userId); } @@ -881,9 +890,9 @@ public class TaskApplication : ITaskApplication return _taskMessageRepository.GetTaskMessages(assignId); } - public int GetRequestedTasksCount() + public async Task GetRequestedTasksCount() { - return _taskRepository.GetRequestedTasksCount(); + return await _taskRepository.GetRequestedTasksCount(); } public OperationResult ChangeRequestTimeAndAccept(string time, long taskId, long assignedId, string message) @@ -1007,15 +1016,15 @@ public class TaskApplication : ITaskApplication return _assignRepository.GetAssignsByTaskId(taskId); } - public int RequestedAndOverdueTasksCount(long userId) + public async Task RequestedAndOverdueTasksCount(long userId) { - return _taskRepository.RequestedAndOverdueTasksCount(userId); + return await _taskRepository.RequestedAndOverdueTasksCount(userId); } - public int OverdueTasksCount(long userId) + public async Task OverdueTasksCount(long userId) { - return _taskRepository.OverdueTasksCount(userId); + return await _taskRepository.OverdueTasksCount(userId); } //public OperationResult MoveDataFRomTaskToAssign() diff --git a/AccountManagement.Application/TaskScheduleApplication.cs b/AccountManagement.Application/TaskScheduleApplication.cs index e78d01b8..7e0d88f4 100644 --- a/AccountManagement.Application/TaskScheduleApplication.cs +++ b/AccountManagement.Application/TaskScheduleApplication.cs @@ -4,222 +4,347 @@ using AccountManagement.Application.Contracts.TaskSchedule; using AccountManagement.Domain.TaskScheduleAgg; using System; using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Transactions; +using AccountManagement.Domain.TaskAgg; using Company.Domain.HolidayItemAgg; +using PersianTools.Core; +using CompanyManagment.App.Contracts.Loan; namespace AccountManagement.Application; public class TaskScheduleApplication : ITaskScheduleApplication { - private readonly ITaskApplication _taskApplication; - private readonly ITaskScheduleRepository _taskScheduleRepository; - private readonly IHolidayItemRepository _holidayItemRepository; + private readonly ITaskApplication _taskApplication; + private readonly ITaskScheduleRepository _taskScheduleRepository; + private readonly IHolidayItemRepository _holidayItemRepository; + private readonly ITaskRepository _taskRepository; + public TaskScheduleApplication(ITaskApplication taskApplication, ITaskScheduleRepository taskScheduleRepository, IHolidayItemRepository holidayItemRepository, ITaskRepository taskRepository) + { + _taskApplication = taskApplication; + _taskScheduleRepository = taskScheduleRepository; + _holidayItemRepository = holidayItemRepository; + _taskRepository = taskRepository; + } - public TaskScheduleApplication(ITaskApplication taskApplication, ITaskScheduleRepository taskScheduleRepository, IHolidayItemRepository holidayItemRepository) - { - _taskApplication = taskApplication; - _taskScheduleRepository = taskScheduleRepository; - _holidayItemRepository = holidayItemRepository; - } - - public OperationResult Create(CreateTask command) - { - OperationResult operation = new OperationResult(); + public OperationResult Create(CreateTask command) + { + OperationResult operation = new OperationResult(); - if (command.HasSchedule) - { - switch (command.ScheduleType) - { - case "limited": - if (Convert.ToInt32(command.ScheduleCount) > 60) - { - return operation.Failed("تعداد وارد شده بیشتر از حد مجاز است"); - } - return CreateLimitedTasks(command); - break; + if (command.HasSchedule) + { + switch (command.ScheduleType) + { + case TaskScheduleType.Limited: + if (Convert.ToInt32(command.ScheduleCount) > 60) + { + return operation.Failed("تعداد وارد شده بیشتر از حد مجاز است"); + } + return CreateLimitedTasks(command); + break; - case "unlimited": - return CreateUnlimitedTasks(command); - break; + case TaskScheduleType.Unlimited: + return CreateUnlimitedTasks(command); + break; - default: - return operation.Failed("خطای سیستمی!"); + default: + return operation.Failed("نوع وظیفه محول شده مشخص نمیباشد"); - } - } - else - { - return operation.Failed("این تسک بصورت زمان بندی شده نمیباشد"); - } - } + } + } + else + { + return operation.Failed("این تسک بصورت دوره ای نمیباشد"); + } + } - public OperationResult CreateLimitedTasks(CreateTask command) - { - OperationResult operation = new OperationResult(); - if (Convert.ToInt32(command.ScheduleCount) < 1 || string.IsNullOrWhiteSpace(command.ScheduleCount)) - { - return operation.Failed("تعداد وارد شده باید بیشتر از 2 باشد"); - } + public async Task GetDetails(long id) + { + return await _taskScheduleRepository.GetDetails(id); + } - switch (command.ScheduleUnitType) - { - case "year": - if (Convert.ToInt32(command.ScheduleCount) != 1) - { - return operation.Failed("دوره نمیتواند بیشتر از 1 سال باشد"); - } - break; - case "month": - if (Convert.ToInt32(command.ScheduleCount) > 12) - { - return operation.Failed("بازه وارد شده نا معتبر است"); - } - break; - case "week": - if (command.ScheduleUnitNumber != "first" && command.ScheduleUnitNumber != "last") - { - return operation.Failed("بازه وارد شده نا معتبر است"); - } - break; - case "day": - if (Convert.ToInt32(command.ScheduleUnitNumber) > 29) - { - return operation.Failed("بازه وارد شده نا معتبر است"); - } - break; - default: - return operation.Failed("نوع بازه مشخص نمیباشد"); - break; + public OperationResult Remove(long taskScheduleId) + { + var op = new OperationResult(); + var taskSchedule = _taskScheduleRepository.Get(taskScheduleId); + if (taskSchedule == null) + return op.Failed("وظیفه مورد نظر یافت نشد"); + var tasks = _taskRepository.GetTasksByTaskScheduleId(taskScheduleId); + var assigns = tasks.SelectMany(x => x.Assigns); + if (assigns.Any(x => x.IsCanceledRequest || x.IsDone || x.IsCancel || x.TimeRequest || x.AcceptedTimeRequest > 0)) + { + taskSchedule.DeActive(); - } - try - { - DateTime previousDateRaw = command.EndTaskDate.ToEndDayOfGeorgianDateTime(); - DateTime previousDateEdited = command.EndTaskDate.ToEndDayOfGeorgianDateTime(); + var removableTask = tasks.Where(x => x.Assigns.All(a => a.IsDone == false && a.IsCancel == false)).ToList(); + _taskRepository.RemoveRange(removableTask); - int count = Convert.ToInt32(command.ScheduleCount); - bool isInt = int.TryParse(command.ScheduleUnitNumber, out int unitNumber); - string kindOfWeekUnit = isInt ? "" : command.ScheduleUnitNumber; - var taskSchedule = new TaskSchedule(command.ScheduleCount, command.ScheduleType, command.ScheduleUnitType, - command.ScheduleUnitNumber, previousDateEdited); - _taskScheduleRepository.Create(taskSchedule); - _taskScheduleRepository.SaveChanges(); - command.TaskScheduleId = taskSchedule.id; + } + else + { + _taskScheduleRepository.Remove(taskSchedule); + _taskRepository.RemoveRange(tasks); + } + _taskRepository.SaveChanges(); + return op.Succcedded(); + } - switch (command.ScheduleUnitType) - { - case "year": - for (int i = 1; i <= count; i++) - { - command.EndTaskDate = previousDateEdited.ToFarsi(); - operation = _taskApplication.CreateTask(command); - taskSchedule.SetLastEndTaskDate(previousDateEdited); + private OperationResult CreateLimitedTasks(CreateTask command) + { + OperationResult operation = new OperationResult(); + if (Convert.ToInt32(command.ScheduleCount) < 1 || string.IsNullOrWhiteSpace(command.ScheduleCount)) + { + return operation.Failed("تعداد وارد شده باید بیشتر از 2 باشد"); + } - bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); - while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) - { - previousDateEdited = previousDateRaw.AddDays(1); - isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); + switch (command.ScheduleUnitType) + { + case TaskScheduleUnitType.Year: + if (Convert.ToInt32(command.ScheduleCount) != 1) + { + return operation.Failed("دوره نمیتواند بیشتر از 1 سال باشد"); + } + break; + case TaskScheduleUnitType.Month: + if (Convert.ToInt32(command.ScheduleCount) > 60) + { + return operation.Failed("بازه وارد شده نا معتبر است"); + } + break; + case TaskScheduleUnitType.Week: + if (command.ScheduleUnitNumber != "first" && command.ScheduleUnitNumber != "last") + { + return operation.Failed("بازه وارد شده نا معتبر است"); + } + break; + case TaskScheduleUnitType.Day: + if (Convert.ToInt32(command.ScheduleUnitNumber) > 29) + { + return operation.Failed("بازه وارد شده نا معتبر است"); + } + break; + default: + return operation.Failed("نوع بازه مشخص نمیباشد"); + break; - } - previousDateRaw = previousDateRaw.AddYears(unitNumber); - previousDateEdited = previousDateRaw; + } + try + { + //using var transaction = new TransactionScope(); + DateTime previousDateRaw = command.EndTaskDate.ToEndDayOfGeorgianDateTime(); + DateTime previousDateEdited = command.EndTaskDate.ToEndDayOfGeorgianDateTime(); + var day = Convert.ToInt32(command.EndTaskDate.Substring(8, 2)); + var month = Convert.ToInt32(command.EndTaskDate.Substring(5, 2)); + var year = Convert.ToInt32(command.EndTaskDate.Substring(0, 4)); - } - break; + int count = Convert.ToInt32(command.ScheduleCount); + bool isInt = int.TryParse(command.ScheduleUnitNumber, out int unitNumber); + string kindOfWeekUnit = isInt ? "" : command.ScheduleUnitNumber; + var taskSchedule = new TaskSchedule(command.ScheduleCount, command.ScheduleType, command.ScheduleUnitType, + command.ScheduleUnitNumber, previousDateEdited); + _taskScheduleRepository.Create(taskSchedule); + _taskScheduleRepository.SaveChanges(); + command.TaskScheduleId = taskSchedule.id; - case "month": - for (int i = 1; i <= count; i++) - { - command.EndTaskDate = previousDateEdited.ToFarsi(); - operation = _taskApplication.CreateTask(command); - taskSchedule.SetLastEndTaskDate(previousDateEdited); - bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); - while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) - { - previousDateEdited = previousDateRaw.AddDays(1); - isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); + switch (command.ScheduleUnitType) + { + case TaskScheduleUnitType.Year: + for (int i = 1; i <= count; i++) + { + command.EndTaskDate = previousDateEdited.ToFarsi(); + operation = _taskApplication.CreateTask(command); + taskSchedule.SetLastEndTaskDate(previousDateEdited); - } - previousDateRaw = previousDateRaw.AddMonths(unitNumber); - previousDateEdited = previousDateRaw; + bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); + while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) + { + previousDateEdited = previousDateRaw.AddDays(1); + isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); + } + previousDateRaw = previousDateRaw.AddYears(unitNumber); + previousDateEdited = previousDateRaw; + } + break; - } - break; + case TaskScheduleUnitType.Month: + bool endOfMonth = day == 31; - case "week": - for (int i = 1; i <= count; i++) - { - if (string.IsNullOrWhiteSpace(kindOfWeekUnit)) - { - throw new InvalidDataException(); - } + if (endOfMonth) + { + for (int i = 1; i < count; i++) + { + command.EndTaskDate = previousDateEdited.ToFarsi(); + operation = _taskApplication.CreateTask(command); + taskSchedule.SetLastEndTaskDate(previousDateEdited); + if (month >= 12) + { + var extra = month - 12; + year++; + month = extra+unitNumber; + } + else + { + month = unitNumber + month; + } + previousDateRaw = $"{year:0000}/{month:00}/01".FindeEndOfMonth().ToGeorgianDateTime(); + bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); + while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) + { + previousDateEdited = previousDateRaw.AddDays(1); + isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); - command.EndTaskDate = kindOfWeekUnit switch - { - "first" => previousDateRaw.GetNextDayOfWeek(DayOfWeek.Saturday).ToFarsi(), - "last" => previousDateRaw.GetNextDayOfWeek(DayOfWeek.Thursday).ToFarsi(), - _ => throw new InvalidDataException() - }; - operation = _taskApplication.CreateTask(command); - taskSchedule.SetLastEndTaskDate(previousDateEdited); - bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); - while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) - { - previousDateEdited = previousDateRaw.AddDays(1); - isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); + } - } - previousDateRaw = command.EndTaskDate.ToGeorgianDateTime(); - previousDateEdited = previousDateRaw; + + + previousDateEdited = previousDateRaw; + + } + } + else + { + for (int i = 1; i < count; i++) + { + command.EndTaskDate = previousDateEdited.ToFarsi(); + operation = _taskApplication.CreateTask(command); + taskSchedule.SetLastEndTaskDate(previousDateEdited); + var endDay = 0; + + if (month >= 12) + { + var extra = month - 12; + year++; + month = extra + unitNumber; + + } + else + { + month = unitNumber + month; + } + + if (day == 30) + { + if (month == 12) + { + var lastYearDay = Convert.ToInt32($"{year:0000}/{month:00}/1".FindeEndOfMonth() + .Substring(8, 2)); + endDay = lastYearDay == 30 ? lastYearDay : 29; + } + + } + + previousDateEdited = endDay == 0 + ? $"{year:0000}/{month:00}/{day:00}".ToGeorgianDateTime() + : $"{year:0000}/{month:00}/{endDay:00}".ToGeorgianDateTime(); + } - } - break; + //for (int i = 1; i <= count; i++) + //{ + // command.EndTaskDate = previousDateEdited.ToFarsi(); + // operation = _taskApplication.CreateTask(command); + // taskSchedule.SetLastEndTaskDate(previousDateEdited); + // previousDateRaw = $"{year:0000}/{month:00}/01".FindeEndOfMonth().ToGeorgianDateTime(); + // bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); + // while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) + // { + // previousDateEdited = previousDateRaw.AddDays(1); + // isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); - case "day": + // } + // previousDateEdited = previousDateRaw; - for (int i = 1; i <= count; i++) - { - command.EndTaskDate = previousDateEdited.ToFarsi(); - operation = _taskApplication.CreateTask(command); - taskSchedule.SetLastEndTaskDate(previousDateEdited); - previousDateRaw = previousDateRaw.AddDays(unitNumber); - bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); - while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) - { - previousDateEdited = previousDateRaw.AddDays(1); - isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); + //} + } - } + break; - previousDateEdited = previousDateRaw; - } - break; + case TaskScheduleUnitType.Week: + for (int i = 1; i <= count; i++) + { + if (string.IsNullOrWhiteSpace(kindOfWeekUnit)) + { + throw new InvalidDataException(); + } - } - _taskScheduleRepository.SaveChanges(); - operation = operation.Succcedded(); - return operation; - } - catch (Exception e) - { - return operation.Failed(e.ToString()); - } - } + command.EndTaskDate = kindOfWeekUnit switch + { + "first" => previousDateRaw.GetNextDayOfWeek(DayOfWeek.Saturday).ToFarsi(), + "last" => previousDateRaw.GetNextDayOfWeek(DayOfWeek.Thursday).ToFarsi(), + _ => throw new InvalidDataException() + }; + operation = _taskApplication.CreateTask(command); + taskSchedule.SetLastEndTaskDate(previousDateEdited); + bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); + while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) + { + previousDateEdited = previousDateRaw.AddDays(1); + isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); - public OperationResult CreateUnlimitedTasks(CreateTask command) - { - var operation = _taskApplication.CreateTask(command); - if (!operation.IsSuccedded) - return operation; - var lastDate = command.EndTaskDate.ToGeorgianDateTime(); - var taskSchedule = new TaskSchedule(command.ScheduleCount, command.ScheduleType, command.ScheduleUnitType, - command.ScheduleUnitNumber, lastDate); - _taskScheduleRepository.Create(taskSchedule); - _taskScheduleRepository.SaveChanges(); - return operation.Succcedded(); + } + previousDateRaw = command.EndTaskDate.ToGeorgianDateTime(); + previousDateEdited = previousDateRaw; - } + + } + break; + + case TaskScheduleUnitType.Day: + + for (int i = 1; i <= count; i++) + { + command.EndTaskDate = previousDateEdited.ToFarsi(); + operation = _taskApplication.CreateTask(command); + taskSchedule.SetLastEndTaskDate(previousDateEdited); + previousDateRaw = previousDateRaw.AddDays(unitNumber); + bool isHoliday = _holidayItemRepository.GetHoliday(previousDateRaw); + while (isHoliday || previousDateEdited.DayOfWeek == DayOfWeek.Friday) + { + previousDateEdited = previousDateRaw.AddDays(1); + isHoliday = _holidayItemRepository.GetHoliday(previousDateEdited); + + } + + previousDateEdited = previousDateRaw; + } + break; + + } + _taskScheduleRepository.SaveChanges(); + //transaction.Complete(); + operation = operation.Succcedded(); + return operation; + } + catch (Exception e) + { + return operation.Failed(e.ToString()); + } + } + + private OperationResult CreateUnlimitedTasks(CreateTask command) + { + using var transaction = new TransactionScope(); + + var lastDate = command.EndTaskDate.ToGeorgianDateTime(); + + var taskSchedule = new TaskSchedule(command.ScheduleCount, command.ScheduleType, command.ScheduleUnitType, + command.ScheduleUnitNumber, lastDate); + + _taskScheduleRepository.Create(taskSchedule); + _taskScheduleRepository.SaveChanges(); + + command.TaskScheduleId = taskSchedule.id; + + var operation = _taskApplication.CreateTask(command); + if (!operation.IsSuccedded) + return operation; + + + _taskScheduleRepository.SaveChanges(); + transaction.Complete(); + return operation.Succcedded(); + + } } \ No newline at end of file diff --git a/AccountManagement.Application/TaskSubjectApplication.cs b/AccountManagement.Application/TaskSubjectApplication.cs index c27fa674..42383942 100644 --- a/AccountManagement.Application/TaskSubjectApplication.cs +++ b/AccountManagement.Application/TaskSubjectApplication.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using _0_Framework.Application; using AccountManagement.Application.Contracts.TaskSubject; using AccountManagement.Domain.TaskSubjectAgg; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace AccountManagement.Application; diff --git a/AccountManagement.Configuration/AccountManagementBootstrapper.cs b/AccountManagement.Configuration/AccountManagementBootstrapper.cs index 1a97d103..132bf2d6 100644 --- a/AccountManagement.Configuration/AccountManagementBootstrapper.cs +++ b/AccountManagement.Configuration/AccountManagementBootstrapper.cs @@ -7,6 +7,7 @@ using AccountManagement.Application.Contracts.Role; using AccountManagement.Application.Contracts.SubAccount; using AccountManagement.Application.Contracts.SubAccountPermissionSubtitle; using AccountManagement.Application.Contracts.Task; +using AccountManagement.Application.Contracts.TaskSchedule; using AccountManagement.Application.Contracts.TaskSubject; using AccountManagement.Application.Contracts.Ticket; using AccountManagement.Application.Contracts.TicketAccessAccount; @@ -25,6 +26,7 @@ using AccountManagement.Domain.SubAccountPermissionSubtitle4Agg; using AccountManagement.Domain.SubAccountRoleAgg; using AccountManagement.Domain.TaskAgg; using AccountManagement.Domain.TaskMessageAgg; +using AccountManagement.Domain.TaskScheduleAgg; using AccountManagement.Domain.TaskSubjectAgg; using AccountManagement.Domain.TicketAccessAccountAgg; using AccountManagement.Domain.TicketAgg; @@ -62,6 +64,8 @@ namespace AccountManagement.Configuration services.AddScoped(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AccountManagement.Domain/AssignAgg/Assign.cs b/AccountManagement.Domain/AssignAgg/Assign.cs index 60188e97..bb31be00 100644 --- a/AccountManagement.Domain/AssignAgg/Assign.cs +++ b/AccountManagement.Domain/AssignAgg/Assign.cs @@ -8,7 +8,7 @@ namespace AccountManagement.Domain.AssignAgg; public class Assign : EntityBase { - public Assign(long taskId, long assignerId, long assignedId, int assignerPositionValue, string assignedName, int assignedPositionValue, DateTime endTaskDate, bool firstTimeCreation = false) + public Assign(long taskId, long assignerId, long assignedId, int assignerPositionValue, string assignedName, int assignedPositionValue, DateTime endTaskDate, bool firstTimeCreation=false) { TaskId = taskId; AssignerId = assignerId; @@ -18,7 +18,7 @@ public class Assign : EntityBase AssignedPositionValue = assignedPositionValue; EndTaskDate = endTaskDate; FirstTimeCreation = firstTimeCreation; - } + } //آیدی شخص ارسال کننده public long TaskId { get; private set; } @@ -52,7 +52,9 @@ public class Assign : EntityBase public string? DoneDescription { get; private set; } public bool IsCanceledRequest { get; private set; } + public bool FirstTimeCreation { get; private set; } + public Tasks Task { get; set; } public List TaskMessageList { get; set; } @@ -71,9 +73,9 @@ public class Assign : EntityBase { TimeRequest = false; AcceptedTimeRequest++; - EndTaskDate = RequestDate.Value; + EndTaskDate = RequestDate < DateTime.Today ? DateTime.Today : RequestDate.Value; - } + } public void RejectTimeRequest() { TimeRequest = false; diff --git a/AccountManagement.Domain/TaskAgg/ITaskRepository.cs b/AccountManagement.Domain/TaskAgg/ITaskRepository.cs index 80b276fe..22c94c92 100644 --- a/AccountManagement.Domain/TaskAgg/ITaskRepository.cs +++ b/AccountManagement.Domain/TaskAgg/ITaskRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Domain; using AccountManagement.Application.Contracts.Task; @@ -88,11 +89,22 @@ public interface ITaskRepository:IRepository /// List GetTasksHaveTicket(TaskSearchModel searchModel); + + + + /// + /// لیست تسک های دوره ای ایجاد شده توسط کاربر + /// + /// + /// + List GetTaskScheduleList(TaskSearchModel searchModel); + + /// /// تعداد تسک های درخواستی. بدون تیکت /// /// - int GetRequestedTasksCount(); + Task GetRequestedTasksCount(); /// /// گرفتن جزئیات درخواست وظیفه @@ -114,39 +126,38 @@ public interface ITaskRepository:IRepository /// bool HasOverdueTasks(long userId); - /// - ///مجوع تعداد تسک های عقب افتاده و درخواستی - /// - /// - /// - int RequestedAndOverdueTasksCount(long userId); + /// + /// مجوع تعداد تسک های عقب افتاده و درخواستی + /// + /// + /// + Task RequestedAndOverdueTasksCount(long userId); /// /// تعداد تسک های دارای تیکت /// /// /// - int TasksHaveTicketCounts(long userId); + Task TasksHaveTicketCounts(long userId); /// /// تعداد درخواست های تسک های دارا تیکت /// /// /// - int TasksHaveTicketRequestsCount(long userId); + Task TasksHaveTicketRequestsCount(long userId); - /// - ///تعداد تسک های شخصی و دریافتی برای امروز و یا عقب افتاده - /// - /// - /// - int OverdueTasksCount(long userId); + /// + /// تعداد تسک های شخصی و دریافتی برای امروز و یا عقب افتاده + /// + /// + /// + Task OverdueTasksCount(long userId); // گرفتن پیام های مربوط به هر تسک + List GetTasksByTaskScheduleId(long taskScheduleId); - - //OperationResult MoveDataFRomTaskToAssign(); - + void RemoveRange(IEnumerable tasks); } \ No newline at end of file diff --git a/AccountManagement.Domain/TaskScheduleAgg/ITaskScheduleRepository.cs b/AccountManagement.Domain/TaskScheduleAgg/ITaskScheduleRepository.cs index 21bb249d..4cd0d651 100644 --- a/AccountManagement.Domain/TaskScheduleAgg/ITaskScheduleRepository.cs +++ b/AccountManagement.Domain/TaskScheduleAgg/ITaskScheduleRepository.cs @@ -1,8 +1,11 @@ -using _0_Framework.Domain; +using System.Threading.Tasks; +using _0_Framework.Domain; +using AccountManagement.Application.Contracts.TaskSchedule; namespace AccountManagement.Domain.TaskScheduleAgg; -public interface ITaskScheduleRepository:IRepository +public interface ITaskScheduleRepository : IRepository { - + Task GetDetails(long id); + void Remove(TaskSchedule entity); } \ No newline at end of file diff --git a/AccountManagement.Domain/TaskScheduleAgg/TaskSchedule.cs b/AccountManagement.Domain/TaskScheduleAgg/TaskSchedule.cs index da4a037f..6f54d275 100644 --- a/AccountManagement.Domain/TaskScheduleAgg/TaskSchedule.cs +++ b/AccountManagement.Domain/TaskScheduleAgg/TaskSchedule.cs @@ -1,29 +1,38 @@ using System; using System.Collections.Generic; +using _0_Framework.Application; using _0_Framework.Domain; +using AccountManagement.Application.Contracts.Task; using AccountManagement.Domain.TaskAgg; namespace AccountManagement.Domain.TaskScheduleAgg; public class TaskSchedule:EntityBase { - public TaskSchedule(string count, string type, string unitType, string unitNumber, DateTime lastEndTaskDate) + public TaskSchedule(string count, TaskScheduleType type, TaskScheduleUnitType unitType, string unitNumber, DateTime lastEndTaskDate) { Count = count; Type = type; UnitType = unitType; UnitNumber = unitNumber; LastEndTaskDate = lastEndTaskDate; + IsCanceled = IsActive.True; } public string Count { get; private set; } - public string Type { get; private set; } - public string UnitType { get; private set; } + public TaskScheduleType Type { get; private set; } + public TaskScheduleUnitType UnitType { get; private set; } public string UnitNumber { get; private set; } public DateTime LastEndTaskDate { get; private set; } + public IsActive IsCanceled { get; private set; } public List TasksList { get; set; } public void SetLastEndTaskDate(DateTime lastEndTaskDate) { LastEndTaskDate = lastEndTaskDate; } + + public void DeActive() + { + IsCanceled = IsActive.False; + } } \ No newline at end of file diff --git a/AccountMangement.Infrastructure.EFCore/AccountContext.cs b/AccountMangement.Infrastructure.EFCore/AccountContext.cs index 235d0449..df25879d 100644 --- a/AccountMangement.Infrastructure.EFCore/AccountContext.cs +++ b/AccountMangement.Infrastructure.EFCore/AccountContext.cs @@ -27,6 +27,7 @@ using AccountManagement.Domain.SubAccountPermissionSubtitle3Agg; using AccountManagement.Domain.SubAccountPermissionSubtitle4Agg; using AccountManagement.Domain.SubAccountRoleAgg; using AccountMangement.Infrastructure.EFCore.Seed; +using AccountManagement.Domain.TaskScheduleAgg; namespace AccountMangement.Infrastructure.EFCore { @@ -57,6 +58,9 @@ namespace AccountMangement.Infrastructure.EFCore public DbSet TicketAccessAccounts { get; set; } + public DbSet TaskSchedules { get; set; } + + #endregion #region Pooya diff --git a/AccountMangement.Infrastructure.EFCore/Mappings/TaskScheduleMapping.cs b/AccountMangement.Infrastructure.EFCore/Mappings/TaskScheduleMapping.cs index 2f4a0f50..ff388549 100644 --- a/AccountMangement.Infrastructure.EFCore/Mappings/TaskScheduleMapping.cs +++ b/AccountMangement.Infrastructure.EFCore/Mappings/TaskScheduleMapping.cs @@ -12,9 +12,10 @@ public class TaskScheduleMapping : IEntityTypeConfiguration builder.HasKey(x => x.id); builder.Property(x => x.Count).HasMaxLength(10); - builder.Property(x => x.Type).HasMaxLength(12); + builder.Property(x => x.Type).HasConversion().HasMaxLength(12); builder.Property(x => x.UnitNumber).HasMaxLength(10); - builder.Property(x => x.UnitType).HasMaxLength(10); + builder.Property(x => x.UnitType).HasConversion().HasMaxLength(10); + builder.Property(x => x.IsCanceled).HasConversion().HasMaxLength(5); builder.HasMany(x => x.TasksList).WithOne(x => x.TaskSchedule) .HasForeignKey(x => x.TaskScheduleId); diff --git a/AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.Designer.cs b/AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.Designer.cs new file mode 100644 index 00000000..52f1c41a --- /dev/null +++ b/AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.Designer.cs @@ -0,0 +1,1274 @@ +// +using System; +using AccountMangement.Infrastructure.EFCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AccountMangement.Infrastructure.EFCore.Migrations +{ + [DbContext(typeof(AccountContext))] + [Migration("20250407150638_add TaskSchedule")] + partial class addTaskSchedule + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AccountManagement.Domain.AccountAgg.Account", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AdminAreaPermission") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("ClientAriaPermission") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Email") + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("Fullname") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("IsActiveString") + .HasMaxLength(6) + .HasColumnType("nvarchar(6)"); + + b.Property("Mobile") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("NationalCode") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("PositionId") + .HasMaxLength(10) + .HasColumnType("bigint"); + + b.Property("PositionIsActive") + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("ProfilePhoto") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("RoleId") + .HasColumnType("bigint"); + + b.Property("RoleName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("VerifyCode") + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.HasKey("id"); + + b.HasIndex("PositionId"); + + b.HasIndex("RoleId"); + + b.ToTable("Accounts", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.AccountLeftWorkAgg.AccountLeftWork", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AccountId") + .HasColumnType("bigint"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("LeftWorkGr") + .HasColumnType("datetime2"); + + b.Property("RoleId") + .HasColumnType("bigint"); + + b.Property("StartWorkGr") + .HasColumnType("datetime2"); + + b.Property("WorkshopId") + .HasColumnType("bigint"); + + b.HasKey("id"); + + b.HasIndex("AccountId"); + + b.ToTable("AccountLeftWork", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.AdminResponseAgg.AdminResponse", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AdminAccountId") + .HasColumnType("bigint"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("IsActiveString") + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("Response") + .HasColumnType("ntext"); + + b.Property("TicketId") + .HasColumnType("bigint"); + + b.HasKey("id"); + + b.HasIndex("TicketId"); + + b.ToTable("AdminResponses", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.AdminResponseMediaAgg.AdminResponseMedia", b => + { + b.Property("AdminResponseId") + .HasColumnType("bigint"); + + b.Property("MediaId") + .HasColumnType("bigint"); + + b.HasKey("AdminResponseId", "MediaId"); + + b.HasIndex("MediaId"); + + b.ToTable("AdminResponseMedias", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.AssignAgg.Assign", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AcceptedTimeRequest") + .HasColumnType("int"); + + b.Property("AssignedId") + .HasColumnType("bigint"); + + b.Property("AssignedName") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("AssignedPositionValue") + .HasColumnType("int"); + + b.Property("AssignerId") + .HasColumnType("bigint"); + + b.Property("AssignerPositionValue") + .HasColumnType("int"); + + b.Property("CancelDescription") + .HasColumnType("ntext"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("DoneDescription") + .HasColumnType("ntext"); + + b.Property("EndTaskDate") + .HasColumnType("datetime2"); + + b.Property("FirstTimeCreation") + .HasColumnType("bit"); + + b.Property("IsCancel") + .HasColumnType("bit"); + + b.Property("IsCanceledRequest") + .HasColumnType("bit"); + + b.Property("IsDone") + .HasColumnType("bit"); + + b.Property("IsDoneRequest") + .HasColumnType("bit"); + + b.Property("RequestDate") + .HasColumnType("datetime2"); + + b.Property("TaskId") + .HasColumnType("bigint"); + + b.Property("TimeRequest") + .HasColumnType("bit"); + + b.Property("TimeRequestDescription") + .HasColumnType("ntext"); + + b.HasKey("id"); + + b.HasIndex("TaskId"); + + b.ToTable("Assigns", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.CameraAccountAgg.CameraAccount", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AccountId") + .HasColumnType("bigint"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("IsActiveSting") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("Mobile") + .HasMaxLength(11) + .HasColumnType("nvarchar(11)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("WorkshopId") + .HasColumnType("bigint"); + + b.Property("WorkshopName") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("id"); + + b.HasIndex("AccountId"); + + b.ToTable("CameraAccounts", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.ClientResponseAgg.ClientResponse", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Response") + .HasColumnType("ntext"); + + b.Property("TicketId") + .HasColumnType("bigint"); + + b.HasKey("id"); + + b.HasIndex("TicketId"); + + b.ToTable("ClientResponses", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.ClientResponseMediaAgg.ClientResponseMedia", b => + { + b.Property("ClientResponseId") + .HasColumnType("bigint"); + + b.Property("MediaId") + .HasColumnType("bigint"); + + b.HasKey("ClientResponseId", "MediaId"); + + b.HasIndex("MediaId"); + + b.ToTable("ClientResponseMedias", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.MediaAgg.Media", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("Category") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Path") + .HasColumnType("ntext"); + + b.Property("ServiceName") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Type") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.HasKey("id"); + + b.ToTable("Medias", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.PositionAgg.Position", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("PositionName") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PositionValue") + .HasMaxLength(2) + .HasColumnType("int"); + + b.HasKey("id"); + + b.ToTable("Positions", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.RoleAgg.Role", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("id"); + + b.ToTable("Roles", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountAgg.SubAccount", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AccountId") + .HasColumnType("bigint"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("FName") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("IsActive") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("LName") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("NationalCode") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("nvarchar(1000)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasMaxLength(11) + .HasColumnType("nvarchar(11)"); + + b.Property("ProfilePhoto") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("SubAccountRoleId") + .HasColumnType("bigint"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("VerifyCode") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.HasKey("id"); + + b.HasIndex("SubAccountRoleId"); + + b.ToTable("SubAccounts", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle1Agg.SubAccountPermissionSubtitle1", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("Code") + .HasMaxLength(15) + .HasColumnType("int"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("id"); + + b.ToTable("SubAccountPermissionSubtitle1", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle2Agg.SubAccountPermissionSubtitle2", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("Code") + .HasMaxLength(15) + .HasColumnType("int"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("id"); + + b.HasIndex("ParentId"); + + b.ToTable("SubAccountPermissionSubtitle2", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle3Agg.SubAccountPermissionSubtitle3", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("Code") + .HasMaxLength(15) + .HasColumnType("int"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("id"); + + b.HasIndex("ParentId"); + + b.ToTable("SubAccountPermissionSubtitle3", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle4Agg.SubAccountPermissionSubtitle4", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("Code") + .HasMaxLength(15) + .HasColumnType("int"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("id"); + + b.HasIndex("ParentId"); + + b.ToTable("SubAccountPermissionSubtitle4", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRole", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AccountId") + .HasColumnType("bigint"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Title") + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("id"); + + b.ToTable("SubAccountRoles", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskAgg.Tasks", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("ContractingPartyName") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("ntext"); + + b.Property("IsActiveString") + .HasMaxLength(7) + .HasColumnType("nvarchar(7)"); + + b.Property("SenderId") + .HasColumnType("bigint"); + + b.Property("StartTaskDate") + .HasColumnType("datetime2"); + + b.Property("TaskScheduleId") + .HasColumnType("bigint"); + + b.Property("TicketId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("id"); + + b.HasIndex("TaskScheduleId"); + + b.ToTable("TasksManager", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskMediaAgg.TaskMedia", b => + { + b.Property("MediaId") + .HasColumnType("bigint"); + + b.Property("TaskId") + .HasColumnType("bigint"); + + b.HasKey("MediaId", "TaskId"); + + b.HasIndex("TaskId"); + + b.ToTable("TasksMedias", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskMessageAgg.TaskMessage", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AssignId") + .HasColumnType("bigint"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Message") + .HasColumnType("ntext"); + + b.Property("RequestedDateFa") + .HasMaxLength(25) + .HasColumnType("nvarchar(25)"); + + b.Property("TypeOfMessage") + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.HasKey("id"); + + b.HasIndex("AssignId"); + + b.ToTable("TaskMessages", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskMessageItemsAgg.TaskMessageItems", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("ReceiverAccountId") + .HasColumnType("bigint"); + + b.Property("SenderAccountId") + .HasColumnType("bigint"); + + b.Property("TaskMessageId") + .HasColumnType("bigint"); + + b.HasKey("id"); + + b.HasIndex("TaskMessageId"); + + b.ToTable("TaskMessageItems", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskScheduleAgg.TaskSchedule", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("Count") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("IsCanceled") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + + b.Property("LastEndTaskDate") + .HasColumnType("datetime2"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(12) + .HasColumnType("nvarchar(12)"); + + b.Property("UnitNumber") + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("UnitType") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.HasKey("id"); + + b.ToTable("TaskSchedules", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskSubjectAgg.TaskSubject", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Subject") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("id"); + + b.ToTable("TaskSubjects", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TicketAccessAccountAgg.TicketAccessAccount", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("AccountId") + .HasColumnType("bigint"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.HasKey("id"); + + b.ToTable("TicketAccessAccounts", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TicketAgg.Ticket", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("id")); + + b.Property("ContractingPartyName") + .HasMaxLength(155) + .HasColumnType("nvarchar(155)"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("ntext"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("SenderId") + .HasColumnType("bigint"); + + b.Property("Status") + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("SubAccountSenderId") + .HasColumnType("bigint"); + + b.Property("TicketNumber") + .HasMaxLength(12) + .HasColumnType("nvarchar(12)"); + + b.Property("TicketType") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Title") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("WorkshopId") + .HasColumnType("bigint"); + + b.HasKey("id"); + + b.ToTable("Tickets", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.TicketMediasAgg.TicketMedia", b => + { + b.Property("TicketId") + .HasColumnType("bigint"); + + b.Property("MediaId") + .HasColumnType("bigint"); + + b.HasKey("TicketId", "MediaId"); + + b.HasIndex("MediaId"); + + b.ToTable("TicketMedias", (string)null); + }); + + modelBuilder.Entity("AccountManagement.Domain.AccountAgg.Account", b => + { + b.HasOne("AccountManagement.Domain.PositionAgg.Position", "Position") + .WithMany("Accounts") + .HasForeignKey("PositionId"); + + b.HasOne("AccountManagement.Domain.RoleAgg.Role", "Role") + .WithMany("Accounts") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Position"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("AccountManagement.Domain.AccountLeftWorkAgg.AccountLeftWork", b => + { + b.HasOne("AccountManagement.Domain.AccountAgg.Account", "Account") + .WithMany("AccountLeftWorkList") + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("AccountManagement.Domain.AdminResponseAgg.AdminResponse", b => + { + b.HasOne("AccountManagement.Domain.TicketAgg.Ticket", "Ticket") + .WithMany("AdminResponses") + .HasForeignKey("TicketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ticket"); + }); + + modelBuilder.Entity("AccountManagement.Domain.AdminResponseMediaAgg.AdminResponseMedia", b => + { + b.HasOne("AccountManagement.Domain.AdminResponseAgg.AdminResponse", "AdminResponse") + .WithMany("AdminResponseMedias") + .HasForeignKey("AdminResponseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AccountManagement.Domain.MediaAgg.Media", "Media") + .WithMany("AdminResponseMedias") + .HasForeignKey("MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AdminResponse"); + + b.Navigation("Media"); + }); + + modelBuilder.Entity("AccountManagement.Domain.AssignAgg.Assign", b => + { + b.HasOne("AccountManagement.Domain.TaskAgg.Tasks", "Task") + .WithMany("Assigns") + .HasForeignKey("TaskId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("Task"); + }); + + modelBuilder.Entity("AccountManagement.Domain.CameraAccountAgg.CameraAccount", b => + { + b.HasOne("AccountManagement.Domain.AccountAgg.Account", "Account") + .WithMany("CameraAccounts") + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + }); + + modelBuilder.Entity("AccountManagement.Domain.ClientResponseAgg.ClientResponse", b => + { + b.HasOne("AccountManagement.Domain.TicketAgg.Ticket", "Ticket") + .WithMany("ClientResponses") + .HasForeignKey("TicketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ticket"); + }); + + modelBuilder.Entity("AccountManagement.Domain.ClientResponseMediaAgg.ClientResponseMedia", b => + { + b.HasOne("AccountManagement.Domain.ClientResponseAgg.ClientResponse", "ClientResponse") + .WithMany("ClientResponseMedias") + .HasForeignKey("ClientResponseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AccountManagement.Domain.MediaAgg.Media", "Media") + .WithMany("ClientResponseMedias") + .HasForeignKey("MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ClientResponse"); + + b.Navigation("Media"); + }); + + modelBuilder.Entity("AccountManagement.Domain.RoleAgg.Role", b => + { + b.OwnsMany("AccountManagement.Domain.RoleAgg.Permission", "Permissions", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property("Id")); + + b1.Property("Code") + .HasColumnType("int"); + + b1.Property("RoleId") + .HasColumnType("bigint"); + + b1.HasKey("Id"); + + b1.HasIndex("RoleId"); + + b1.ToTable("RolePermissions", (string)null); + + b1.WithOwner("Role") + .HasForeignKey("RoleId"); + + b1.Navigation("Role"); + }); + + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountAgg.SubAccount", b => + { + b.HasOne("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRole", "SubAccountRole") + .WithMany("SubAccounts") + .HasForeignKey("SubAccountRoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SubAccountRole"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle2Agg.SubAccountPermissionSubtitle2", b => + { + b.HasOne("AccountManagement.Domain.SubAccountPermissionSubtitle1Agg.SubAccountPermissionSubtitle1", "Parent") + .WithMany("Children") + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle3Agg.SubAccountPermissionSubtitle3", b => + { + b.HasOne("AccountManagement.Domain.SubAccountPermissionSubtitle2Agg.SubAccountPermissionSubtitle2", "Parent") + .WithMany("Children") + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle4Agg.SubAccountPermissionSubtitle4", b => + { + b.HasOne("AccountManagement.Domain.SubAccountPermissionSubtitle3Agg.SubAccountPermissionSubtitle3", "Parent") + .WithMany("Children") + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRole", b => + { + b.OwnsMany("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRolePermission", "RolePermissions", b1 => + { + b1.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property("id")); + + b1.Property("PermissionCode") + .HasColumnType("int"); + + b1.Property("SubAccountRoleId") + .HasColumnType("bigint"); + + b1.HasKey("id"); + + b1.HasIndex("SubAccountRoleId"); + + b1.ToTable("SubAccountRolePermissions", (string)null); + + b1.WithOwner("SubAccountRole") + .HasForeignKey("SubAccountRoleId"); + + b1.Navigation("SubAccountRole"); + }); + + b.Navigation("RolePermissions"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskAgg.Tasks", b => + { + b.HasOne("AccountManagement.Domain.TaskScheduleAgg.TaskSchedule", "TaskSchedule") + .WithMany("TasksList") + .HasForeignKey("TaskScheduleId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("TaskSchedule"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskMediaAgg.TaskMedia", b => + { + b.HasOne("AccountManagement.Domain.MediaAgg.Media", "Media") + .WithMany("TaskMedias") + .HasForeignKey("MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AccountManagement.Domain.TaskAgg.Tasks", "Tasks") + .WithMany("TaskMedias") + .HasForeignKey("TaskId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Media"); + + b.Navigation("Tasks"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskMessageAgg.TaskMessage", b => + { + b.HasOne("AccountManagement.Domain.AssignAgg.Assign", "Assign") + .WithMany("TaskMessageList") + .HasForeignKey("AssignId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assign"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskMessageItemsAgg.TaskMessageItems", b => + { + b.HasOne("AccountManagement.Domain.TaskMessageAgg.TaskMessage", "TaskMessage") + .WithMany("TaskMessageItemsList") + .HasForeignKey("TaskMessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TaskMessage"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TicketMediasAgg.TicketMedia", b => + { + b.HasOne("AccountManagement.Domain.MediaAgg.Media", "Media") + .WithMany("TicketMedias") + .HasForeignKey("MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AccountManagement.Domain.TicketAgg.Ticket", "Ticket") + .WithMany("TicketMedias") + .HasForeignKey("TicketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Media"); + + b.Navigation("Ticket"); + }); + + modelBuilder.Entity("AccountManagement.Domain.AccountAgg.Account", b => + { + b.Navigation("AccountLeftWorkList"); + + b.Navigation("CameraAccounts"); + }); + + modelBuilder.Entity("AccountManagement.Domain.AdminResponseAgg.AdminResponse", b => + { + b.Navigation("AdminResponseMedias"); + }); + + modelBuilder.Entity("AccountManagement.Domain.AssignAgg.Assign", b => + { + b.Navigation("TaskMessageList"); + }); + + modelBuilder.Entity("AccountManagement.Domain.ClientResponseAgg.ClientResponse", b => + { + b.Navigation("ClientResponseMedias"); + }); + + modelBuilder.Entity("AccountManagement.Domain.MediaAgg.Media", b => + { + b.Navigation("AdminResponseMedias"); + + b.Navigation("ClientResponseMedias"); + + b.Navigation("TaskMedias"); + + b.Navigation("TicketMedias"); + }); + + modelBuilder.Entity("AccountManagement.Domain.PositionAgg.Position", b => + { + b.Navigation("Accounts"); + }); + + modelBuilder.Entity("AccountManagement.Domain.RoleAgg.Role", b => + { + b.Navigation("Accounts"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle1Agg.SubAccountPermissionSubtitle1", b => + { + b.Navigation("Children"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle2Agg.SubAccountPermissionSubtitle2", b => + { + b.Navigation("Children"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountPermissionSubtitle3Agg.SubAccountPermissionSubtitle3", b => + { + b.Navigation("Children"); + }); + + modelBuilder.Entity("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRole", b => + { + b.Navigation("SubAccounts"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskAgg.Tasks", b => + { + b.Navigation("Assigns"); + + b.Navigation("TaskMedias"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskMessageAgg.TaskMessage", b => + { + b.Navigation("TaskMessageItemsList"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TaskScheduleAgg.TaskSchedule", b => + { + b.Navigation("TasksList"); + }); + + modelBuilder.Entity("AccountManagement.Domain.TicketAgg.Ticket", b => + { + b.Navigation("AdminResponses"); + + b.Navigation("ClientResponses"); + + b.Navigation("TicketMedias"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.cs b/AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.cs new file mode 100644 index 00000000..f075e340 --- /dev/null +++ b/AccountMangement.Infrastructure.EFCore/Migrations/20250407150638_add TaskSchedule.cs @@ -0,0 +1,74 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AccountMangement.Infrastructure.EFCore.Migrations +{ + /// + public partial class addTaskSchedule : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "UnitType", + table: "TaskSchedules", + type: "nvarchar(10)", + maxLength: 10, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(10)", + oldMaxLength: 10, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Type", + table: "TaskSchedules", + type: "nvarchar(12)", + maxLength: 12, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(12)", + oldMaxLength: 12, + oldNullable: true); + + migrationBuilder.AddColumn( + name: "IsCanceled", + table: "TaskSchedules", + type: "nvarchar(5)", + maxLength: 5, + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IsCanceled", + table: "TaskSchedules"); + + migrationBuilder.AlterColumn( + name: "UnitType", + table: "TaskSchedules", + type: "nvarchar(10)", + maxLength: 10, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(10)", + oldMaxLength: 10); + + migrationBuilder.AlterColumn( + name: "Type", + table: "TaskSchedules", + type: "nvarchar(12)", + maxLength: 12, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(12)", + oldMaxLength: 12); + } + } +} diff --git a/AccountMangement.Infrastructure.EFCore/Migrations/AccountContextModelSnapshot.cs b/AccountMangement.Infrastructure.EFCore/Migrations/AccountContextModelSnapshot.cs index 61675f0e..3770c043 100644 --- a/AccountMangement.Infrastructure.EFCore/Migrations/AccountContextModelSnapshot.cs +++ b/AccountMangement.Infrastructure.EFCore/Migrations/AccountContextModelSnapshot.cs @@ -759,10 +759,16 @@ namespace AccountMangement.Infrastructure.EFCore.Migrations b.Property("CreationDate") .HasColumnType("datetime2"); + b.Property("IsCanceled") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("nvarchar(5)"); + b.Property("LastEndTaskDate") .HasColumnType("datetime2"); b.Property("Type") + .IsRequired() .HasMaxLength(12) .HasColumnType("nvarchar(12)"); @@ -771,6 +777,7 @@ namespace AccountMangement.Infrastructure.EFCore.Migrations .HasColumnType("nvarchar(10)"); b.Property("UnitType") + .IsRequired() .HasMaxLength(10) .HasColumnType("nvarchar(10)"); diff --git a/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs index f88ba7d1..47b3420d 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs @@ -4,6 +4,7 @@ using _0_Framework.InfraStructure; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using System.Linq; +using System.Threading.Tasks; using _0_Framework.Application; using AccountManagement.Application.Contracts.Account; using AccountManagement.Application.Contracts.Assign; @@ -46,7 +47,6 @@ public class TaskRepository : RepositoryBase, ITaskRepository public EditTask GetDetails(long TaskId) { - var task = Get(TaskId); var userId = _authHelper.CurrentAccountId(); @@ -94,7 +94,8 @@ public class TaskRepository : RepositoryBase, ITaskRepository Fullname = a.Fullname, Id = a.id, - }).FirstOrDefault() + }).FirstOrDefault(), + TaskScheduleId = x.TaskScheduleId ?? 0 }).FirstOrDefault(); @@ -112,6 +113,17 @@ public class TaskRepository : RepositoryBase, ITaskRepository res.IsCancel = res.AssignViewModels.First(x => x.AssignedId == userId).IsCancel; } + if (res.TaskScheduleId>0) + { + var taskSchedule = _accountContext.TaskSchedules.FirstOrDefault(x => x.id == res.TaskScheduleId); + + res.ScheduleUnitType = taskSchedule.UnitType; + res.ScheduleType = taskSchedule.Type; + res.ScheduleCount = taskSchedule.Count; + res.ScheduleUnitNumber = taskSchedule.UnitNumber; + } + + //_accountContext.Tasks.Where(x => x.id == TaskId).Select(x => new EditTask() //{ // EndTaskDate = x.EndTaskDate.ToFarsi(), @@ -968,7 +980,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository .ThenInclude(x => x.Media) .Where(x => x.Task.IsActiveString == "true" && (x.AssignerId == accountId && x.AssignedId != accountId) && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest) && x.Task.TicketId == null && - x.Task.SenderId == accountId) + x.Task.SenderId == accountId && x.Task.TaskScheduleId == null) .Select(x => new TaskViewModel() { @@ -1839,7 +1851,307 @@ public class TaskRepository : RepositoryBase, ITaskRepository return final; } + public List GetTaskScheduleList(TaskSearchModel searchModel) + { + var accountId = long.Parse(_contextAccessor.HttpContext.User.FindFirst("AccountId").Value); + var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); + var emptyAcc = new AccountViewModel() + { + Fullname = "-", + PositionValue = 0 + }; + var raw = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) + .ThenInclude(x => x.Media) + .Include(x => x.Task).ThenInclude(x => x.TaskSchedule) + .Where(x => + x.Task.IsActiveString == "true" && x.Task.SenderId == accountId + && x.Task.TaskScheduleId != null && x.Task.TaskScheduleId > 0 && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)); + if (!string.IsNullOrWhiteSpace(searchModel.GeneralSearch)) + { + raw = raw.Where(x => + (x.Task.Description != null && x.Task.Description.Contains(searchModel.GeneralSearch)) + || x.Task.ContractingPartyName.Contains(searchModel.GeneralSearch) + || x.Task.Title.Contains(searchModel.GeneralSearch)); + } + + + + + var query = raw.GroupBy(x => x.Task.TaskScheduleId).Select(x => + new TaskViewModel() + { + AssignedId = x.First().AssignedId, + AssignerId = x.First().AssignerId, + CreateDate = x.First().Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.First().EndTaskDate.ToFarsi(), + IsDone = x.First().IsDone, + EndTaskDateGE = x.First().EndTaskDate, + Name = x.First().Task.Title, + RequestCancel = x.First().IsCanceledRequest, + RequestTime = x.First().TimeRequest, + Id = x.First().Task.id, + CreateTaskDateGE = x.First().Task.CreationDate, + IsCancel = x.First().IsCancel, + AcceptedTimeRequest = x.First().AcceptedTimeRequest, + IsCancelRequest = x.First().IsCanceledRequest, + ContractingPartyName = x.First().Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.First().Task.id), + Description = x.First().Task.Description, + IsDoneRequest = x.First().IsDoneRequest, + ScheduleType = x.First().Task.TaskSchedule.Type, + ScheduleUnitType = x.First().Task.TaskSchedule.UnitType, + TaskScheduleId = (long)x.First().Task.TaskScheduleId + + } + ); + + if (!string.IsNullOrWhiteSpace(searchModel.GeneralSearch)) + { + query = query.Where(x => + (x.Description != null && x.Description.Contains(searchModel.GeneralSearch)) + || x.ContractingPartyName.Contains(searchModel.GeneralSearch) + || x.Name.Contains(searchModel.GeneralSearch)); + } + + var res = query.Select(x => new TaskViewModel() + { + Sender = _accountContext.Accounts.Include(a => a.Position).Select(a => new AccountViewModel() + { + PositionValue = a.Position.PositionValue, + Id = a.id, + Fullname = a.Fullname, + }).FirstOrDefault(a => a.Id == x.AssignerId), + + SelfName = _accountContext.Accounts.FirstOrDefault(a => a.id == accountId).Fullname, + + Assigned = _accountContext.Assigns.Where(a => a.TaskId == x.Id) + .Where(a => a.AssignedPositionValue >= positionValue).Select(a => a.AssignedId) + .ToList(), + CreateDate = x.CreateDate, + EndTaskDateFA = x.EndTaskDateFA, + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDateGE, + Name = x.Name, + RequestCancel = x.RequestCancel, + RequestTime = x.RequestTime, + Id = x.Id, + CreateTaskDateGE = x.CreateTaskDateGE, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCancelRequest, + ContractingPartyName = x.ContractingPartyName, + MediaCount = x.MediaCount, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest, + ScheduleType = x.ScheduleType, + ScheduleUnitType = x.ScheduleUnitType, + TaskScheduleId = x.TaskScheduleId + }); + if (!string.IsNullOrWhiteSpace(searchModel.StartDate) && !string.IsNullOrWhiteSpace(searchModel.EndDate)) + { + var start = searchModel.StartDate.ToGeorgianDateTime(); + var end = searchModel.EndDate.ToGeorgianDateTime(); + res = res.Where(x => + ((start > x.CreateTaskDateGE && x.CreateTaskDateGE < end) && + + (end > x.EndTaskDateGE && x.EndTaskDateGE > start)) + || ((start < x.CreateTaskDateGE && x.CreateTaskDateGE < end) && + + (end < x.EndTaskDateGE && x.EndTaskDateGE > start)) + || ((start < x.CreateTaskDateGE && x.CreateTaskDateGE < end) && + + (end > x.EndTaskDateGE && x.EndTaskDateGE > start)) + || ((start > x.CreateTaskDateGE && x.CreateTaskDateGE < end) && + + (end < x.EndTaskDateGE && x.EndTaskDateGE > end))); + } + + if (!string.IsNullOrWhiteSpace(searchModel.IsDoneRequest)) + { + bool isDoneReq = bool.Parse(searchModel.IsDoneRequest); + res = res.Where(x => x.IsDoneRequest == isDoneReq); + } + + if (!string.IsNullOrWhiteSpace(searchModel.IsDone)) + { + bool isDone = bool.Parse(searchModel.IsDone); + res = res.Where(x => x.IsDone == isDone); + } + + if (!string.IsNullOrWhiteSpace(searchModel.IsCanceled)) + { + bool isCancel = bool.Parse(searchModel.IsCanceled); + res = res.Where(x => x.IsCancel == isCancel); + } + + if (!string.IsNullOrWhiteSpace(searchModel.IsTimeRequest)) + { + bool isTimeRequest = bool.Parse(searchModel.IsTimeRequest); + res = res.Where(x => x.RequestTime == isTimeRequest); + } + + if (!string.IsNullOrWhiteSpace(searchModel.TimeRequestAccepted)) + { + res = res.Where(x => x.AcceptedTimeRequest > 0); + } + + if (!string.IsNullOrWhiteSpace(searchModel.IsCancelRequest)) + { + bool isCancelReq = bool.Parse(searchModel.IsCancelRequest); + res = res.Where(x => x.IsCancelRequest == isCancelReq); + + } + + + + var result = res.AsEnumerable(); + + + if (searchModel.AccountId > 0) + { + result = result.Where(x => + x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); + } + + + var orderResult = result.OrderByDescending(x => x.IsCancel ? 0 : 1).ThenBy(x => x.IsDone ? 1 : 0) + .ThenBy(x => x.EndTaskDateGE); + + + var final = orderResult.Skip(searchModel.PageIndex).Take(30).ToList(); + + final = final.Select(x => new TaskViewModel() + { + AssignViewModels = _accountContext.Accounts.Include(x => x.Position) + .Where(a => x.Assigned.Contains(a.id) && accountId != a.id) + .Select(a => new AssignViewModel() + { + AssignedName = a.Fullname, + AssignedPositionValue = a.Position.PositionValue + }).ToList(), + Sender = x.Sender, + SelfAssigner = x.Sender.Id == accountId ? true : false, + Assigned = x.Assigned, + SelfAssigned = x.Assigned.Any(a => a == accountId) ? true : false, + CreateDate = x.CreateDate, + EndTaskDateFA = x.EndTaskDateFA, + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDateGE, + Name = x.Name, + RequestCancel = x.RequestCancel, + RequestTime = x.RequestTime, + Id = x.Id, + CreateTaskDateGE = x.CreateTaskDateGE, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCancelRequest, + ContractingPartyName = x.ContractingPartyName, + MediaCount = x.MediaCount, + SelfName = x.SelfName, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest, + ScheduleType = x.ScheduleType, + ScheduleUnitType = x.ScheduleUnitType, + TaskScheduleId = x.TaskScheduleId + + + }).ToList(); + + + final = final.Select(x => new TaskViewModel() + { + + AssignList = x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() + { + AssignViewModels = a.ToList(), + PosValue = a.Key + }).ToList(), + Sender = x.Sender, + Assigned = x.Assigned, + CreateDate = x.CreateDate, + EndTaskDateFA = x.EndTaskDateFA, + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDateGE, + Name = x.Name, + RequestCancel = x.RequestCancel, + RequestTime = x.RequestTime, + Id = x.Id, + CreateTaskDateGE = x.CreateTaskDateGE, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCancelRequest, + ContractingPartyName = x.ContractingPartyName, + Color = x.IsDone ? "green" : SetTasksColors(x.EndTaskDateGE, x.IsCancel), + MediaCount = x.MediaCount, + HasAttachment = x.MediaCount > 0, + SelfName = x.SelfName, + SelfAssigned = x.SelfAssigned, + SelfAssigner = x.SelfAssigner, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest, + AssignViewModels = x.AssignViewModels, + ScheduleType = x.ScheduleType, + ScheduleUnitType = x.ScheduleUnitType, + TaskScheduleId = x.TaskScheduleId + + }).ToList(); + + final = final.Select(x => new TaskViewModel() + { + + AssignList = !(x.SelfAssigned || x.SelfAssigner) + ? AddAssign(x.AssignList, x.Sender) + : x.AssignList, + Sender = !(x.SelfAssigned || x.SelfAssigner) + ? new AccountViewModel() + { + PositionValue = 0, + Fullname = "-" + } + : x.Sender, + Assigned = x.Assigned, + CreateDate = x.CreateDate, + EndTaskDateFA = x.EndTaskDateFA, + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDateGE, + Name = x.Name, + RequestCancel = x.RequestCancel, + RequestTime = x.RequestTime, + Id = x.Id, + CreateTaskDateGE = x.CreateTaskDateGE, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCancelRequest, + ContractingPartyName = x.ContractingPartyName, + Color = x.Color, + MediaCount = x.MediaCount, + HasAttachment = x.HasAttachment, + SelfName = !(x.SelfAssigned || x.SelfAssigner) ? "-" : x.SelfName, + EndTaskTime = $"{x.EndTaskDateGE.Hour}:{x.EndTaskDateGE.Minute}:{x.EndTaskDateGE.Second}" != "23:59:59" + ? $"{x.EndTaskDateGE.Hour}:{x.EndTaskDateGE.Minute}" + : "", + Description = x.Description, + IsDoneRequest = x.IsDoneRequest, + CanAssign = _positionRepository.GetLastPositionValue() != positionValue, + CanDelete = x.Sender.Id == accountId, + CanEdit = x.Sender.Id == accountId && !(_accountContext.Assigns.Any(a => a.TaskId == x.Id && (a.AcceptedTimeRequest > 0 || a.IsCanceledRequest + || a.IsDoneRequest || a.TimeRequest || a.IsCancel || a.IsDone))), + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname, + AssignedReceiverViewModel = x.AssignViewModels.Any() + ? x.AssignViewModels.MinBy(a => a.AssignedPositionValue) + : new() + { + AssignedName = "-", + AssignedPositionValue = 0 + }, + ScheduleType = x.ScheduleType, + ScheduleUnitType = x.ScheduleUnitType, + TaskScheduleId = x.TaskScheduleId + + }).ToList(); + return final; + } public string SetTasksColors(DateTime date, bool isCancel) { @@ -1888,23 +2200,23 @@ public class TaskRepository : RepositoryBase, ITaskRepository } - public int GetRequestedTasksCount() + public async Task GetRequestedTasksCount() { var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); var accountId = long.Parse(_contextAccessor.HttpContext.User.FindFirst("AccountId").Value); if (positionValue == 1) { - return _accountContext.Assigns.Include(x => x.Task).Where(x => + return await _accountContext.Assigns.Include(x => x.Task).Where(x => !x.IsDone && x.Task.IsActiveString == "true" && !x.IsCancel && (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest) && (accountId == x.Task.SenderId) && x.Task.TicketId == null).GroupBy(x => x.TaskId) - .Select(x => x.First()).Count(); + .Select(x => x.First()).CountAsync(); } else { - return _accountContext.Assigns.Include(x => x.Task).Where(x => + return await _accountContext.Assigns.Include(x => x.Task).Where(x => !x.IsDone && x.Task.IsActiveString == "true" && !x.IsCancel && (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest) && (accountId == x.Task.SenderId) && x.Task.TicketId == null).GroupBy(x => x.TaskId) - .Select(x => x.First()).Count(); + .Select(x => x.First()).CountAsync(); } } @@ -2001,7 +2313,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository } - public int RequestedAndOverdueTasksCount(long userId) + public async Task RequestedAndOverdueTasksCount(long userId) { var account = _accountRepository.GetIncludePositions(userId); if (account.Position == null) @@ -2009,7 +2321,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository DateTime now = DateTime.Now; - var overdueTasksCount = OverdueTasksCount(userId); + var overdueTasksCount = await OverdueTasksCount(userId); //overdueTasksCount = _accountContext.Tasks.Include(x => @@ -2018,10 +2330,10 @@ public class TaskRepository : RepositoryBase, ITaskRepository // !x.Assigns.Any(a => a.TimeRequest) // && x.Assigns.Any(a => a.AssignedId == userId) && // (x.Assigns.First(a => a.AssignedId == userId).EndTaskDate.Date <= DateTime.Now.Date)); - var overdueRequestsCount = GetRequestedTasksCount(); + var overdueRequestsCount = await GetRequestedTasksCount(); - var ticketRequested = TasksHaveTicketRequestsCount(userId); - var overdueTicket = TasksHaveTicketCounts(userId); + var ticketRequested = await TasksHaveTicketRequestsCount(userId); + var overdueTicket = await TasksHaveTicketCounts(userId); return overdueTasksCount + overdueRequestsCount + ticketRequested + overdueTicket; } @@ -2036,7 +2348,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository return overdueRequestsCount; } - public int OverdueTasksCount(long userId) + public async Task OverdueTasksCount(long userId) { var account = _accountRepository.GetIncludePositions(userId); @@ -2048,12 +2360,12 @@ public class TaskRepository : RepositoryBase, ITaskRepository int overdueTasksCount; if (positionValue == 1) { - overdueTasksCount = _accountContext.Assigns.Include(x => x.Task).Where(x => x.AssignedId == userId && + overdueTasksCount = await _accountContext.Assigns.Include(x => x.Task).Where(x => x.AssignedId == userId && x.AssignerId == userId && x.Task.Assigns.Count == 1 && !x.IsCancel && !x.IsCanceledRequest && !x.IsDone && !x.TimeRequest && !x.IsDoneRequest && x.EndTaskDate.Date <= DateTime.Now.Date && x.Task.IsActiveString == "true" && x.Task.TicketId == null) - .GroupBy(x => x.TaskId).Select(x => x.First()).Count(); + .GroupBy(x => x.TaskId).Select(x => x.First()).CountAsync(); //overdueTasksCount = _accountContext.Tasks.Include(x => // x.Assigns).Count(x => !x.Assigns.Any(a => a.IsCancel) && !x.Assigns.Any(a => a.IsCanceledRequest) && @@ -2065,43 +2377,49 @@ public class TaskRepository : RepositoryBase, ITaskRepository } else { - overdueTasksCount = _accountContext.Assigns.Include(x => x.Task).Where(x => x.AssignedId == userId && + overdueTasksCount = await _accountContext.Assigns.Include(x => x.Task).Where(x => x.AssignedId == userId && !x.IsCancel && !x.IsCanceledRequest && !x.IsDone && !x.TimeRequest && !x.IsDoneRequest && x.EndTaskDate.Date <= DateTime.Now.Date && x.Task.IsActiveString == "true" && x.Task.TicketId == null) - .GroupBy(x => x.TaskId).Select(x => x.First()).Count(); + .GroupBy(x => x.TaskId).Select(x => x.First()).CountAsync(); ; } return overdueTasksCount; } - public int TasksHaveTicketCounts(long userId) + public List GetTasksByTaskScheduleId(long taskScheduleId) { - return _accountContext.Assigns.Include(x => x.Task).Where(x => + return _accountContext.Tasks.Include(x=>x.Assigns).Where(x => x.TaskScheduleId != null && x.TaskScheduleId == taskScheduleId).ToList(); + } + + + public async Task TasksHaveTicketCounts(long userId) + { + return await _accountContext.Assigns.Include(x => x.Task).Where(x => !x.IsDone && x.Task.IsActiveString == "true" && !x.IsCancel && !x.IsCanceledRequest && !x.IsDoneRequest && !x.TimeRequest && (x.AssignerId == userId || x.AssignedId == userId) && - (x.Task.TicketId != null && x.Task.TicketId > 0)).GroupBy(x => x.TaskId).Count(); + (x.Task.TicketId != null && x.Task.TicketId > 0)).GroupBy(x => x.TaskId).CountAsync(); } - public int TasksHaveTicketRequestsCount(long userId) + public async Task TasksHaveTicketRequestsCount(long userId) { var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); var accountId = long.Parse(_contextAccessor.HttpContext.User.FindFirst("AccountId").Value); if (positionValue == 1) { - return _accountContext.Assigns.Include(x => x.Task).Where(x => + return await _accountContext.Assigns.Include(x => x.Task).Where(x => !x.IsDone && x.Task.IsActiveString == "true" && !x.IsCancel && (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest) && (accountId == x.Task.SenderId) && x.Task.TicketId != null && x.Task.TicketId > 0).GroupBy(x => x.TaskId) - .Select(x => x.First()).Count(); + .Select(x => x.First()).CountAsync(); } else { - return _accountContext.Assigns.Include(x => x.Task).Where(x => + return await _accountContext.Assigns.Include(x => x.Task).Where(x => !x.IsDone && x.Task.IsActiveString == "true" && !x.IsCancel && (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest) && (accountId == x.Task.SenderId) && x.Task.TicketId != null && x.Task.TicketId > 0).GroupBy(x => x.TaskId) - .Select(x => x.First()).Count(); + .Select(x => x.First()).CountAsync(); } } diff --git a/AccountMangement.Infrastructure.EFCore/Repository/TaskScheduleRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/TaskScheduleRepository.cs new file mode 100644 index 00000000..7228b20b --- /dev/null +++ b/AccountMangement.Infrastructure.EFCore/Repository/TaskScheduleRepository.cs @@ -0,0 +1,66 @@ +using System.Linq; +using System.Threading.Tasks; +using _0_Framework.Application; +using _0_Framework.InfraStructure; +using AccountManagement.Application.Contracts.Media; +using AccountManagement.Application.Contracts.TaskSchedule; +using AccountManagement.Domain.TaskScheduleAgg; +using Microsoft.EntityFrameworkCore; + +namespace AccountMangement.Infrastructure.EFCore.Repository; + +public class TaskScheduleRepository: RepositoryBase, ITaskScheduleRepository +{ + private readonly AccountContext _accountContext; + + public TaskScheduleRepository(AccountContext accountContext):base(accountContext) + { + _accountContext = accountContext; + } + + public async Task GetDetails(long id) + { + var taskSchedule=await _accountContext.TaskSchedules.Include(x=>x.TasksList).ThenInclude(x=>x.Assigns) + .Include(x=>x.TasksList).ThenInclude(x=>x.TaskMedias).ThenInclude(x=>x.Media).FirstOrDefaultAsync(x => x.id == id); + if (taskSchedule == null) + { + return null; + } + + var firstTaskDetails = taskSchedule.TasksList.First(); + + var firstTimeAssigns = firstTaskDetails.Assigns.Where(x=>x.FirstTimeCreation).ToList(); + + var assignedIds = firstTimeAssigns.Select(x => x.AssignedId).ToList(); + + var senderId = firstTaskDetails.SenderId; + + + var assignedAccounts = await _accountContext.Accounts.Where(x => assignedIds.Contains(x.id)).ToListAsync(); + + var sender = + await _accountContext.Accounts.FirstOrDefaultAsync(x => senderId == x.id); + + var viewModel = new TaskScheduleDetailsViewModel() + { + Title = firstTaskDetails.Title, + Description = firstTaskDetails.Description, + ContractingPartyName = firstTaskDetails.ContractingPartyName, + AssignedName = assignedAccounts.Select(x=>x.Fullname).ToList(), + CreationDateFa = firstTaskDetails.CreationDate.ToFarsi(), + SenderName = sender.Fullname, + TaskScheduleType = taskSchedule.Type, + TaskScheduleUnitType = taskSchedule.UnitType, + UnitNumber = taskSchedule.UnitNumber, + Medias = firstTaskDetails.TaskMedias.Select(x=> new MediaViewModel() + { + Category = x.Media.Category, + Id = x.MediaId, + Type = x.Media.Type, + Path = x.Media.Path, + }).ToList(), + }; + return viewModel; + + } +} \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Pages/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Index.cshtml.cs index 9207552b..ca781bdc 100644 --- a/ServiceHost/Areas/Admin/Pages/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Index.cshtml.cs @@ -59,7 +59,7 @@ namespace ServiceHost.Areas.Admin.Pages _ticketApplication = ticketApplication; } - public void OnGet() + public async Task OnGet() { long userId = _authHelper.CurrentAccountId(); var todayGr = DateTime.Now; @@ -75,7 +75,7 @@ namespace ServiceHost.Areas.Admin.Pages day = todayFa.Substring(8, 2); year = todayFa.Substring(0, 4); - TaskCount = _taskApplication.RequestedAndOverdueTasksCount(userId); + TaskCount = await _taskApplication.RequestedAndOverdueTasksCount(userId); TicketCount = _ticketApplication.GetAdminTicketsCount(); //foreach (string fileEntry in fileEntries) diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs index bc764189..da7c1117 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.CodeAnalysis.CSharp.Syntax; using System.Collections.Generic; using System.Globalization; +using AccountManagement.Application.Contracts.TaskSchedule; using Microsoft.AspNetCore.Authorization; using Company.Domain.HolidayAgg; using CompanyManagment.App.Contracts.Employer; @@ -32,9 +33,9 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.Task private readonly IHolidayItemApplication _holidayItemApplication; private readonly IEmployerApplication _employerApplication; private readonly IWorkshopApplication _workshopApplication; + private readonly ITaskScheduleApplication _taskScheduleApplication; - - public CreateModel(ITaskApplication taskApplication, IAccountApplication accountApplication, IPersonalContractingPartyApp personalContractingPartyApp, IAuthHelper authHelper, IPersonalContractingPartyApp contractingPartyApp, IPositionApplication positionApplication, ITaskSubjectApplication taskSubjectApplication, IWebHostEnvironment webHostEnvironment, IHolidayApplication holidayApplication, IHolidayItemApplication holidayItemApplication, IEmployerApplication employerApplication, IWorkshopApplication workshopApplication) + public CreateModel(ITaskApplication taskApplication, IAccountApplication accountApplication, IPersonalContractingPartyApp personalContractingPartyApp, IAuthHelper authHelper, IPersonalContractingPartyApp contractingPartyApp, IPositionApplication positionApplication, ITaskSubjectApplication taskSubjectApplication, IWebHostEnvironment webHostEnvironment, IHolidayApplication holidayApplication, IHolidayItemApplication holidayItemApplication, IEmployerApplication employerApplication, IWorkshopApplication workshopApplication, ITaskScheduleApplication taskScheduleApplication) { _taskApplication = taskApplication; _accountApplication = accountApplication; @@ -45,6 +46,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.Task _holidayItemApplication = holidayItemApplication; _employerApplication = employerApplication; _workshopApplication = workshopApplication; + _taskScheduleApplication = taskScheduleApplication; } public CreateTask Command { get; set; } @@ -87,6 +89,16 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.Task { Command.SenderId = _authHelper.CurrentAccountId(); Command.Description = Command.Description?.Replace("\n", "
"); + + if (Command.HasSchedule) + { + var scheduleResult = _taskScheduleApplication.Create(Command); + return new JsonResult(new + { + IsSuccedded = scheduleResult.IsSuccedded, + message = scheduleResult.Message, + }); + } var result = _taskApplication.CreateTask(Command); return new JsonResult(new { diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateScheduleModal.cshtml b/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateScheduleModal.cshtml new file mode 100644 index 00000000..cb89c12e --- /dev/null +++ b/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateScheduleModal.cshtml @@ -0,0 +1,445 @@ +@model AccountManagement.Application.Contracts.Task.CreateTaskModal +@* @model ServiceHost.Areas.AdminNew.Pages.Company.Task.CreateModel *@ +@inject _0_Framework.Application.IAuthHelper AuthHelper; + +@{ + string adminVersion = _0_Framework.Application.Version.AdminVersion; + ViewData["title"] = " - وظیفه جدید"; +} + + + + + + + + + + +@*