diff --git a/0_Framework/Application/Version.cs b/0_Framework/Application/Version.cs index 0984e674..2f572a36 100644 --- a/0_Framework/Application/Version.cs +++ b/0_Framework/Application/Version.cs @@ -10,8 +10,8 @@ public static class Version { static Version() { - StyleVersion = "2.12.00"; - AdminVersion = "2.5.20"; + StyleVersion = "2.12.01"; + AdminVersion = "2.5.21"; CameraVersion = "1.0.3"; } diff --git a/AccountManagement.Application.Contracts/Task/ITaskApplication.cs b/AccountManagement.Application.Contracts/Task/ITaskApplication.cs index 9318f10e..919ce287 100644 --- a/AccountManagement.Application.Contracts/Task/ITaskApplication.cs +++ b/AccountManagement.Application.Contracts/Task/ITaskApplication.cs @@ -23,6 +23,7 @@ public interface ITaskApplication //List GetAllNotSelfIncludedTasks(TaskSearchModel searchModel); List GetReceivedTasks(TaskSearchModel searchModel); List GetSentTasks(TaskSearchModel searchModel); + List GetTasksHaveTicket(TaskSearchModel searchModel); // گرفتن مهلت برای یک وظیفه OperationResult CreateRequestTime(CreateTaskTimeRequest command); diff --git a/AccountManagement.Application/TaskApplication.cs b/AccountManagement.Application/TaskApplication.cs index c264deac..701716c5 100644 --- a/AccountManagement.Application/TaskApplication.cs +++ b/AccountManagement.Application/TaskApplication.cs @@ -1,6 +1,7 @@ using _0_Framework.Application; using System; using System.Collections.Generic; +using System.Data.OleDb; using System.IO; using System.Linq; using AccountManagement.Application.Contracts.Assign; @@ -9,7 +10,10 @@ using AccountManagement.Domain.AccountAgg; using AccountManagement.Domain.AssignAgg; using AccountManagement.Domain.MediaAgg; using AccountManagement.Domain.TaskAgg; +using IPE.SmsIrClient.Models.Results; using TaskManager.Domain.PositionAgg; +using System.Reflection; + using Microsoft.AspNetCore.Http; using System.Globalization; using AccountManagement.Application.Contracts.TaskMessage; @@ -506,6 +510,11 @@ public class TaskApplication : ITaskApplication return _taskRepository.GetSentTasks(searchModel); } + public List GetTasksHaveTicket(TaskSearchModel searchModel) + { + return _taskRepository.GetTasksHaveTicket(searchModel); + } + //ساخت درخواست مهلت public OperationResult CreateRequestTime(CreateTaskTimeRequest command) { diff --git a/AccountManagement.Application/TicketApplication.cs b/AccountManagement.Application/TicketApplication.cs index a17f3040..e0c5ecbe 100644 --- a/AccountManagement.Application/TicketApplication.cs +++ b/AccountManagement.Application/TicketApplication.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Sockets; +using System.Reflection; using _0_Framework.Application; using AccountManagement.Application.Contracts.Task; using AccountManagement.Application.Contracts.Ticket; @@ -12,7 +14,11 @@ using AccountManagement.Domain.AssignAgg; using AccountManagement.Domain.ClientResponseAgg; using AccountManagement.Domain.MediaAgg; using AccountManagement.Domain.TaskAgg; +using AccountManagement.Domain.TicketAccessAccountAgg; using AccountManagement.Domain.TicketAgg; +using CompanyManagment.App.Contracts.Workshop; +using IPE.SmsIrClient.Models.Results; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; namespace AccountManagement.Application; diff --git a/AccountManagement.Domain/TaskAgg/ITaskRepository.cs b/AccountManagement.Domain/TaskAgg/ITaskRepository.cs index 24040064..7d56c48d 100644 --- a/AccountManagement.Domain/TaskAgg/ITaskRepository.cs +++ b/AccountManagement.Domain/TaskAgg/ITaskRepository.cs @@ -21,6 +21,7 @@ public interface ITaskRepository:IRepository List GetReceivedTasks(TaskSearchModel searchModel); List GetSentTasks(TaskSearchModel searchModel); List AllRequestedTasks(TaskSearchModel searchModel); + List GetTasksHaveTicket(TaskSearchModel searchModel); string SetTasksColors(DateTime time,bool isCancel); int GetRequestedTasksCount(); EditTask GetRequestDetails(long id); diff --git a/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs index 92b8e6c7..f7c3bdd6 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs @@ -23,73 +23,73 @@ using AccountManagement.Application.Contracts.Ticket; namespace AccountMangement.Infrastructure.EFCore.Repository; public class - TaskRepository : RepositoryBase, ITaskRepository + TaskRepository : RepositoryBase, ITaskRepository { - private readonly AccountContext _accountContext; - private readonly IHttpContextAccessor _contextAccessor; - private readonly IAccountRepository _accountRepository; - private readonly IPositionRepository _positionRepository; - private readonly IWebHostEnvironment _webHostEnvironment; - private readonly IAuthHelper _authHelper; - private readonly ITicketRepository _ticketRepository; + private readonly AccountContext _accountContext; + private readonly IHttpContextAccessor _contextAccessor; + private readonly IAccountRepository _accountRepository; + private readonly IPositionRepository _positionRepository; + private readonly IWebHostEnvironment _webHostEnvironment; + private readonly IAuthHelper _authHelper; + private readonly ITicketRepository _ticketRepository; - public TaskRepository(IHttpContextAccessor contextAccessor, AccountContext accountContext, - IAccountRepository accountRepository, IPositionRepository positionRepository, - IWebHostEnvironment webHostEnvironment, IAuthHelper authHelper, ITicketRepository ticketRepository) : base(accountContext) - { - _contextAccessor = contextAccessor; - _accountContext = accountContext; - _accountRepository = accountRepository; - _positionRepository = positionRepository; - _webHostEnvironment = webHostEnvironment; - _authHelper = authHelper; - _ticketRepository = ticketRepository; - } + public TaskRepository(IHttpContextAccessor contextAccessor, AccountContext accountContext, + IAccountRepository accountRepository, IPositionRepository positionRepository, + IWebHostEnvironment webHostEnvironment, IAuthHelper authHelper, ITicketRepository ticketRepository) : base(accountContext) + { + _contextAccessor = contextAccessor; + _accountContext = accountContext; + _accountRepository = accountRepository; + _positionRepository = positionRepository; + _webHostEnvironment = webHostEnvironment; + _authHelper = authHelper; + _ticketRepository = ticketRepository; + } - public EditTask GetDetails(long TaskId) - { - var task = Get(TaskId); + public EditTask GetDetails(long TaskId) + { + var task = Get(TaskId); - var userId = _authHelper.CurrentAccountId(); + var userId = _authHelper.CurrentAccountId(); - EditTask res = _accountContext.Tasks.Include(x => x.Assigns).Where(x => x.id == TaskId).Select(x => - new EditTask() - { + EditTask res = _accountContext.Tasks.Include(x => x.Assigns).Where(x => x.id == TaskId).Select(x => + new EditTask() + { - Description = x.Description, - Id = x.id, - Title = x.Title, - medias = _accountContext.TaskMedias.Include(z => z.Media).Where(e => e.TaskId == x.id).Select(m => - new MediaViewModel() - { - Path = m.Media.Path, - Type = m.Media.Type, - Category = m.Media.Category, - Id = m.Media.id - }).ToList(), - ContractingPartyName = x.ContractingPartyName, - ReceiverId = _accountContext.Assigns.Where(a => a.TaskId == x.id).Select(a => a.AssignedId).ToList(), - SenderId = x.SenderId, - AssignViewModels = x.Assigns.Select(a => new AssignViewModel() - { - Id = a.id, - EndTaskDateFa = a.EndTaskDate.ToFarsiFull(), - IsCancel = a.IsCancel, - IsCanceledRequest = a.IsCanceledRequest, - IsDone = a.IsDone, - IsDoneRequest = a.IsDoneRequest, - TimeRequest = a.TimeRequest, - AssignedName = a.AssignedName, - AssignedId = a.AssignedId, - AssignerId = a.AssignerId + Description = x.Description, + Id = x.id, + Title = x.Title, + medias = _accountContext.TaskMedias.Include(z => z.Media).Where(e => e.TaskId == x.id).Select(m => + new MediaViewModel() + { + Path = m.Media.Path, + Type = m.Media.Type, + Category = m.Media.Category, + Id = m.Media.id + }).ToList(), + ContractingPartyName = x.ContractingPartyName, + ReceiverId = _accountContext.Assigns.Where(a => a.TaskId == x.id).Select(a => a.AssignedId).ToList(), + SenderId = x.SenderId, + AssignViewModels = x.Assigns.Select(a => new AssignViewModel() + { + Id = a.id, + EndTaskDateFa = a.EndTaskDate.ToFarsiFull(), + IsCancel = a.IsCancel, + IsCanceledRequest = a.IsCanceledRequest, + IsDone = a.IsDone, + IsDoneRequest = a.IsDoneRequest, + TimeRequest = a.TimeRequest, + AssignedName = a.AssignedName, + AssignedId = a.AssignedId, + AssignerId = a.AssignerId - }).ToList(), - IsDone = x.Assigns.All(a=>a.IsDone), - IsCancel = x.Assigns.All(a=>a.IsCancel), - TicketId = x.TicketId, - CreateDateFa = x.CreationDate.ToFarsi(), - + }).ToList(), + IsDone = x.Assigns.All(a => a.IsDone), + IsCancel = x.Assigns.All(a => a.IsCancel), + TicketId = x.TicketId, + CreateDateFa = x.CreationDate.ToFarsi(), + SenderViewModel = _accountContext.Accounts.Where(a => a.id == x.SenderId).Select(a => new AccountViewModel() { @@ -100,694 +100,694 @@ public class }).FirstOrDefault(); - res.TicketViewModel = res.TicketId != null && res.TicketId > 0 - ? _ticketRepository.GetDetails(res.TicketId.Value) - : null; - if (res.AssignViewModels.Any(x=>x.AssignedId==userId)) - { - res.EndTaskDate = _accountContext.Assigns.First(a => a.TaskId == res.Id && a.AssignedId == userId) - .EndTaskDate.ToFarsi(); + res.TicketViewModel = res.TicketId != null && res.TicketId > 0 + ? _ticketRepository.GetDetails(res.TicketId.Value) + : null; + if (res.AssignViewModels.Any(x => x.AssignedId == userId)) + { + res.EndTaskDate = _accountContext.Assigns.First(a => a.TaskId == res.Id && a.AssignedId == userId) + .EndTaskDate.ToFarsi(); - - res.AssignViewModels = res.AssignViewModels.Where(x => x.AssignedId == userId).ToList(); - res.IsDone = res.AssignViewModels.First(x=>x.AssignedId==userId).IsDone; + + res.AssignViewModels = res.AssignViewModels.Where(x => x.AssignedId == userId).ToList(); + res.IsDone = res.AssignViewModels.First(x => x.AssignedId == userId).IsDone; res.IsCancel = res.AssignViewModels.First(x => x.AssignedId == userId).IsCancel; } - - //_accountContext.Tasks.Where(x => x.id == TaskId).Select(x => new EditTask() - //{ - // EndTaskDate = x.EndTaskDate.ToFarsi(), - // Description = x.Description, - // Id = x.id, - // Title = x.Title, - // medias = _accountContext.TaskMedias.Include(z => z.Media).Where(e => e.TaskId == x.id).Select(m => - // new MediaViewModel() - // { - // Path = m.Media.Path, - // Type = m.Media.Type, - // Category = m.Media.Category, - // Id = m.Media.id - // }).ToList(), - // EndTaskTime = x.EndTaskDate.ToFarsiFull().Substring(11), - // ContractingPartyName = x.ContractingPartyName, - // CompleteDescription = x.DoneDescription, - // IsDone = x.IsDone, - // ReceiverId = _accountContext.Assigns.Where(a => a.TaskId == x.id).Select(a => a.AssignedId).ToList(), - // SenderId = x.SenderId - - //}).FirstOrDefault(); - return res; - } - - public Tasks GetIncludeAssign(long taskId) - { - return _accountContext.Tasks.Include(x => x.Assigns).FirstOrDefault(x => x.id == taskId); - } - - public void Remove(long id) - { - var task = Get(id); - Remove(task); - } - - - - public List GetRequestedTasks(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 - }; - IQueryable query; - - - query = _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).Select(x => - new TaskViewModel() - { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = x.Task.TaskMedias.Count(m => m.TaskId == x.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest - - }); - - //res = res.GroupBy(x => x.Id).Select(x => x.First()); - //res = res.OrderBy(x => x.IsDone ? 1 : 0) - // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); - 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 - }); - 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 resEnum = res.AsEnumerable(); - var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); - - if (searchModel.AccountId > 0) - { - result = result.Where(x => x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); - } - - - var orderResult = result.OrderByDescending(x => x.IsCancelRequest) - .ThenByDescending(x => x.RequestTime).ThenByDescending(x => x.IsDoneRequest); - var finalList = orderResult.Skip(searchModel.PageIndex).Take(30).ToList(); - - var addAssign = finalList.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, - }).ToList(); - - - var finalAssign = addAssign.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.IsCancelRequest || x.RequestTime || x.IsDoneRequest ? SetRequestTasksColors(x.RequestTime, x.IsCancelRequest, x.IsDoneRequest) : "", - 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 - }).ToList(); - - var final = finalAssign.Select(x => new TaskViewModel() - { - - AssignList = !(x.SelfAssigned || x.SelfAssigner) ? ExtraTools.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, - CanCheckRequests = x.Sender.PositionValue >= positionValue, - Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname, - AssignedReceiverViewModel = x.AssignViewModels.Any() - ? x.AssignViewModels.MinBy(a => a.AssignedPositionValue) - : new() - { - AssignedName = "-", - AssignedPositionValue = 0 - }, - }).ToList(); - return final; - } - - public List GetAllTasks(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 - }; - IQueryable query; - - if (positionValue == 1) - { - query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) - .ThenInclude(x => x.Media) - .Where(x => - x.Task.IsActiveString == "true" && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) - .Select(x => - new TaskViewModel() - { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest, - - }); - } - else - { - return new(); - } - - 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)); - } - - //res = res.GroupBy(x => x.Id).Select(x => x.First()); - //res = res.OrderBy(x => x.IsDone ? 1 : 0) - // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); - 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 - }); - 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 resEnum = res.AsEnumerable(); - var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); - - 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 - - }).ToList(); - - - final = final.Select(x => new TaskViewModel() - { - - 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 - }).ToList(); - - final = final.Select(x => new TaskViewModel() - { - - - 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 - }, - - }).ToList(); - return final; - - } - - - - - public List GetSentTasks(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 - }; - IQueryable query; - - if (positionValue == 1) - { - query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) - .ThenInclude(x => x.Media) - .Where(x => - x.Task.IsActiveString == "true" && (x.AssignerId == accountId && x.AssignedId != accountId) && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest) && - x.Task.SenderId == accountId) - .Select(x => - new TaskViewModel() - { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest, - - }); - - } - else - { - query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) - .ThenInclude(x => x.Media) - .Where(x => - x.Task.IsActiveString == "true" && x.AssignerId == accountId && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) - .Select(x => - new TaskViewModel() - { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest, - - }); - - - } - - 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, + + //_accountContext.Tasks.Where(x => x.id == TaskId).Select(x => new EditTask() + //{ + // EndTaskDate = x.EndTaskDate.ToFarsi(), + // Description = x.Description, + // Id = x.id, + // Title = x.Title, + // medias = _accountContext.TaskMedias.Include(z => z.Media).Where(e => e.TaskId == x.id).Select(m => + // new MediaViewModel() + // { + // Path = m.Media.Path, + // Type = m.Media.Type, + // Category = m.Media.Category, + // Id = m.Media.id + // }).ToList(), + // EndTaskTime = x.EndTaskDate.ToFarsiFull().Substring(11), + // ContractingPartyName = x.ContractingPartyName, + // CompleteDescription = x.DoneDescription, + // IsDone = x.IsDone, + // ReceiverId = _accountContext.Assigns.Where(a => a.TaskId == x.id).Select(a => a.AssignedId).ToList(), + // SenderId = x.SenderId + + //}).FirstOrDefault(); + return res; + } + + public Tasks GetIncludeAssign(long taskId) + { + return _accountContext.Tasks.Include(x => x.Assigns).FirstOrDefault(x => x.id == taskId); + } + + public void Remove(long id) + { + var task = Get(id); + Remove(task); + } + + + + public List GetRequestedTasks(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 + }; + IQueryable query; + + + query = _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).Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = x.Task.TaskMedias.Count(m => m.TaskId == x.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest + + }); + + //res = res.GroupBy(x => x.Id).Select(x => x.First()); + //res = res.OrderBy(x => x.IsDone ? 1 : 0) + // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); + 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 + }); + 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 resEnum = res.AsEnumerable(); + var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); + + if (searchModel.AccountId > 0) + { + result = result.Where(x => x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); + } + + + var orderResult = result.OrderByDescending(x => x.IsCancelRequest) + .ThenByDescending(x => x.RequestTime).ThenByDescending(x => x.IsDoneRequest); + var finalList = orderResult.Skip(searchModel.PageIndex).Take(30).ToList(); + + var addAssign = finalList.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, + }).ToList(); + + + var finalAssign = addAssign.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.IsCancelRequest || x.RequestTime || x.IsDoneRequest ? SetRequestTasksColors(x.RequestTime, x.IsCancelRequest, x.IsDoneRequest) : "", + 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 + }).ToList(); + + var final = finalAssign.Select(x => new TaskViewModel() + { + + AssignList = !(x.SelfAssigned || x.SelfAssigner) ? ExtraTools.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, + CanCheckRequests = x.Sender.PositionValue >= positionValue, + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname, + AssignedReceiverViewModel = x.AssignViewModels.Any() + ? x.AssignViewModels.MinBy(a => a.AssignedPositionValue) + : new() + { + AssignedName = "-", + AssignedPositionValue = 0 + }, + }).ToList(); + return final; + } + + public List GetAllTasks(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 + }; + IQueryable query; + + if (positionValue == 1) + { + query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) + .ThenInclude(x => x.Media) + .Where(x => + x.Task.IsActiveString == "true" && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) + .Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + + }); + } + else + { + return new(); + } + + 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)); + } + + //res = res.GroupBy(x => x.Id).Select(x => x.First()); + //res = res.OrderBy(x => x.IsDone ? 1 : 0) + // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); + 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 + }); + 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 resEnum = res.AsEnumerable(); + var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); + + 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 + + }).ToList(); + + + final = final.Select(x => new TaskViewModel() + { + + 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 + }).ToList(); + + final = final.Select(x => new TaskViewModel() + { + + + 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 + }, + + }).ToList(); + return final; + + } + + + + + public List GetSentTasks(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 + }; + IQueryable query; + + if (positionValue == 1) + { + query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) + .ThenInclude(x => x.Media) + .Where(x => + x.Task.IsActiveString == "true" && (x.AssignerId == accountId && x.AssignedId != accountId) && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest) && + x.Task.SenderId == accountId) + .Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + + }); + + } + else + { + query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) + .ThenInclude(x => x.Media) + .Where(x => + x.Task.IsActiveString == "true" && x.AssignerId == accountId && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) + .Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + + }); + + + } + + 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) @@ -817,53 +817,53 @@ public class 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 > 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))); - } + (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.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.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.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.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.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); + if (!string.IsNullOrWhiteSpace(searchModel.IsCancelRequest)) + { + bool isCancelReq = bool.Parse(searchModel.IsCancelRequest); + res = res.Where(x => x.IsCancelRequest == isCancelReq); - } + } #endregion @@ -877,7 +877,7 @@ public class CreateDate = x.First().CreateDate, EndTaskDateFA = x.Min(e => e.EndTaskDateGE).ToFarsi(), IsDone = x.All(a => a.IsDone) ? true : false, - EndTaskDateGE = x.All(a => a.IsDone)?x.Min(e=>e.EndTaskDateGE) :x.Where(e=>!e.IsDone).Min(e => e.EndTaskDateGE), + EndTaskDateGE = x.All(a => a.IsDone) ? x.Min(e => e.EndTaskDateGE) : x.Where(e => !e.IsDone).Min(e => e.EndTaskDateGE), Name = x.First().Name, RequestTime = x.First().RequestTime, Id = x.Key, @@ -892,18 +892,18 @@ public class }); - if (searchModel.AccountId > 0) - { - result = result.Where(x => - x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); - } + 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 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(); + var final = orderResult.Skip(searchModel.PageIndex).Take(30).ToList(); final = final.Select(x => new TaskViewModel() { @@ -935,11 +935,11 @@ public class Description = x.Description, IsDoneRequest = x.IsDoneRequest - }).ToList(); + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + final = final.Select(x => new TaskViewModel() + { AssignList = x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() { @@ -971,8 +971,8 @@ public class AssignViewModels = x.AssignViewModels }).ToList(); - final = final.Select(x => new TaskViewModel() - { + final = final.Select(x => new TaskViewModel() + { AssignList = !(x.SelfAssigned || x.SelfAssigner) ? ExtraTools.AddAssign(x.AssignList, x.Sender) @@ -1019,366 +1019,646 @@ public class AssignedPositionValue = 0 }, - }).ToList(); - return final; - } + }).ToList(); + return final; + } - public List AllRequestedTasks(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 - }; - IQueryable query; + public List AllRequestedTasks(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 + }; + IQueryable query; - if (positionValue == 1) - { - query = _accountContext.Assigns.Include(x => x.Task).Where(x => - !x.IsDone && x.Task.IsActiveString == "true" && - (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest)).Select(x => - new TaskViewModel() - { + if (positionValue == 1) + { + query = _accountContext.Assigns.Include(x => x.Task).Where(x => + !x.IsDone && x.Task.IsActiveString == "true" && + (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest)).Select(x => + new TaskViewModel() + { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = x.Task.TaskMedias.Count(m => m.TaskId == x.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = x.Task.TaskMedias.Count(m => m.TaskId == x.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest - }); - } - else - { - return new(); - } - //res = res.GroupBy(x => x.Id).Select(x => x.First()); - //res = res.OrderBy(x => x.IsDone ? 1 : 0) - // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); - 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)); - } - 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)); - } + }); + } + else + { + return new(); + } + //res = res.GroupBy(x => x.Id).Select(x => x.First()); + //res = res.OrderBy(x => x.IsDone ? 1 : 0) + // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); + 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)); + } + 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), + 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, + 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(), + 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 - }); - 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) && + 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 + }); + 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 > 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))); - } + (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.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.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.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.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.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); + if (!string.IsNullOrWhiteSpace(searchModel.IsCancelRequest)) + { + bool isCancelReq = bool.Parse(searchModel.IsCancelRequest); + res = res.Where(x => x.IsCancelRequest == isCancelReq); - } + } - var resEnum = res.AsEnumerable(); - var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); + var resEnum = res.AsEnumerable(); + var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); - if (searchModel.AccountId > 0) - { - result = result.Where(x => x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); - } - var orderResult = result.OrderByDescending(x => x.IsCancelRequest) - .ThenByDescending(x => x.RequestTime).ThenByDescending(x => x.IsDoneRequest); - var finalList = orderResult.Skip(searchModel.PageIndex).Take(30).ToList(); + if (searchModel.AccountId > 0) + { + result = result.Where(x => x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); + } + var orderResult = result.OrderByDescending(x => x.IsCancelRequest) + .ThenByDescending(x => x.RequestTime).ThenByDescending(x => x.IsDoneRequest); + var finalList = orderResult.Skip(searchModel.PageIndex).Take(30).ToList(); - var AddAssign = finalList.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, + var AddAssign = finalList.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, - }).ToList(); + }).ToList(); - var finalAssign = AddAssign.Select(x => new TaskViewModel() - { + var finalAssign = AddAssign.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.IsCancelRequest || x.RequestTime || x.IsDoneRequest ? SetRequestTasksColors(x.RequestTime, x.IsCancelRequest, x.IsDoneRequest) : "", - 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 - }).ToList(); + 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.IsCancelRequest || x.RequestTime || x.IsDoneRequest ? SetRequestTasksColors(x.RequestTime, x.IsCancelRequest, x.IsDoneRequest) : "", + 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 + }).ToList(); - var final = finalAssign.Select(x => new TaskViewModel() - { + var final = finalAssign.Select(x => new TaskViewModel() + { - AssignList = !(x.SelfAssigned || x.SelfAssigner) ? ExtraTools.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, - CanCheckRequests = x.Sender.PositionValue >= positionValue, - Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname, - AssignedReceiverViewModel = x.AssignViewModels.Any() - ? x.AssignViewModels.MinBy(a => a.AssignedPositionValue) - : new() - { - AssignedName = "-", - AssignedPositionValue = 0 - }, - }).ToList(); - return final; - } + AssignList = !(x.SelfAssigned || x.SelfAssigner) ? ExtraTools.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, + CanCheckRequests = x.Sender.PositionValue >= positionValue, + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname, + AssignedReceiverViewModel = x.AssignViewModels.Any() + ? x.AssignViewModels.MinBy(a => a.AssignedPositionValue) + : new() + { + AssignedName = "-", + AssignedPositionValue = 0 + }, + }).ToList(); + return final; + } + + public List GetTasksHaveTicket(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) + .Where(x => + x.Task.IsActiveString == "true" && (x.AssignedId == accountId || x.Task.SenderId == accountId) + && x.Task.TicketId != null && (!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)); + } - public string SetTasksColors(DateTime date, bool isCancel) - { - if (isCancel) - { - //return "brown"; - return "green"; - } - - var now = DateTime.Now.Date; - if (date.Date < now) - { - return "dark"; - } - else if (date.Date == now) - { - return "red"; - } - else if (date.Date > now) - { - return "gray"; - } - - return ""; - - } - - public string SetRequestTasksColors(bool timeRequest, bool cancelRequest, bool isDoneRequest) - { - if (timeRequest) - { - return "yellow"; - } - else if (cancelRequest) - { - return "red"; - } - else if (isDoneRequest) - { - return "green"; - } - else - { - return ""; - } - - } - - public int 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 => - !x.IsDone && x.Task.IsActiveString == "true" && - (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest) && accountId == x.Task.SenderId).GroupBy(x => x.TaskId) - .Select(x => x.First()).Count(); - } - else - { - return _accountContext.Assigns.Include(x => x.Task).Where(x => - !x.IsDone && x.Task.IsActiveString == "true" && - (x.IsCanceledRequest == true || x.TimeRequest == true || x.IsDoneRequest) && (accountId == x.Task.SenderId)).GroupBy(x => x.TaskId) - .Select(x => x.First()).Count(); - } - } - public EditTask GetRequestDetails(long id) - { - var task = Get(id); - EditTask res; + var query = raw.Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + }); + 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 + }); + 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 + + }).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 + }).ToList(); + + final = final.Select(x => new TaskViewModel() + { + + AssignList = !(x.SelfAssigned || x.SelfAssigner) + ? ExtraTools.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 + }, + }).ToList(); + return final; + } + + + public string SetTasksColors(DateTime date, bool isCancel) + { + if (isCancel) + { + //return "brown"; + return "green"; + } + + var now = DateTime.Now.Date; + if (date.Date < now) + { + return "dark"; + } + else if (date.Date == now) + { + return "red"; + } + else if (date.Date > now) + { + return "gray"; + } + + return ""; + + } + + public string SetRequestTasksColors(bool timeRequest, bool cancelRequest, bool isDoneRequest) + { + if (timeRequest) + { + return "yellow"; + } + else if (cancelRequest) + { + return "red"; + } + else if (isDoneRequest) + { + return "green"; + } + else + { + return ""; + } + + } + + public int 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 => + !x.IsDone && x.Task.IsActiveString == "true" && + (x.IsCanceledRequest || x.TimeRequest || x.IsDoneRequest) && accountId == x.Task.SenderId).GroupBy(x => x.TaskId) + .Select(x => x.First()).Count(); + } + else + { + return _accountContext.Assigns.Include(x => x.Task).Where(x => + !x.IsDone && x.Task.IsActiveString == "true" && + (x.IsCanceledRequest == true || x.TimeRequest == true || x.IsDoneRequest) && (accountId == x.Task.SenderId)).GroupBy(x => x.TaskId) + .Select(x => x.First()).Count(); + } + } + + + public EditTask GetRequestDetails(long id) + { + var task = Get(id); + EditTask res; if (task.SenderId == _authHelper.CurrentAccountId()) { - return _accountContext.Tasks.Include(x => x.Assigns).Where(x => x.id == id).Select(x => new EditTask() + var query = _accountContext.Tasks.Include(x => x.Assigns).Where(x => x.id == id).Select(x => new EditTask() { Description = x.Description, @@ -1395,37 +1675,43 @@ public class ContractingPartyName = x.ContractingPartyName, ReceiverId = _accountContext.Assigns.Where(a => a.TaskId == x.id).Select(a => a.AssignedId).ToList(), SenderId = x.SenderId, + CreateDateFa = x.CreationDate.ToFarsi(), + TicketId = x.TicketId, - AssignViewModels = x.Assigns.Where(a => a.IsCanceledRequest || a.IsDoneRequest || a.TimeRequest).Select( - a => new AssignViewModel() - { - Id = a.id, - EndTaskDateFa = a.EndTaskDate.ToFarsiFull(), - IsCancel = a.IsCancel, - IsCanceledRequest = a.IsCanceledRequest, - IsDone = a.IsDone, - IsDoneRequest = a.IsDoneRequest, - TimeRequest = a.TimeRequest, - AssignedName = a.AssignedName, - AssignedId = a.AssignedId, - RequestDateFa = a.RequestDate.ToFarsi() + AssignViewModels = x.Assigns.Where(a => a.IsCanceledRequest || a.IsDoneRequest || a.TimeRequest).Select( + a => new AssignViewModel() + { + Id = a.id, + EndTaskDateFa = a.EndTaskDate.ToFarsiFull(), + IsCancel = a.IsCancel, + IsCanceledRequest = a.IsCanceledRequest, + IsDone = a.IsDone, + IsDoneRequest = a.IsDoneRequest, + TimeRequest = a.TimeRequest, + AssignedName = a.AssignedName, + AssignedId = a.AssignedId, + RequestDateFa = a.RequestDate.ToFarsi() }).ToList(), - TicketViewModel = x.TicketId != null && x.TicketId > 0 - ? _ticketRepository.GetDetails(x.TicketId.Value) - : null, + }).FirstOrDefault(); + + query.TicketViewModel = query.TicketId != null && query.TicketId > 0 + ? _ticketRepository.GetDetails(query.TicketId.Value) + : null; + + return query; } else return new(); } - public string GetWebEnvironmentPath() - { - return _webHostEnvironment.ContentRootPath; - } + public string GetWebEnvironmentPath() + { + return _webHostEnvironment.ContentRootPath; + } public bool HasOverdueTasks() { @@ -1451,912 +1737,912 @@ public class } - // public OperationResult MoveDataFRomTaskToAssign() - // { - // var res = new OperationResult(); - // try - // { - // var tasks = _accountContext.Tasks.ToList(); - - // foreach (var task in tasks) - // { - // var assigns = _accountContext.Assigns.Where(x => x.TaskId == task.id).ToList(); - // foreach (var assign in assigns) - // { - // assign.InsertNewData(task.EndTaskDate, task.TimeRequest, task.AcceptedTimeRequest, task.RequestDate, task.TimeRequestDescription, task.IsCanceledRequest, - // task.IsCancel, task.CancelDescription, task.IsDone, task.IsDoneRequest, task.DoneDescription); - // } - // } - //_positionRepository.SaveChanges(); - // return res.Succcedded(); - // } - // catch (Exception e) - // { - // Console.WriteLine(e); - // return res.Failed("خطای سیستمی"); - // } - - // } - - - public List GetSelfTasks(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 query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) - .ThenInclude(x => x.Media) - .Where(x => - x.Task.IsActiveString == "true" && (x.AssignerId == accountId && x.AssignedId == accountId) && - (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) - .Select(x => - new TaskViewModel() - { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest, - - }); - 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 - }); - 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 - - }).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(), - AssignViewModels = x.AssignViewModels, - 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 - }).ToList(); - - final = final.Select(x => new TaskViewModel() - { - - AssignList = !(x.SelfAssigned || x.SelfAssigner) ? ExtraTools.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 - }, - - }).ToList(); - return final; - } - - - public List GetReceivedTasks(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) - .Where(x => - x.Task.IsActiveString == "true" && x.AssignedId == accountId && (!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.Select(x => - new TaskViewModel() - { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest, - }); - 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 - }); - 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 - - }).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 - }).ToList(); - - final = final.Select(x => new TaskViewModel() - { - - AssignList = !(x.SelfAssigned || x.SelfAssigner) - ? ExtraTools.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 - }, - }).ToList(); - return final; - } - - - - public List GetTasks(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 - }; - IQueryable query; - - if (positionValue == 1) - { - query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) - .ThenInclude(x => x.Media) - .Where(x => - x.Task.IsActiveString == "true" && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) - .Select(x => - new TaskViewModel() - { - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest, - - }); - } - else - { - query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) - .ThenInclude(x => x.Media) - .Where(x => - x.Task.IsActiveString == "true" && (x.AssignedId == accountId || x.AssignerId == accountId)) - .Select(x => - new TaskViewModel() - { - - AssignedId = x.AssignedId, - AssignerId = x.AssignerId, - CreateDate = x.Task.CreationDate.ToFarsi(), - EndTaskDateFA = x.EndTaskDate.ToFarsi(), - IsDone = x.IsDone, - EndTaskDateGE = x.EndTaskDate, - Name = x.Task.Title, - RequestCancel = x.IsCanceledRequest, - RequestTime = x.TimeRequest, - Id = x.Task.id, - CreateTaskDateGE = x.Task.CreationDate, - IsCancel = x.IsCancel, - AcceptedTimeRequest = x.AcceptedTimeRequest, - IsCancelRequest = x.IsCanceledRequest, - ContractingPartyName = x.Task.ContractingPartyName, - MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), - Description = x.Task.Description, - IsDoneRequest = x.IsDoneRequest, - - - }); - } - - 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)); - } - - //res = res.GroupBy(x => x.Id).Select(x => x.First()); - //res = res.OrderBy(x => x.IsDone ? 1 : 0) - // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); - 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 - }); - 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 resEnum = res.AsEnumerable(); - var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); - - 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 - - }).ToList(); - - - final = final.Select(x => new TaskViewModel() - { - - 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 - }).ToList(); - - final = final.Select(x => new TaskViewModel() - { - - - 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 - }, - - }).ToList(); - return final; - - } + // public OperationResult MoveDataFRomTaskToAssign() + // { + // var res = new OperationResult(); + // try + // { + // var tasks = _accountContext.Tasks.ToList(); + + // foreach (var task in tasks) + // { + // var assigns = _accountContext.Assigns.Where(x => x.TaskId == task.id).ToList(); + // foreach (var assign in assigns) + // { + // assign.InsertNewData(task.EndTaskDate, task.TimeRequest, task.AcceptedTimeRequest, task.RequestDate, task.TimeRequestDescription, task.IsCanceledRequest, + // task.IsCancel, task.CancelDescription, task.IsDone, task.IsDoneRequest, task.DoneDescription); + // } + // } + //_positionRepository.SaveChanges(); + // return res.Succcedded(); + // } + // catch (Exception e) + // { + // Console.WriteLine(e); + // return res.Failed("خطای سیستمی"); + // } + + // } + + + public List GetSelfTasks(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 query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) + .ThenInclude(x => x.Media) + .Where(x => + x.Task.IsActiveString == "true" && (x.AssignerId == accountId && x.AssignedId == accountId) && + (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) + .Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + + }); + 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 + }); + 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 + + }).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(), + AssignViewModels = x.AssignViewModels, + 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 + }).ToList(); + + final = final.Select(x => new TaskViewModel() + { + + AssignList = !(x.SelfAssigned || x.SelfAssigner) ? ExtraTools.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 + }, + + }).ToList(); + return final; + } + + + public List GetReceivedTasks(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) + .Where(x => + x.Task.IsActiveString == "true" && x.AssignedId == accountId && (!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.Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + }); + 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 + }); + 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 + + }).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 + }).ToList(); + + final = final.Select(x => new TaskViewModel() + { + + AssignList = !(x.SelfAssigned || x.SelfAssigner) + ? ExtraTools.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 + }, + }).ToList(); + return final; + } + + + + public List GetTasks(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 + }; + IQueryable query; + + if (positionValue == 1) + { + query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) + .ThenInclude(x => x.Media) + .Where(x => + x.Task.IsActiveString == "true" && (!x.IsCanceledRequest && !x.TimeRequest && !x.IsDoneRequest)) + .Select(x => + new TaskViewModel() + { + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + + }); + } + else + { + query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias) + .ThenInclude(x => x.Media) + .Where(x => + x.Task.IsActiveString == "true" && (x.AssignedId == accountId || x.AssignerId == accountId)) + .Select(x => + new TaskViewModel() + { + + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.EndTaskDate.ToFarsi(), + IsDone = x.IsDone, + EndTaskDateGE = x.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.IsCanceledRequest, + RequestTime = x.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.IsCancel, + AcceptedTimeRequest = x.AcceptedTimeRequest, + IsCancelRequest = x.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = _accountContext.TaskMedias.Count(m => m.TaskId == x.Task.id), + Description = x.Task.Description, + IsDoneRequest = x.IsDoneRequest, + + + }); + } + + 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)); + } + + //res = res.GroupBy(x => x.Id).Select(x => x.First()); + //res = res.OrderBy(x => x.IsDone ? 1 : 0) + // .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); + 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 + }); + 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 resEnum = res.AsEnumerable(); + var result = resEnum.GroupBy(x => x.Id).Select(x => x.First()); + + 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 + + }).ToList(); + + + final = final.Select(x => new TaskViewModel() + { + + 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 + }).ToList(); + + final = final.Select(x => new TaskViewModel() + { + + + 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 + }, + + }).ToList(); + return final; + + } } public static class ExtraTools { - public static List AddAssign(List list, AccountViewModel acc) - { - list.Add(new AssignList() - { - AssignViewModels = new List() - { - new () - { - AssignedName = acc.Fullname, - AssignedPositionValue = acc.PositionValue - }, - }.ToList(), - PosValue = acc.PositionValue - }); - return list; + public static List AddAssign(List list, AccountViewModel acc) + { + list.Add(new AssignList() + { + AssignViewModels = new List() + { + new () + { + AssignedName = acc.Fullname, + AssignedPositionValue = acc.PositionValue + }, + }.ToList(), + PosValue = acc.PositionValue + }); + return list; - } + } - public static List AddAccountIdToList(List list, long accountId) - { - list.Add(accountId); - return list; - } + public static List AddAccountIdToList(List list, long accountId) + { + list.Add(accountId); + return list; + } } \ No newline at end of file diff --git a/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs index 9419e62c..ec45e19e 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs @@ -204,66 +204,69 @@ public class TicketRepository : RepositoryBase, ITicketRepository Description = x.Description, Id = x.id, SenderId = x.SenderId, - Sender = _accountContext.Accounts.Select(account => new AccountViewModel() - { - Id = account.id, - Fullname = account.Fullname, - }).Where(a => a.Id == x.SenderId).FirstOrDefault(), TicketType = x.TicketType, Title = x.Title, CreationDateStr = x.CreationDate.ToFarsi(), - MediaViewModels = _accountContext.TicketMedias.Include(z => z.Media).Where(a => a.TicketId == x.id) - .Select(m => new MediaViewModel() - { - Id = m.Media.id, - Path = m.Media.Path, - Type = m.Media.Type, - Category = m.Media.Category, - }).ToList(), - ClientResponseViewModels = _accountContext.ClientResponses.Where(c => c.TicketId == x.id) - .Select(m => new ClientResponseViewModel() - { - Response = m.Response, - TicketId = m.TicketId, - MediaViewModels = _accountContext.ClientResponseMedias.Include(a => a.Media) - .Where(a => a.ClientResponseId == m.id).Select(cm => new MediaViewModel() - { - Category = cm.Media.Category, - Path = cm.Media.Path, - Id = cm.Media.id, - Type = cm.Media.Type, - }).ToList(), - CreationDate = m.CreationDate, - Id = m.id, - }).ToList(), - AdminResponseViewModels = _accountContext.AdminResponses.Where(c => c.TicketId == x.id) - .Select(m => new AdminResponseViewModel() - { - Response = m.Response, - FullName = _accountContext.Accounts.FirstOrDefault(ac => ac.id == m.AdminAccountId).Fullname, - TicketId = m.TicketId, - AdminAccountId = m.AdminAccountId, - MediaViewModels = _accountContext.AdminResponseMedias.Include(a => a.Media) - .Where(a => a.AdminResponseId == m.id).Select(cm => new MediaViewModel() - { - Category = cm.Media.Category, - Path = cm.Media.Path, - Id = cm.Media.id, - Type = cm.Media.Type, - }).ToList(), - CreationDate = m.CreationDate, - Id = m.id, - IsActive = m.IsActiveString, - - }).ToList(), WorkshopId = x.WorkshopId, TicketNumber = $"TKC_{x.TicketNumber}", Status = x.Status }).FirstOrDefault(x => x.Id == id); - query.ResponseViewModels = MergeResponses(query.ClientResponseViewModels, query.AdminResponseViewModels); + query.AdminResponseViewModels = _accountContext.AdminResponses.Where(c => c.TicketId == query.Id) + .Select(m => new AdminResponseViewModel() + { + Response = m.Response, + FullName = _accountContext.Accounts.FirstOrDefault(ac => ac.id == m.AdminAccountId).Fullname, + TicketId = m.TicketId, + AdminAccountId = m.AdminAccountId, + MediaViewModels = _accountContext.AdminResponseMedias.Include(a => a.Media) + .Where(a => a.AdminResponseId == m.id).Select(cm => new MediaViewModel() + { + Category = cm.Media.Category, + Path = cm.Media.Path, + Id = cm.Media.id, + Type = cm.Media.Type, + }).ToList(), + CreationDate = m.CreationDate, + Id = m.id, + IsActive = m.IsActiveString, + }).ToList(); + query.ClientResponseViewModels = _accountContext.ClientResponses.Where(c => c.TicketId == query.Id) + .Select(m => new ClientResponseViewModel() + { + Response = m.Response, + TicketId = m.TicketId, + MediaViewModels = _accountContext.ClientResponseMedias.Include(a => a.Media) + .Where(a => a.ClientResponseId == m.id).Select(cm => new MediaViewModel() + { + Category = cm.Media.Category, + Path = cm.Media.Path, + Id = cm.Media.id, + Type = cm.Media.Type, + }).ToList(), + CreationDate = m.CreationDate, + Id = m.id, + }).ToList(); + query.MediaViewModels = _accountContext.TicketMedias.Include(z => z.Media).Where(a => a.TicketId == query.Id) + .Select(m => new MediaViewModel() + { + Id = m.Media.id, + Path = m.Media.Path, + Type = m.Media.Type, + Category = m.Media.Category, + }).ToList(); + query.Sender = _accountContext.Accounts.Select(account => new AccountViewModel() + { + Id = account.id, + Fullname = account.Fullname, + }).FirstOrDefault(a => a.Id == query.SenderId); + + + + query.ResponseViewModels = MergeResponses(query.ClientResponseViewModels, query.AdminResponseViewModels); + return query; } diff --git a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs index 61521129..0beef7a1 100644 --- a/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallMandatoryRepository.cs @@ -343,7 +343,7 @@ public class RollCallMandatoryRepository : RepositoryBase, IRoll int mandatoryM = (int)(Mandatory.TotalMinutes % 60); overMandatoryHours = mandatoryH.ToString(); overMandatoryMinuts = mandatoryM.ToString(); - } + } } #endregion diff --git a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs index bc06e221..6c9b47f2 100644 --- a/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs +++ b/CompanyManagment.EFCore/Repository/YearlySalaryRepository.cs @@ -1456,20 +1456,48 @@ public class YearlySalaryRepository : RepositoryBase, IYearl .FirstOrDefault(x => x.ContractStart == separationStartDate); if ((hasleft && leftWorkDate <= separationEndDate) || (separationEndDate == contractEnd && checkoutMonth == "12")) { + var end = EndOfYearCantoleaveList(startWorkDate, separationEndDate, workshopId, employeeId, + hasleft, leftWorkDate, fridayStartToEnd, officialHoliday, totalHoursH, totalHorsM, + separationStartDate); + + var canTolv = endOfYearRes.CanToLeave; + var absence = end.Sum(x => x.PeriodOfAbsence); + if (canTolv >= absence) + { + canTolv -= absence; + absence = 0; + + } + else + { + absence -= canTolv; + canTolv = 0; + + } + + result.LeavPay = canTolv * leavePayPerHours; + //مدت غیبت + result.AbsencePeriod = absence; + ////مدت طلب مرخصی + result.CreditLeaves = canTolv; + //کسری غیبت + result.AbsenceDeduction = absence * absenceDeductionPerHourses; + //میانگین ساعت کار در یک روز + result.AverageHoursPerDay = end.FirstOrDefault()!.WorkingPerDayHourses; + //وضعیت تصفیه مزد مرخصی result.LeaveCheckout = true; - ////مدت طلب مرخصی - result.CreditLeaves = 0; + //مزد مرخصی - result.LeavPay = endOfYearRes.CanToLeave * leavePayPerHours; + //result.LeavPay = endOfYearRes.CanToLeave * leavePayPerHours; //مدت غیبت - result.AbsencePeriod = endOfYearRes.PeriodOfAbsence; + //result.AbsencePeriod = endOfYearRes.PeriodOfAbsence; //کسری غیبت - result.AbsenceDeduction = endOfYearRes.PeriodOfAbsence * absenceDeductionPerHourses; + //result.AbsenceDeduction = endOfYearRes.PeriodOfAbsence * absenceDeductionPerHourses; //میانگین ساعت کار در یک روز - result.AverageHoursPerDay = endOfYearRes.WorkingPerDayHourses; + //result.AverageHoursPerDay = endOfYearRes.WorkingPerDayHourses; } else @@ -2612,7 +2640,7 @@ public class YearlySalaryRepository : RepositoryBase, IYearl } -; + bool lastChekout = endMonthGr == contract.ContractEnd; bool endOfyear = lastChekout && isEndOfYear; //if (canToLeave >= usedLeaves) //اگر طلب مرخصی داشت diff --git a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs index 681e065d..a9b050c0 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/Checkouts/Index.cshtml.cs @@ -2697,8 +2697,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w1) endTimeSingel2 = endTimeSingel2.Subtract(rest0w1); sumRest = sumRest.Add(rest0w1); @@ -2724,8 +2725,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w1) endTimeSingel2 = endTimeSingel2.Subtract(rest0w1); @@ -2760,8 +2762,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w2) endTimeSingel2 = endTimeSingel2.Subtract(rest0w2); sumRest = sumRest.Add(rest0w2); @@ -2786,8 +2789,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w2) endTimeSingel2 = endTimeSingel2.Subtract(rest0w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, startTimeTowSh1, endTimeTowSh2); @@ -2820,8 +2824,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w3) endTimeSingel2 = endTimeSingel2.Subtract(rest0w3); sumRest = sumRest.Add(rest0w3); @@ -2846,8 +2851,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe3); - // if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w3) endTimeSingel2 = endTimeSingel2.Subtract(rest0w3); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -2881,8 +2887,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe4); - // if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w4) endTimeSingel2 = endTimeSingel2.Subtract(rest0w4); sumRest = sumRest.Add(rest0w4); @@ -2907,8 +2914,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe4); - // if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w3) endTimeSingel2 = endTimeSingel2.Subtract(rest0w4); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, startTimeTowSh1, endTimeTowSh2); @@ -2942,8 +2950,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w1) endTimeSingel2 = endTimeSingel2.Subtract(rest0w1); sumRest = sumRest.Add(rest0w1); @@ -2968,8 +2977,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w1) endTimeSingel2 = endTimeSingel2.Subtract(rest0w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3003,8 +3013,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w2) endTimeSingel2 = endTimeSingel2.Subtract(rest0w2); sumRest = sumRest.Add(rest0w2); @@ -3029,8 +3040,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Shanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Shanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Shanbe2); - // if (string.IsNullOrWhiteSpace(command.TowShifts1Shanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest0w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest0w2) endTimeSingel2 = endTimeSingel2.Subtract(rest0w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, startTimeTowSh1, endTimeTowSh2); @@ -3066,8 +3078,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe1); - // if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w1) endTimeSingel2 = endTimeSingel2.Subtract(rest1w1); sumRest = sumRest.Add(rest1w1); @@ -3092,8 +3105,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w1) endTimeSingel2 = endTimeSingel2.Subtract(rest1w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3127,8 +3141,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w2) endTimeSingel2 = endTimeSingel2.Subtract(rest1w2); sumRest = sumRest.Add(rest1w2); @@ -3153,8 +3168,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w2) endTimeSingel2 = endTimeSingel2.Subtract(rest1w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3188,8 +3204,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe3); - // if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w3) endTimeSingel2 = endTimeSingel2.Subtract(rest1w3); sumRest = sumRest.Add(rest1w3); @@ -3214,8 +3231,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w3) endTimeSingel2 = endTimeSingel2.Subtract(rest1w3); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3249,8 +3267,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w4) endTimeSingel2 = endTimeSingel2.Subtract(rest1w4); sumRest = sumRest.Add(rest1w4); @@ -3275,8 +3294,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w4) endTimeSingel2 = endTimeSingel2.Subtract(rest1w4); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3310,8 +3330,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w1) endTimeSingel2 = endTimeSingel2.Subtract(rest1w1); sumRest = sumRest.Add(rest1w1); @@ -3336,8 +3357,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w1) endTimeSingel2 = endTimeSingel2.Subtract(rest1w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3371,8 +3393,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w2) endTimeSingel2 = endTimeSingel2.Subtract(rest1w2); sumRest = sumRest.Add(rest1w2); @@ -3397,8 +3420,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2YekShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1YekShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2YekShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1YekShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest1w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest1w2) endTimeSingel2 = endTimeSingel2.Subtract(rest1w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3435,8 +3459,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w1) endTimeSingel2 = endTimeSingel2.Subtract(rest2w1); sumRest = sumRest.Add(rest2w1); @@ -3462,8 +3487,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w1) endTimeSingel2 = endTimeSingel2.Subtract(rest2w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3497,8 +3523,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe2); - // if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w2) endTimeSingel2 = endTimeSingel2.Subtract(rest2w2); sumRest = sumRest.Add(rest2w2); @@ -3523,8 +3550,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w2) endTimeSingel2 = endTimeSingel2.Subtract(rest2w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3558,8 +3586,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w3) endTimeSingel2 = endTimeSingel2.Subtract(rest2w3); sumRest = sumRest.Add(rest2w3); @@ -3584,8 +3613,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w3) endTimeSingel2 = endTimeSingel2.Subtract(rest2w3); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3619,8 +3649,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w4) endTimeSingel2 = endTimeSingel2.Subtract(rest2w4); sumRest = sumRest.Add(rest2w4); @@ -3645,8 +3676,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe4); - // if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w4) endTimeSingel2 = endTimeSingel2.Subtract(rest2w4); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3680,8 +3712,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w1) endTimeSingel2 = endTimeSingel2.Subtract(rest2w1); sumRest = sumRest.Add(rest2w1); @@ -3706,8 +3739,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w1) endTimeSingel2 = endTimeSingel2.Subtract(rest2w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3741,8 +3775,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w2) endTimeSingel2 = endTimeSingel2.Subtract(rest2w2); sumRest = sumRest.Add(rest2w2); @@ -3767,8 +3802,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2DoShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1DoShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2DoShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1DoShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest2w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest2w2) endTimeSingel2 = endTimeSingel2.Subtract(rest2w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3805,8 +3841,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w1) endTimeSingel2 = endTimeSingel2.Subtract(rest3w1); sumRest = sumRest.Add(rest3w1); @@ -3831,8 +3868,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w1) endTimeSingel2 = endTimeSingel2.Subtract(rest3w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3866,8 +3904,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w2) endTimeSingel2 = endTimeSingel2.Subtract(rest3w2); sumRest = sumRest.Add(rest3w2); @@ -3892,8 +3931,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w2) endTimeSingel2 = endTimeSingel2.Subtract(rest3w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3927,8 +3967,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w3) endTimeSingel2 = endTimeSingel2.Subtract(rest3w3); sumRest = sumRest.Add(rest3w3); @@ -3953,8 +3994,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w3) endTimeSingel2 = endTimeSingel2.Subtract(rest3w3); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -3988,8 +4030,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w4) endTimeSingel2 = endTimeSingel2.Subtract(rest3w4); sumRest = sumRest.Add(rest3w4); @@ -4014,8 +4057,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w4) endTimeSingel2 = endTimeSingel2.Subtract(rest3w4); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4049,8 +4093,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w1) endTimeSingel2 = endTimeSingel2.Subtract(rest3w1); sumRest = sumRest.Add(rest3w1); @@ -4075,8 +4120,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w1) endTimeSingel2 = endTimeSingel2.Subtract(rest3w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4110,8 +4156,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w2) endTimeSingel2 = endTimeSingel2.Subtract(rest3w2); sumRest = sumRest.Add(rest3w2); @@ -4136,8 +4183,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2SeShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1SeShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2SeShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1SeShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest3w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest3w2) endTimeSingel2 = endTimeSingel2.Subtract(rest3w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4174,8 +4222,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w1) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w1) endTimeSingel2 = endTimeSingel2.Subtract(rest4w1); sumRest = sumRest.Add(rest4w1); @@ -4200,8 +4251,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w1) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w1) endTimeSingel2 = endTimeSingel2.Subtract(rest4w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4235,8 +4289,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w2) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w2) endTimeSingel2 = endTimeSingel2.Subtract(rest4w2); sumRest = sumRest.Add(rest4w2); @@ -4261,8 +4318,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest4w2) endTimeSingel2 = endTimeSingel2.Subtract(rest4w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4296,8 +4354,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w3) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w3) endTimeSingel2 = endTimeSingel2.Subtract(rest4w3); sumRest = sumRest.Add(rest4w3); @@ -4322,8 +4383,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe3); - // if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w3) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w3) endTimeSingel2 = endTimeSingel2.Subtract(rest4w3); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4357,8 +4421,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w4) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w4) endTimeSingel2 = endTimeSingel2.Subtract(rest4w4); sumRest = sumRest.Add(rest4w4); @@ -4383,8 +4450,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe4); - // if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w4) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w4) endTimeSingel2 = endTimeSingel2.Subtract(rest4w4); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4418,8 +4488,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w1) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w1) endTimeSingel2 = endTimeSingel2.Subtract(rest4w1); sumRest = sumRest.Add(rest4w1); @@ -4444,8 +4517,10 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe1); - // if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w1) endTimeSingel2 = endTimeSingel2.Subtract(rest4w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4479,8 +4554,11 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w2) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + + if (endTimeSingel2 - starTimeSingel1 >= rest4w2) endTimeSingel2 = endTimeSingel2.Subtract(rest4w2); sumRest = sumRest.Add(rest4w2); @@ -4505,8 +4583,10 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2CheharShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1CheharShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2CheharShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1CheharShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest4w2) + + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest4w2) endTimeSingel2 = endTimeSingel2.Subtract(rest4w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4543,8 +4623,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w1) endTimeSingel2 = endTimeSingel2.Subtract(rest5w1); sumRest = sumRest.Add(rest5w1); @@ -4569,8 +4650,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe1); - // if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w1) endTimeSingel2 = endTimeSingel2.Subtract(rest5w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4604,8 +4686,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe2); - // if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w2) endTimeSingel2 = endTimeSingel2.Subtract(rest5w2); sumRest = sumRest.Add(rest5w2); @@ -4630,8 +4713,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w2) endTimeSingel2 = endTimeSingel2.Subtract(rest5w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4665,8 +4749,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w3) endTimeSingel2 = endTimeSingel2.Subtract(rest5w3); sumRest = sumRest.Add(rest5w3); @@ -4691,8 +4776,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe3)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w3) endTimeSingel2 = endTimeSingel2.Subtract(rest5w3); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4726,8 +4812,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w4) endTimeSingel2 = endTimeSingel2.Subtract(rest5w4); sumRest = sumRest.Add(rest5w4); @@ -4752,8 +4839,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe4)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w4) endTimeSingel2 = endTimeSingel2.Subtract(rest5w4); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4787,8 +4875,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w1) endTimeSingel2 = endTimeSingel2.Subtract(rest5w1); sumRest = sumRest.Add(rest5w1); @@ -4813,8 +4902,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe1)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w1) endTimeSingel2 = endTimeSingel2.Subtract(rest5w1); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4848,8 +4938,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w2) endTimeSingel2 = endTimeSingel2.Subtract(rest5w2); sumRest = sumRest.Add(rest5w2); @@ -4874,8 +4965,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2PanjShanbe2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1PanjShanbe2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2PanjShanbe2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1PanjShanbe2)) - if (endTimeSingel2 - starTimeSingel1 >= rest5w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest5w2) endTimeSingel2 = endTimeSingel2.Subtract(rest5w2); var rotatingCheck = RotatingShiftCheck(starTimeSingel1, endTimeSingel2, @@ -4911,8 +5003,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Jome1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Jome1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Jome1); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Jome1)) - if (endTimeSingel2 - starTimeSingel1 >= rest6w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest6w1) endTimeSingel2 = endTimeSingel2.Subtract(rest6w1); sumRest = sumRest.Add(rest6w1); @@ -4948,8 +5041,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Jome2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Jome2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Jome2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Jome2)) - if (endTimeSingel2 - starTimeSingel1 >= rest6w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest6w2) endTimeSingel2 = endTimeSingel2.Subtract(rest6w2); sumRest = sumRest.Add(rest6w2); @@ -4984,8 +5078,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Jome3); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Jome3); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Jome3); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Jome3)) - if (endTimeSingel2 - starTimeSingel1 >= rest6w3) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest6w3) endTimeSingel2 = endTimeSingel2.Subtract(rest6w3); sumRest = sumRest.Add(rest6w3); @@ -5020,8 +5115,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Jome4); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Jome4); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Jome4); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Jome4)) - if (endTimeSingel2 - starTimeSingel1 >= rest6w4) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest6w4) endTimeSingel2 = endTimeSingel2.Subtract(rest6w4); sumRest = sumRest.Add(rest6w4); @@ -5056,8 +5152,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Jome1); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Jome1); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Jome1); - // if (string.IsNullOrWhiteSpace(command.TowShifts1Jome1)) - if (endTimeSingel2 - starTimeSingel1 >= rest6w1) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest6w1) endTimeSingel2 = endTimeSingel2.Subtract(rest6w1); sumRest = sumRest.Add(rest6w1); @@ -5092,8 +5189,9 @@ public class IndexModel : PageModel endTimeSingel2 = Convert.ToDateTime(command.SingleShift2Jome2); startTimeTowSh1 = Convert.ToDateTime(command.TowShifts1Jome2); endTimeTowSh2 = Convert.ToDateTime(command.TowShifts2Jome2); - //if (string.IsNullOrWhiteSpace(command.TowShifts1Jome2)) - if (endTimeSingel2 - starTimeSingel1 >= rest6w2) + if (endTimeSingel2.TimeOfDay == new TimeSpan(0, 0, 0)) + endTimeSingel2 = endTimeSingel2.AddDays(1); + if (endTimeSingel2 - starTimeSingel1 >= rest6w2) endTimeSingel2 = endTimeSingel2.Subtract(rest6w2); sumRest = sumRest.Add(rest6w2); diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateModal.cshtml b/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateModal.cshtml index 3a8e2127..91640267 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateModal.cshtml +++ b/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateModal.cshtml @@ -102,8 +102,8 @@
- - + +
@@ -111,7 +111,7 @@
- +
@@ -122,7 +122,7 @@
- +