diff --git a/0_Framework/Application/Version.cs b/0_Framework/Application/Version.cs index 13f01541..e9c4589a 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.11.28"; - AdminVersion = "2.5.13"; + StyleVersion = "2.11.31"; + AdminVersion = "2.5.16"; CameraVersion = "1.0.3"; } diff --git a/AccountManagement.Application.Contracts/Task/CreateTask.cs b/AccountManagement.Application.Contracts/Task/CreateTask.cs index a88b849f..8b951b5f 100644 --- a/AccountManagement.Application.Contracts/Task/CreateTask.cs +++ b/AccountManagement.Application.Contracts/Task/CreateTask.cs @@ -12,15 +12,9 @@ public class CreateTask public string EndTaskTime { get; set; } public string ContractingPartyName { get; set; } public string? Description { get; set; } - public IFormFile Document1 { get; set; } - public IFormFile Document2 { get; set; } - public IFormFile Document3 { get; set; } - public IFormFile Document4 { get; set; } - public IFormFile Document5 { get; set; } - public IFormFile Document6 { get; set; } public List PositionId { get; set; } - - public IFormFile Voice{ get; set; } + public List UploadedMedia { get; set; } + public long UploadedVoiceMedia { get; set; } diff --git a/AccountManagement.Application.Contracts/Task/ITaskApplication.cs b/AccountManagement.Application.Contracts/Task/ITaskApplication.cs index 39d18075..b2cf6640 100644 --- a/AccountManagement.Application.Contracts/Task/ITaskApplication.cs +++ b/AccountManagement.Application.Contracts/Task/ITaskApplication.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using _0_Framework.Application; using AccountManagement.Application.Contracts.Assign; +using Microsoft.AspNetCore.Http; namespace AccountManagement.Application.Contracts.Task; @@ -40,10 +41,14 @@ public interface ITaskApplication OperationResult RejectCompleteRequest(long taskId); OperationResult CreateTaskByPosition(CreateTask command, List positionIds); - List GetAllRequestedTasks(TaskSearchModel searchModel); + List GetRequestedTasks(TaskSearchModel searchModel); + List AllRequestedTasks(TaskSearchModel searchModel); int GetRequestedTasksCount(); OperationResult ChangeRequestTimeAndAccept(string time,long taskId); TaskViewModel GetRequestDetails(long id); + OperationResult UploadMedia(IFormFile mediaFile,long senderId); + OperationResult RemoveMedia(long mediaId); + void RemoveTempUploadedFiles(long userId); } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Task/TaskSearchModel.cs b/AccountManagement.Application.Contracts/Task/TaskSearchModel.cs index f40ff119..09936fcf 100644 --- a/AccountManagement.Application.Contracts/Task/TaskSearchModel.cs +++ b/AccountManagement.Application.Contracts/Task/TaskSearchModel.cs @@ -12,7 +12,7 @@ public class TaskSearchModel public string IsCancelRequest { get; set; } public string IsTimeRequest { get; set; } public string TimeRequestAccepted { get; set; } - public string TypeOfTicket { get; set; } + public string TypeOfTask { get; set; } public string GeneralSearch { get; set; } diff --git a/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs b/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs index 0182e371..5821c6e1 100644 --- a/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs +++ b/AccountManagement.Application.Contracts/Ticket/CreateTicket.cs @@ -10,11 +10,7 @@ public class CreateTicket public long SenderId { get; set; } public string ContractingPartyName { get; set; } public string TicketType { get; set; } - public IFormFile Document1 { get; set; } - public IFormFile Document2 { get; set; } - public IFormFile Document3 { get; set; } - public IFormFile Document4 { get; set; } - public IFormFile Document5 { get; set; } - public IFormFile ScreenShot { get; set; } - public IFormFile Voice { get; set; } + public List UploadedMediaIds { get; set; } + public long ScreenShotId { get; set; } + public long VoiceId { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Ticket/EditTicket.cs b/AccountManagement.Application.Contracts/Ticket/EditTicket.cs index 5509fd95..77ec0ae0 100644 --- a/AccountManagement.Application.Contracts/Ticket/EditTicket.cs +++ b/AccountManagement.Application.Contracts/Ticket/EditTicket.cs @@ -7,4 +7,6 @@ public class EditTicket:CreateTicket { public long Id { get; set; } public List MediaViewModels { get; set; } + public List AdminResponseViewModels{ get; set; } + public List ClientResponseViewModels { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Ticket/Response.cs b/AccountManagement.Application.Contracts/Ticket/Response.cs new file mode 100644 index 00000000..5b09069a --- /dev/null +++ b/AccountManagement.Application.Contracts/Ticket/Response.cs @@ -0,0 +1,16 @@ +using AccountManagement.Application.Contracts.Media; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccountManagement.Application.Contracts.Ticket; +public class Response +{ + public long TicketId { get; set; } + public string ResponseMessage { get; set; } + public bool IsAdmin { get; set; } + public bool IsClient { get; set; } + public List MediaViewModels { get; set; } +} \ No newline at end of file diff --git a/AccountManagement.Application.Contracts/Ticket/ResponseTicket.cs b/AccountManagement.Application.Contracts/Ticket/ResponseTicket.cs index 9843cf83..a233e0d9 100644 --- a/AccountManagement.Application.Contracts/Ticket/ResponseTicket.cs +++ b/AccountManagement.Application.Contracts/Ticket/ResponseTicket.cs @@ -6,11 +6,6 @@ public class ResponseTicket { public long TicketId { get; set; } public string Response { get; set; } - public IFormFile Document1 { get; set; } - public IFormFile Document2 { get; set; } - public IFormFile Document3 { get; set; } - public IFormFile Document4 { get; set; } - public IFormFile Document5 { get; set; } - public IFormFile Document6 { get; set; } - public IFormFile Voice { get; set; } + public List UploadedFileIds { get; set; } + public long VoiceId { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application/AccountManagement.Application.csproj b/AccountManagement.Application/AccountManagement.Application.csproj index 1d0d8fd6..cab6f7be 100644 --- a/AccountManagement.Application/AccountManagement.Application.csproj +++ b/AccountManagement.Application/AccountManagement.Application.csproj @@ -7,8 +7,7 @@ - - + diff --git a/AccountManagement.Application/TaskApplication.cs b/AccountManagement.Application/TaskApplication.cs index 132ec015..1bc26aec 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; @@ -12,7 +13,7 @@ using AccountManagement.Domain.TaskAgg; using IPE.SmsIrClient.Models.Results; using TaskManager.Domain.PositionAgg; using System.Reflection; -using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Http; using System.Globalization; @@ -20,1155 +21,880 @@ using System.Globalization; namespace AccountManagement.Application; public class TaskApplication : ITaskApplication { - private readonly ITaskRepository _taskRepository; - private readonly IAccountRepository _accountRepository; - private readonly IMediaRepository _mediaRepository; - private readonly IPositionRepository _positionRepository; - private readonly IAssignRepository _assignRepository; - private readonly IHttpContextAccessor _contextAccessor; - private readonly IWebHostEnvironment _webHostEnvironment; - private readonly IAuthHelper _authHelper; + private readonly ITaskRepository _taskRepository; + private readonly IAccountRepository _accountRepository; + private readonly IMediaRepository _mediaRepository; + private readonly IPositionRepository _positionRepository; + private readonly IAssignRepository _assignRepository; + private readonly IHttpContextAccessor _contextAccessor; + + private readonly IAuthHelper _authHelper; - public TaskApplication(ITaskRepository taskRepository, IAccountRepository accountRepository, IMediaRepository mediaRepository, IAssignRepository assignRepository, IHttpContextAccessor contextAccessor, IPositionRepository positionRepository, IWebHostEnvironment webHostEnvironment, IAuthHelper authHelper) - { - _taskRepository = taskRepository; - _accountRepository = accountRepository; - _mediaRepository = mediaRepository; - _assignRepository = assignRepository; - _contextAccessor = contextAccessor; - _positionRepository = positionRepository; - _webHostEnvironment = webHostEnvironment; - _authHelper = authHelper; - } - //غیرفعال سازی تسک - public OperationResult DeActiveTask(long TaskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == TaskId)) + public TaskApplication(ITaskRepository taskRepository, IAccountRepository accountRepository, IMediaRepository mediaRepository, IAssignRepository assignRepository, IHttpContextAccessor contextAccessor, IPositionRepository positionRepository, IAuthHelper authHelper) + { + _taskRepository = taskRepository; + _accountRepository = accountRepository; + _mediaRepository = mediaRepository; + _assignRepository = assignRepository; + _contextAccessor = contextAccessor; + _positionRepository = positionRepository; + + _authHelper = authHelper; + } + //غیرفعال سازی تسک + public OperationResult DeActiveTask(long TaskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == TaskId)) + { + return operation.Failed("چنین وظیفه ای برای حذف وجود ندارد!"); + } + + var task = _taskRepository.Get(TaskId); + task.DeActive(); + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + + } + //حذف کامل تسک + public OperationResult RemoveTask(long TaskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == TaskId)) + { + return operation.Failed("چنین وظیفه ای برای حذف وجود ندارد!"); + } + + var task = _taskRepository.Get(TaskId); + var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); + var sender = _accountRepository.GetIncludePositions(task.SenderId); + if (sender.Position.PositionValue < positionValue) + { + return operation.Failed("شما نمیتواند وظیفه ای که سطحی از شما پایین تر دارد را حذف کنید"); + } + var medias = _mediaRepository.GetMediaByTaskId(TaskId); + if (task.IsCanceledRequest || task.IsDone || task.IsCancel || task.TimeRequest || task.AcceptedTimeRequest > 0) + { + task.DeActive(); + } + else + { + foreach (var item in medias) + { + RemoveFile(item.Id); + } + _taskRepository.Remove(task.id); + + } + + _taskRepository.SaveChanges(); + return operation.Succcedded(); + } + //حذف فایلی در تسک + public OperationResult RemoveFile(long MediaId) + { + var operation = new OperationResult(); + if (!_mediaRepository.Exists(x => x.id == MediaId)) + { + operation.Failed("چنین فایلی وجود ندارد"); + } + var media = _mediaRepository.Get(MediaId); + File.Delete(media.Path); + _mediaRepository.Remove(media.id); + _mediaRepository.SaveChanges(); + return operation.Succcedded(); + } + //ویرایش تسک + public OperationResult Edit(EditTask command) + { + var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); + var operation = new OperationResult(); + if (string.IsNullOrEmpty(command.Title)) + { + return operation.Failed("لطفا عنوان وظیفه خود ار وارد کنید"); + } + + if (string.IsNullOrEmpty(command.EndTaskDate)) + { + return operation.Failed("لطفا تاریخ انجام وظیفه را وارد کنید"); + } + + if (command.ReceiverId.Count < 1) + { + return operation.Failed("طرف وظیفه خود را وارد کنید"); + } + + if (command.SenderId < 1) + { + return operation.Failed("خطای سیستمی!!!"); + } + + var sender = _accountRepository.GetIncludePositions(command.SenderId); + if (sender.Position.PositionValue < posValue) + { + return operation.Failed("شما حق ویرایش این وظیفه را ندارید"); + } + var receivers = _accountRepository.GetAccountsByIds(command.ReceiverId); + + if (sender.Position.PositionValue == 1) + { + + } + + else if (receivers.Any(x => sender.Position.PositionValue >= x.Position.PositionValue)) + { + var checkReceiver = receivers.Where(x => sender.Position.PositionValue >= x.Position.PositionValue).ToList(); + if (checkReceiver.All(x => x.id == sender.id)) + { + + } + else if (checkReceiver.Any(x => sender.Position.PositionValue > x.Position.PositionValue)) + { + return operation.Failed("شما نمیتوانید به سطح بالاتر خود وظیفه ای دهید"); + } + + } + else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id)) + { + + } + var task = _taskRepository.Get(command.Id); + var endTask = command.EndTaskDate.ToGeorgianDateTime(); + var errorDateTime = new DateTime(3000, 12, 20, new PersianCalendar()); + if (endTask == errorDateTime) + { + return operation.Failed("لطفا تاریخ را به درستی وارد کنید"); + } + + task.Edit(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName); + _taskRepository.SaveChanges(); + _assignRepository.RemoveRangeAssigns(task.id); + foreach (var receiver in receivers) + { + var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, + receiver.Fullname, + receiver.Position.PositionValue); + _assignRepository.Create(assign); + } + _assignRepository.SaveChanges(); + + #region ChangeMedias + + + #region SaveDocuments + + if (command.UploadedMedia?.Count>0) + { + foreach (var mediaId in command.UploadedMedia) + { + var media = _mediaRepository.Get(mediaId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "Task", $"{task.id}"); + Directory.CreateDirectory(path); + + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, media.Category); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); + } + } + + + + + + #endregion + + + + if (command.UploadedVoiceMedia > 0) + { + var media = _mediaRepository.Get(command.UploadedVoiceMedia); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "Task", $"{task.id}"); + Directory.CreateDirectory(path); + + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, "صوت"); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); + + } + #region DeleteMedias + + if (command.DeletedFileIds?.Count > 0) + { + foreach (var mediaId in command.DeletedFileIds) + { + var media = _mediaRepository.Get(mediaId); + _mediaRepository.Remove(media.id); + File.Delete(media.Path); + } + } + + _mediaRepository.SaveChanges(); + + #endregion + + #endregion + + + _taskRepository.SaveChanges(); + return operation.Succcedded(); + } + //ساخت یک ارجاع دهنده + public OperationResult CreateAssign(CreateAssign command) + { + var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == command.TaskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + if (!_accountRepository.Exists(x => x.id == command.AssignerId)) + { + return operation.Failed("خطای سیستمی!!"); + } + + foreach (var assignedId in command.AssignedId) + { + if (!_accountRepository.Exists(x => x.id == assignedId)) + { + return operation.Failed("چنین شخصی برای ارجاع وجود ندارد."); + } + + } + + var assigner = _accountRepository.GetIncludePositions(command.AssignerId); + foreach (var assignedId in command.AssignedId) + { + var assigned = _accountRepository.GetIncludePositions(assignedId); + + var assign = new Assign(command.TaskId, command.AssignerId, assignedId, assigner.Position.PositionValue, + assigned.Fullname, assigned.Position.PositionValue); + _assignRepository.Create(assign); + } + _assignRepository.SaveChanges(); + return operation.Succcedded(); + } + //ساخت تسک + public OperationResult CreateTask(CreateTask command) + { + var operation = new OperationResult(); + if (string.IsNullOrEmpty(command.Title)) + { + return operation.Failed("لطفا عنوان وظیفه خود ار وارد کنید"); + } + var now = DateTime.Now.Date; + if (string.IsNullOrEmpty(command.EndTaskDate)) + { + + return operation.Failed("لطفا تاریخ انجام وظیفه را وارد کنید"); + } + + + + if (string.IsNullOrEmpty(command.ContractingPartyName)) + { + return operation.Failed("لطفا طرف حساب خودرا وارد کنید"); + } + + + if (command.SenderId < 1) + { + return operation.Failed("خطای سیستمی!!!"); + } + + var sender = _accountRepository.GetIncludePositions(command.SenderId); + + if (command.PositionId?.Count > 0 && command.ReceiverId?.Count > 0) + { + if (command.PositionId.Any(x => x > 0)) + { + return operation.Failed("شما نمیتوانید همرمان به صورت انفرادی و هم به صورت گروهی تسک دهید. "); + } + } + else if (command.PositionId?.Count > 0) + { + var res = CreateTaskByPosition(command); + return res; + } + if (command.ReceiverId.Count < 1) + { + return operation.Failed("طرف وظیفه خود را وارد کنید"); + } + + var receivers = _accountRepository.GetAccountsByIds(command.ReceiverId); + + if (sender.Position.PositionValue == 1) + { + + } + + else if (receivers.Any(x => sender.Position.PositionValue >= x.Position.PositionValue)) + { + var checkReceiver = receivers.Where(x => sender.Position.PositionValue >= x.Position.PositionValue).ToList(); + if (checkReceiver.All(x => x.id == sender.id)) + { + + } + else if (checkReceiver.Any(x => sender.Position.PositionValue > x.Position.PositionValue)) + { + return operation.Failed("شما نمیتوانید به سطح بالاتر خود یا هم سطح خود وظیفه ای دهید"); + } + + } + else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id)) + { + + } + + + var endTask = string.IsNullOrWhiteSpace(command.EndTaskTime) || command.EndTaskTime == "00:00" ? command.EndTaskDate.ToGeorgianDateTime2() : command.EndTaskDate.ToGeorgianDateWithTime(command.EndTaskTime); + + var errorDateTime = new DateTime(3000, 12, 20, new PersianCalendar()); + if (endTask == errorDateTime) + { + return operation.Failed("لطفا تاریخ را به درستی وارد کنید"); + } + + if (endTask.Date < now) + { + return operation.Failed("لطفا تاریخ آینده را وارد کنید"); + } + var task = new Tasks(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName); + _taskRepository.Create(task); + _assignRepository.SaveChanges(); + foreach (var receiver in receivers) + { + var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, receiver.Fullname, + receiver.Position.PositionValue); + _assignRepository.Create(assign); + } + + + + #region SaveMedias + + #region SaveDocuments + + if (command.UploadedMedia?.Count > 0) { - return operation.Failed("چنین وظیفه ای برای حذف وجود ندارد!"); - } - - var task = _taskRepository.Get(TaskId); - task.DeActive(); - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - - } - //حذف کامل تسک - public OperationResult RemoveTask(long TaskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == TaskId)) - { - return operation.Failed("چنین وظیفه ای برای حذف وجود ندارد!"); - } - - var task = _taskRepository.Get(TaskId); - var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); - var sender = _accountRepository.GetIncludePositions(task.SenderId); - if (sender.Position.PositionValue < positionValue) - { - return operation.Failed("شما نمیتواند وظیفه ای که سطحی از شما پایین تر دارد را حذف کنید"); - } - var medias = _mediaRepository.GetMediaByTaskId(TaskId); - if (task.IsCanceledRequest || task.IsDone || task.IsCancel || task.TimeRequest || task.AcceptedTimeRequest > 0) - { - task.DeActive(); - } - else - { - foreach (var item in medias) - { - RemoveFile(item.Id); - } - _taskRepository.Remove(task.id); - - } - - _taskRepository.SaveChanges(); - return operation.Succcedded(); - } - //حذف فایلی در تسک - public OperationResult RemoveFile(long MediaId) - { - var operation = new OperationResult(); - if (!_mediaRepository.Exists(x => x.id == MediaId)) - { - operation.Failed("چنین فایلی وجود ندارد"); - } - var media = _mediaRepository.Get(MediaId); - File.Delete(media.Path); - _mediaRepository.Remove(media.id); - _mediaRepository.SaveChanges(); - return operation.Succcedded(); - } - //ویرایش تسک - public OperationResult Edit(EditTask command) - { - var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); - var operation = new OperationResult(); - if (string.IsNullOrEmpty(command.Title)) - { - return operation.Failed("لطفا عنوان وظیفه خود ار وارد کنید"); - } - - if (string.IsNullOrEmpty(command.EndTaskDate)) - { - return operation.Failed("لطفا تاریخ انجام وظیفه را وارد کنید"); - } - - if (command.ReceiverId.Count < 1) - { - return operation.Failed("طرف وظیفه خود را وارد کنید"); - } - - if (command.SenderId < 1) - { - return operation.Failed("خطای سیستمی!!!"); - } - - var sender = _accountRepository.GetIncludePositions(command.SenderId); - if (sender.Position.PositionValue < posValue) - { - return operation.Failed("شما حق ویرایش این وظیفه را ندارید"); - } - var receivers = _accountRepository.GetAccountsByIds(command.ReceiverId); - - if (sender.Position.PositionValue == 1) - { - - } - - else if (receivers.Any(x => sender.Position.PositionValue >= x.Position.PositionValue)) - { - var checkReceiver = receivers.Where(x => sender.Position.PositionValue >= x.Position.PositionValue).ToList(); - if (checkReceiver.All(x => x.id == sender.id)) - { - - } - else - { - return operation.Failed("شما نمیتوانید به سطح بالاتر خود یا هم سطح خود وظیفه ای دهید"); - } - - } - else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id)) - { - - } - var task = _taskRepository.Get(command.Id); - var endTask = command.EndTaskDate.ToGeorgianDateTime(); - var errorDateTime = new DateTime(3000, 12, 20, new PersianCalendar()); - if (endTask == errorDateTime) - { - return operation.Failed("لطفا تاریخ را به درستی وارد کنید"); - } - - task.Edit(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName); - _taskRepository.SaveChanges(); - _assignRepository.RemoveRangeAssigns(task.id); - foreach (var receiver in receivers) - { - var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, - receiver.Fullname, - receiver.Position.PositionValue); - _assignRepository.Create(assign); - } - _assignRepository.SaveChanges(); - - #region ChangeMedias - - #region DeleteMedias - - if (command.DeletedFileIds?.Count > 0) - { - foreach (var mediaId in command.DeletedFileIds) + foreach (var mediaId in command.UploadedMedia) { var media = _mediaRepository.Get(mediaId); - _mediaRepository.Remove(media.id); - File.Delete(media.Path); - } - } - - _mediaRepository.SaveChanges(); - - #endregion - - - - - #region SaveDocuments - - if ((command.Document1?.Length > 2000000) || (command.Document2?.Length > 2000000) || (command.Document3?.Length > 2000000)) - return operation.Failed("حجم فایل نمیتواند از 2 مگابایت بیشتر باشد"); - - if (command.Document1?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document1.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document1.CopyTo(stream); - - } - - - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - } - if (command.Document2?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document2.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document2.CopyTo(stream); - - } - - - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - } - if (command.Document3?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document3.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document3.CopyTo(stream); - - } - - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - - } - if (command.Document4?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document4.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document4.CopyTo(stream); - - } - - - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - } - if (command.Document5?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document5.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document5.CopyTo(stream); - - } - - - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - } - if (command.Document6?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document6.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document6.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - } - - - - - - - #endregion - - - - if (command.Voice?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Voice.FileName); - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Voice.CopyTo(stream); - } - - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "صوت"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - - } - - - #endregion - - - _taskRepository.SaveChanges(); - return operation.Succcedded(); - } - //ساخت یک ارجاع دهنده - public OperationResult CreateAssign(CreateAssign command) - { - var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == command.TaskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - if (!_accountRepository.Exists(x => x.id == command.AssignerId)) - { - return operation.Failed("خطای سیستمی!!"); - } - - foreach (var assignedId in command.AssignedId) - { - if (!_accountRepository.Exists(x => x.id == assignedId)) - { - return operation.Failed("چنین شخصی برای ارجاع وجود ندارد."); - } - - } - - var assigner = _accountRepository.GetIncludePositions(command.AssignerId); - foreach (var assignedId in command.AssignedId) - { - var assigned = _accountRepository.GetIncludePositions(assignedId); - - var assign = new Assign(command.TaskId, command.AssignerId, assignedId, assigner.Position.PositionValue, - assigned.Fullname, assigned.Position.PositionValue); - _assignRepository.Create(assign); - } - _assignRepository.SaveChanges(); - return operation.Succcedded(); - } - //ساخت تسک - public OperationResult CreateTask(CreateTask command) - { - var operation = new OperationResult(); - if (string.IsNullOrEmpty(command.Title)) - { - return operation.Failed("لطفا عنوان وظیفه خود ار وارد کنید"); - } - - if (string.IsNullOrEmpty(command.EndTaskDate)) - { - return operation.Failed("لطفا تاریخ انجام وظیفه را وارد کنید"); - } - - - - if (string.IsNullOrEmpty(command.ContractingPartyName)) - { - return operation.Failed("لطفا طرف حساب خودرا وارد کنید"); - } - - - if (command.SenderId < 1) - { - return operation.Failed("خطای سیستمی!!!"); - } - - var sender = _accountRepository.GetIncludePositions(command.SenderId); - - if (command.PositionId?.Count > 0 && command.ReceiverId?.Count > 0) - { - if (command.PositionId.Any(x => x > 0)) - { - return operation.Failed("شما نمیتوانید همرمان به صورت انفرادی و هم به صورت گروهی تسک دهید. "); - } - } - else if (command.PositionId?.Count > 0) - { - var res = CreateTaskByPosition(command); - return res; - } - if (command.ReceiverId.Count < 1) - { - return operation.Failed("طرف وظیفه خود را وارد کنید"); - } - - var receivers = _accountRepository.GetAccountsByIds(command.ReceiverId); - - if (sender.Position.PositionValue == 1) - { - - } - - else if (receivers.Any(x => sender.Position.PositionValue >= x.Position.PositionValue)) - { - var checkReceiver = receivers.Where(x => sender.Position.PositionValue >= x.Position.PositionValue).ToList(); - if (checkReceiver.All(x => x.id == sender.id)) - { - - } - else - { - return operation.Failed("شما نمیتوانید به سطح بالاتر خود یا هم سطح خود وظیفه ای دهید"); - } - - } - else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id)) - { - - } - - - var endTask = string.IsNullOrWhiteSpace(command.EndTaskTime) || command.EndTaskTime=="00:00" ? command.EndTaskDate.ToGeorgianDateTime2() : command.EndTaskDate.ToGeorgianDateWithTime(command.EndTaskTime); - - var errorDateTime = new DateTime(3000, 12, 20, new PersianCalendar()); - if (endTask == errorDateTime) - { - return operation.Failed("لطفا تاریخ را به درستی وارد کنید"); - } - - var task = new Tasks(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName); - _taskRepository.Create(task); - _assignRepository.SaveChanges(); - foreach (var receiver in receivers) - { - var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, receiver.Fullname, - receiver.Position.PositionValue); - _assignRepository.Create(assign); - } - - - - #region SaveMedias - - #region SaveDocuments - - if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000) - || (command.Document5?.Length > 5000000) || (command.Document6?.Length > 5000000)) - return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد"); - - if (command.Document1?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document1.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document1.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document2?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document2.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document2.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document3?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document3.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document3.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document4?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document4.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document4.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document5?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document5.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document5.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document6?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document6.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document6.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - - - - #endregion - - - - if (command.Voice?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Voice.FileName); - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Voice.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "صوت"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - } - - - - #endregion - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } - - public OperationResult CreateTaskByPosition(CreateTask command) - { - var operation = new OperationResult(); - var sender = _accountRepository.GetIncludePositions(command.SenderId); - - var receivers = _positionRepository.GetAccountsByIds(command.PositionId); - - - if (sender.Position.PositionValue == 1) - { - - } - else if (receivers.Any(x => sender.Position.PositionValue > x.Position.PositionValue)) - { - return operation.Failed("شما نمیتوانید به سطح بالاتر خود وظیفه ای دهید"); - } - else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id)) - { - - } - else if (receivers.Any(x => sender.Position.PositionValue == x.Position.PositionValue)) - { - return operation.Failed("شما نمیتوانید به هم سطح خود وظیفه ای دهید"); - } - - - DateTime endTask; - if (string.IsNullOrWhiteSpace(command.EndTaskTime)) - { - endTask = command.EndTaskDate.ToGeorgianDateTime2(); - } - else - { - endTask = command.EndTaskDate.ToGeorgianDateWithTime(command.EndTaskTime); - } - - - - var task = new Tasks(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName); - _taskRepository.Create(task); - _assignRepository.SaveChanges(); - foreach (var receiver in receivers) - { - var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, receiver.Fullname, - receiver.Position.PositionValue); - _assignRepository.Create(assign); - } - - - - #region SaveMedias - - #region SaveDocuments - - if ((command.Document1?.Length > 2000000) || (command.Document2?.Length > 2000000) || (command.Document3?.Length > 2000000)) - return operation.Failed("حجم فایل نمیتواند از 2 مگابایت بیشتر باشد"); - - if (command.Document1?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", "Task", $"{task.id}"); - Directory.CreateDirectory(path); + Directory.CreateDirectory(path); - string filepath = Path.Combine(path, command.Document1.FileName); - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document1.CopyTo(stream); + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, media.Category); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); } - if (command.Document2?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); + - string filepath = Path.Combine(path, command.Document2.FileName); + #endregion - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document2.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document3?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document3.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document3.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document4?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document4.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document4.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document5?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document5.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document5.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document6?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document6.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document6.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } + if (command.UploadedVoiceMedia > 0) + { + var media = _mediaRepository.Get(command.UploadedVoiceMedia); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "Task", $"{task.id}"); + Directory.CreateDirectory(path); - #endregion + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, "صوت"); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); + + } + + #endregion + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + + public OperationResult CreateTaskByPosition(CreateTask command) + { + var operation = new OperationResult(); + var sender = _accountRepository.GetIncludePositions(command.SenderId); + + var receivers = _positionRepository.GetAccountsByIds(command.PositionId); + + + if (sender.Position.PositionValue == 1) + { + + } + else if (receivers.Any(x => sender.Position.PositionValue > x.Position.PositionValue)) + { + return operation.Failed("شما نمیتوانید به سطح بالاتر خود وظیفه ای دهید"); + } + else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id)) + { + + } - if (command.Voice?.Length > 0) - { - var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Voice.FileName); - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Voice.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "صوت"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - - } + DateTime endTask; + if (string.IsNullOrWhiteSpace(command.EndTaskTime)) + { + endTask = command.EndTaskDate.ToGeorgianDateTime2(); + } + else + { + endTask = command.EndTaskDate.ToGeorgianDateWithTime(command.EndTaskTime); + } - #endregion - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } - - // ویرایش تسک - public EditTask GetDetails(long taskId) - { - return _taskRepository.GetDetails(taskId); - } - - //لیست کامل تسک ها - public List GetTasks(TaskSearchModel searchModel) - { - var test = _taskRepository.GetTasks(searchModel); - - return test; - } - - public List GetSelfTasks(TaskSearchModel searchModel) - { - return _taskRepository.GetSelfTasks(searchModel); - } - - public List GetAllNotSelfIncludedTasks(TaskSearchModel searchModel) - { - return _taskRepository.GetAllNotSelfIncludedTasks(searchModel); - } - - public List GetReceivedTasks(TaskSearchModel searchModel) - { - return _taskRepository.GetReceivedTasks(searchModel); - } - - public List GetSentTasks(TaskSearchModel searchModel) - { - return _taskRepository.GetSentTasks(searchModel); - } - - //ساخت درخواست مهلت - public OperationResult CreateRequestTime(CreateTaskTimeRequest command) - { - var accountId = _authHelper.CurrentAccountId(); - var operation = new OperationResult(); - if (command.TaskId == 0) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - - if (string.IsNullOrWhiteSpace(command.Description)) - { - return operation.Failed("توضیحات خود را وارد کنید"); - } - - if (string.IsNullOrWhiteSpace(command.RequestTime)) - { - return operation.Failed("مهلت درخواستی خود را وارد کنید"); - } - - - var task = _taskRepository.Get(command.TaskId); - var requestTime = command.RequestTime.ToGeorgianDateTime(); - var errorDateTime = new DateTime(3000, 12, 20, new PersianCalendar()); - if (requestTime == errorDateTime) - { - return operation.Failed("لطفا تاریخ را به درستی وارد کنید"); - } - if (task.SenderId==accountId) - { - task.ChangeTimeTask(requestTime); - } - else - { - task.CreateTimeRequest(requestTime, command.Description); - } - - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } - //تایید درخواست مهلت - public OperationResult AcceptRequestDatetime(long taskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == taskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - - var task = _taskRepository.Get(taskId); - if (!task.TimeRequest) - { - return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد"); - } - - if (task.RequestDate == null) - { - return operation.Failed("تاریخی برای درخواست وظیفه ثبت نشده است"); - } - task.AcceptTimeRequest(); - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } - //ساخت درخواست کنسل - public OperationResult CreateCancelRequest(CreateTaskCancel command) - { - var accountId = _authHelper.CurrentAccountId(); - var operation = new OperationResult(); - if (string.IsNullOrWhiteSpace(command.Description)) - { - return operation.Failed("توضیحات خود را وارد کنید"); - } - - if (!_taskRepository.Exists(x => x.id == command.TaskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - var task = _taskRepository.Get(command.TaskId); - task.CreateCancelRequest(command.Description); - if (task.SenderId==accountId) - { - task.AcceptCancelRequest(); - } - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } - //تایید درخواست کنسل - public OperationResult AcceptCancelRequest(long taskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == taskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - var task = _taskRepository.Get(taskId); - if (!task.IsCanceledRequest) - { - return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد"); - } - task.AcceptCancelRequest(); - _taskRepository.SaveChanges(); - return operation.Succcedded(taskId); - } - //انجام شدن تسک - public OperationResult CreateCompleteTaskRequest(CompleteTaskViewModel command) - { - var accountId = _authHelper.CurrentAccountId(); - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == command.Id)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - var task = _taskRepository.Get(command.Id); - task.CompleteRequest(command.Description); - if (task.SenderId==accountId) - { - task.Completed(); - } - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } - - public OperationResult AcceptCompleteRequest(long taskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == taskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - var task = _taskRepository.Get(taskId); - if (!task.IsDoneRequest) - { - return operation.Failed("چنین وظیفه ای درخواستی برای تایید ندارد"); - } - task.Completed(); - _taskRepository.SaveChanges(); - return operation.Succcedded(taskId); - } - - public OperationResult RejectCompleteRequest(long taskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == taskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - var task = _taskRepository.Get(taskId); - if (!task.IsDoneRequest) - { - return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد"); - } - task.RejectCompleteRequest(); - _taskRepository.SaveChanges(); - return operation.Succcedded(taskId); - } - - //لغو درخواست کنسل تسک - public OperationResult RejectCancelRequest(long taskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == taskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - var task = _taskRepository.Get(taskId); - if (!task.IsCanceledRequest) - { - return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد"); - } - task.RejectCancel(); - _taskRepository.SaveChanges(); - return operation.Succcedded(taskId); - } - //لغو درخواست مهلت تسک - public OperationResult RejectTimeRequest(long taskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == taskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - - var task = _taskRepository.Get(taskId); - if (!task.TimeRequest) - { - return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد"); - } - task.RejectTimeRequest(); - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } - - public OperationResult CreateTaskByPosition(CreateTask command, List positionIds) - { - var operation = new OperationResult(); - var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); - var positions = new List(); - foreach (var positionId in positionIds) - { - var position = _positionRepository.Get(positionId); - positions.Add(position); - } + var task = new Tasks(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName); + _taskRepository.Create(task); + _assignRepository.SaveChanges(); + foreach (var receiver in receivers) + { + var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, receiver.Fullname, + receiver.Position.PositionValue); + _assignRepository.Create(assign); + } - if (positions.Any(x => x.PositionValue <= positionValue)) - { - return operation.Failed("شما نمیتوانید به گروه هم سطح یا سطح بالاتر خود تسکی دهد"); - } - var receiverIds = new List(); - foreach (var positionId in positionIds) - { - var acc = _accountRepository.GetAccountsByPositionId(positionId).Select(x => x.Id).ToList(); - receiverIds.AddRange(acc); - } + #region SaveMedias - command.ReceiverId = receiverIds; - operation = CreateTask(command); - return operation; - } + #region SaveDocuments - public List GetAllRequestedTasks(TaskSearchModel searchModel) - { - return _taskRepository.GetAllRequestedTasks(searchModel); - } + foreach (var mediaId in command.UploadedMedia) + { + var media = _mediaRepository.Get(mediaId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "Task", $"{task.id}"); + Directory.CreateDirectory(path); - public int GetRequestedTasksCount() - { - return _taskRepository.GetRequestedTasksCount(); - } - public OperationResult ChangeRequestTimeAndAccept(string time, long taskId) - { - var operation = new OperationResult(); - if (!_taskRepository.Exists(x => x.id == taskId)) - { - return operation.Failed("چنین وظیفه ای وجود ندارد"); - } - var task = _taskRepository.Get(taskId); - if (!task.TimeRequest) - { - return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد"); - } + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); - if (task.RequestDate == null) - { - return operation.Failed("تاریخی برای درخواست وظیفه ثبت نشده است"); - } + media.Edit(filepath, media.Type, media.Category); - DateTime timeGr = time.ToGeorgianDateTime2(); - task.ChangeTimeTask(timeGr); - _taskRepository.SaveChanges(); - return operation.Succcedded(task.id); - } + _mediaRepository.SaveChanges(); + _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); + } - public TaskViewModel GetRequestDetails(long id) - { - return _taskRepository.GetRequestDetails(id); - } + #endregion + + if (command.UploadedVoiceMedia > 0) + { + var media = _mediaRepository.Get(command.UploadedVoiceMedia); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "Task", $"{task.id}"); + Directory.CreateDirectory(path); + + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, "صوت"); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); + + } + + #endregion + + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + + // ویرایش تسک + public EditTask GetDetails(long taskId) + { + return _taskRepository.GetDetails(taskId); + } + + //لیست کامل تسک ها + public List GetTasks(TaskSearchModel searchModel) + { + var test = _taskRepository.GetTasks(searchModel); + + return test; + } + + public List GetSelfTasks(TaskSearchModel searchModel) + { + return _taskRepository.GetSelfTasks(searchModel); + } + + public List GetAllNotSelfIncludedTasks(TaskSearchModel searchModel) + { + return _taskRepository.GetAllNotSelfIncludedTasks(searchModel); + } + + public List GetReceivedTasks(TaskSearchModel searchModel) + { + return _taskRepository.GetReceivedTasks(searchModel); + } + + public List GetSentTasks(TaskSearchModel searchModel) + { + return _taskRepository.GetSentTasks(searchModel); + } + + //ساخت درخواست مهلت + public OperationResult CreateRequestTime(CreateTaskTimeRequest command) + { + var accountId = _authHelper.CurrentAccountId(); + var operation = new OperationResult(); + if (command.TaskId == 0) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + + if (string.IsNullOrWhiteSpace(command.Description)) + { + return operation.Failed("توضیحات خود را وارد کنید"); + } + + if (string.IsNullOrWhiteSpace(command.RequestTime)) + { + return operation.Failed("مهلت درخواستی خود را وارد کنید"); + } + + + var task = _taskRepository.Get(command.TaskId); + var requestTime = command.RequestTime.ToGeorgianDateTime(); + var errorDateTime = new DateTime(3000, 12, 20, new PersianCalendar()); + if (requestTime == errorDateTime) + { + return operation.Failed("لطفا تاریخ را به درستی وارد کنید"); + } + if (task.SenderId == accountId) + { + task.ChangeTimeTask(requestTime); + } + else + { + task.CreateTimeRequest(requestTime, command.Description); + } + + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + //تایید درخواست مهلت + public OperationResult AcceptRequestDatetime(long taskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == taskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + + var task = _taskRepository.Get(taskId); + if (!task.TimeRequest) + { + return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد"); + } + + if (task.RequestDate == null) + { + return operation.Failed("تاریخی برای درخواست وظیفه ثبت نشده است"); + } + task.AcceptTimeRequest(); + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + //ساخت درخواست کنسل + public OperationResult CreateCancelRequest(CreateTaskCancel command) + { + var accountId = _authHelper.CurrentAccountId(); + var operation = new OperationResult(); + if (string.IsNullOrWhiteSpace(command.Description)) + { + return operation.Failed("توضیحات خود را وارد کنید"); + } + + if (!_taskRepository.Exists(x => x.id == command.TaskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + var task = _taskRepository.Get(command.TaskId); + task.CreateCancelRequest(command.Description); + if (task.SenderId == accountId) + { + task.AcceptCancelRequest(); + } + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + //تایید درخواست کنسل + public OperationResult AcceptCancelRequest(long taskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == taskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + var task = _taskRepository.Get(taskId); + if (!task.IsCanceledRequest) + { + return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد"); + } + task.AcceptCancelRequest(); + _taskRepository.SaveChanges(); + return operation.Succcedded(taskId); + } + //انجام شدن تسک + public OperationResult CreateCompleteTaskRequest(CompleteTaskViewModel command) + { + var accountId = _authHelper.CurrentAccountId(); + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == command.Id)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + var task = _taskRepository.Get(command.Id); + task.CompleteRequest(command.Description); + if (task.SenderId == accountId) + { + task.Completed(); + } + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + + public OperationResult AcceptCompleteRequest(long taskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == taskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + var task = _taskRepository.Get(taskId); + if (!task.IsDoneRequest) + { + return operation.Failed("چنین وظیفه ای درخواستی برای تایید ندارد"); + } + task.Completed(); + _taskRepository.SaveChanges(); + return operation.Succcedded(taskId); + } + + public OperationResult RejectCompleteRequest(long taskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == taskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + var task = _taskRepository.Get(taskId); + if (!task.IsDoneRequest) + { + return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد"); + } + task.RejectCompleteRequest(); + _taskRepository.SaveChanges(); + return operation.Succcedded(taskId); + } + + //لغو درخواست کنسل تسک + public OperationResult RejectCancelRequest(long taskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == taskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + var task = _taskRepository.Get(taskId); + if (!task.IsCanceledRequest) + { + return operation.Failed("چنین وظیفه ای درخواستی برای انصراف ندارد"); + } + task.RejectCancel(); + _taskRepository.SaveChanges(); + return operation.Succcedded(taskId); + } + //لغو درخواست مهلت تسک + public OperationResult RejectTimeRequest(long taskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == taskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + + var task = _taskRepository.Get(taskId); + if (!task.TimeRequest) + { + return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد"); + } + task.RejectTimeRequest(); + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + + public OperationResult CreateTaskByPosition(CreateTask command, List positionIds) + { + var operation = new OperationResult(); + var positionValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); + var positions = new List(); + foreach (var positionId in positionIds) + { + var position = _positionRepository.Get(positionId); + positions.Add(position); + } + + + if (positions.Any(x => x.PositionValue < positionValue)) + { + return operation.Failed("شما نمیتوانید به سطح بالاتر خود تسکی دهد"); + } + + var receiverIds = new List(); + foreach (var positionId in positionIds) + { + var acc = _accountRepository.GetAccountsByPositionId(positionId).Select(x => x.Id).ToList(); + receiverIds.AddRange(acc); + } + + command.ReceiverId = receiverIds; + operation = CreateTask(command); + return operation; + } + + public List GetRequestedTasks(TaskSearchModel searchModel) + { + return _taskRepository.GetRequestedTasks(searchModel); + } + + public List AllRequestedTasks(TaskSearchModel searchModel) + { + return _taskRepository.AllRequestedTasks(searchModel); + } + + public int GetRequestedTasksCount() + { + return _taskRepository.GetRequestedTasksCount(); + } + + public OperationResult ChangeRequestTimeAndAccept(string time, long taskId) + { + var operation = new OperationResult(); + if (!_taskRepository.Exists(x => x.id == taskId)) + { + return operation.Failed("چنین وظیفه ای وجود ندارد"); + } + + var task = _taskRepository.Get(taskId); + if (!task.TimeRequest) + { + return operation.Failed("چنین وظیفه ای درخواستی برای مهلت ندارد"); + } + + if (task.RequestDate == null) + { + return operation.Failed("تاریخی برای درخواست وظیفه ثبت نشده است"); + } + + DateTime timeGr = time.ToGeorgianDateTime2(); + task.ChangeTimeTask(timeGr); + _taskRepository.SaveChanges(); + return operation.Succcedded(task.id); + } + + public TaskViewModel GetRequestDetails(long id) + { + return _taskRepository.GetRequestDetails(id); + } + public OperationResult UploadMedia(IFormFile mediaFile, long senderId) + { + var operation = new OperationResult(); + if ((mediaFile.Length > 2000000) || (mediaFile.Length > 2000000) || (mediaFile.Length > 2000000)) + return operation.Failed("حجم فایل نمیتواند از 2 مگابایت بیشتر باشد"); + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "temp", $"{senderId}"); + Directory.CreateDirectory(path); + + string uniqueFileName = $"{Path.GetFileNameWithoutExtension(mediaFile.FileName)}_{DateTime.Now.Ticks}{Path.GetExtension(mediaFile.FileName)}"; + string filepath = Path.Combine(path, uniqueFileName); + + using (var stream = new FileStream(filepath, FileMode.Create)) + { + mediaFile.CopyTo(stream); + + } + var type = Path.GetExtension(filepath); + var media = new Media(filepath, type, "فایل"); + _mediaRepository.Create(media); + _mediaRepository.SaveChanges(); + return operation.Succcedded(media.id); + + } + + public OperationResult RemoveMedia(long mediaId) + { + var operation = new OperationResult(); + try + { + var media = _mediaRepository.Get(mediaId); + var path = media.Path; + if (File.Exists(path)) + { + File.Delete(path); + } + _mediaRepository.Remove(mediaId); + return operation.Succcedded(); + } + catch + { + return operation.Failed("مشکلی در حذف این فایل وجود دارد"); + } + + } + + public void RemoveTempUploadedFiles(long userId) + { + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "temp", $"{userId}"); + + + if (Directory.Exists(path)) + { + + Directory.Delete(path, true); + } + + } } \ No newline at end of file diff --git a/AccountManagement.Application/TicketApplication.cs b/AccountManagement.Application/TicketApplication.cs index 38b42ae5..bb665d9d 100644 --- a/AccountManagement.Application/TicketApplication.cs +++ b/AccountManagement.Application/TicketApplication.cs @@ -13,6 +13,7 @@ using AccountManagement.Domain.ClientResponseAgg; using AccountManagement.Domain.MediaAgg; using AccountManagement.Domain.TaskAgg; using AccountManagement.Domain.TicketAgg; +using Microsoft.AspNetCore.Hosting; namespace AccountManagement.Application; @@ -59,117 +60,41 @@ public class TicketApplication : ITicketApplication _ticketRepository.SaveChanges(); #region SaveDocuments - if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000) - || (command.Document5?.Length > 5000000)) - return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد"); - - if (command.Document1?.Length > 0) + if (command.UploadedMediaIds?.Count>0) { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Ticket", $"{ticket.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document1.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) + foreach (var mediaId in command.UploadedMediaIds) { - command.Document1.CopyTo(stream); + var media = _mediaRepository.Get(mediaId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "Ticket", $"{ticket.id}"); + Directory.CreateDirectory(path); + + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, media.Category); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateTicketMedia(ticket.id, media.id); } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateTicketMedia(ticket.id, media.id); } - if (command.Document2?.Length > 0) + if (command.ScreenShotId > 0) { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", + var media = _mediaRepository.Get(command.ScreenShotId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", "Ticket", $"{ticket.id}"); Directory.CreateDirectory(path); - string filepath = Path.Combine(path, command.Document2.FileName); + string filepath = Path.Combine(path, Path.GetFileName(path)); + File.Move(oldPath, filepath); - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document2.CopyTo(stream); - } - var type = Path.GetExtension(filepath); + media.Edit(filepath, media.Type, media.Category); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateTicketMedia(ticket.id, media.id); - } - if (command.Document3?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Ticket", $"{ticket.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document3.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document3.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateTicketMedia(ticket.id, media.id); - } - if (command.Document4?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Ticket", $"{ticket.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document4.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document4.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateTicketMedia(ticket.id, media.id); - } - if (command.Document5?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Ticket", $"{ticket.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document5.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document5.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateTicketMedia(ticket.id, media.id); - } - if (command.ScreenShot?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Ticket", $"{ticket.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.ScreenShot.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.ScreenShot.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); _mediaRepository.SaveChanges(); _mediaRepository.CreateTicketMedia(ticket.id, media.id); } @@ -178,22 +103,19 @@ public class TicketApplication : ITicketApplication #endregion #region SaveVoice - if (command.Voice?.Length > 0) + if (command.VoiceId > 0) { - - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", + var media = _mediaRepository.Get(command.ScreenShotId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", "Ticket", $"{ticket.id}"); Directory.CreateDirectory(path); - string filepath = Path.Combine(path, command.Voice.FileName); + string filepath = Path.Combine(path, Path.GetFileName(path)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, "صوت"); - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Voice.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); _mediaRepository.SaveChanges(); _mediaRepository.CreateTicketMedia(ticket.id, media.id); @@ -279,160 +201,52 @@ public class TicketApplication : ITicketApplication #region SaveDocuments - if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000) - || (command.Document5?.Length > 5000000) || (command.Document6?.Length > 5000000)) - return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد"); - - - if (command.Document1?.Length > 0) + if (command.UploadedMedia?.Count>0) { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document1.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) + foreach (var mediaId in command.UploadedMedia) { - command.Document1.CopyTo(stream); + var media = _mediaRepository.Get(mediaId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "Task", $"{task.id}"); + Directory.CreateDirectory(path); + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, media.Category); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); + } - if (command.Document2?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document2.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document2.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document3?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document3.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document3.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document4?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document4.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document4.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document5?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document5.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document5.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - if (command.Document6?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "Task", $"{task.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document6.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document6.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); - } - - - #endregion - #region SaveVoice - if (command.Voice?.Length > 0) + + if (command.UploadedVoiceMedia > 0) { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", + var media = _mediaRepository.Get(command.UploadedVoiceMedia); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", "Task", $"{task.id}"); Directory.CreateDirectory(path); - string filepath = Path.Combine(path, command.Voice.FileName); - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Voice.CopyTo(stream); - } - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "صوت"); - _mediaRepository.Create(media); + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, "صوت"); + _mediaRepository.SaveChanges(); _mediaRepository.CreateMediaWithTaskMedia(task.id, media.id); } #endregion + - - - - #endregion _taskRepository.SaveChanges(); return operation.Succcedded(task.id); @@ -465,138 +279,30 @@ public class TicketApplication : ITicketApplication #region SaveDocuments - if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000) - || (command.Document5?.Length > 5000000) || (command.Document6?.Length > 5000000)) - return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد"); - - - if (command.Document1?.Length > 0) + if (command.UploadedFileIds?.Count>0) { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketAdminResponse", $"{adminRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document1.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) + foreach (var mediaId in command.UploadedFileIds) { - command.Document1.CopyTo(stream); + var media = _mediaRepository.Get(mediaId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "TicketAdminResponse", $"{adminRes.id}"); + Directory.CreateDirectory(path); + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, media.Category); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id); } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id); - } - if (command.Document2?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketAdminResponse", $"{adminRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document2.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document2.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id); - } - if (command.Document3?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketAdminResponse", $"{adminRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document3.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document3.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id); - } - if (command.Document4?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketAdminResponse", $"{adminRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document4.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document4.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id); - } - if (command.Document5?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketAdminResponse", $"{adminRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document5.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document5.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id); - } - - if (command.Document6?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", - "Storage", - "TicketAdminResponse", $"{adminRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document6.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document6.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id); - - } #endregion - _mediaRepository.SaveChanges(); + _mediaRepository.SaveChanges(); return operation.Succcedded(adminRes.id); @@ -615,135 +321,26 @@ public class TicketApplication : ITicketApplication _ticketRepository.SaveChanges(); #region SaveDocuments - if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000) - || (command.Document5?.Length > 5000000) || (command.Document6?.Length > 5000000)) - return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد"); - - - if (command.Document1?.Length > 0) + if (command.UploadedFileIds?.Count>0) { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketClientResponse", $"{clientRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document1.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) + foreach (var mediaId in command.UploadedFileIds) { - command.Document1.CopyTo(stream); + var media = _mediaRepository.Get(mediaId); + var oldPath = media.Path; + var path = Path.Combine($"{_taskRepository.GetWebEnvironmentPath()}", "Storage", + "TicketClientResponse", $"{clientRes.id}"); + Directory.CreateDirectory(path); + + + string filepath = Path.Combine(path, Path.GetFileName(oldPath)); + File.Move(oldPath, filepath); + + media.Edit(filepath, media.Type, media.Category); + + _mediaRepository.SaveChanges(); + _mediaRepository.CreateClientResponseMedia(clientRes.id, media.id); } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateClientResponseMedia(clientRes.id, media.id); - - } - if (command.Document2?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketClientResponse", $"{clientRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document2.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document2.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateClientResponseMedia(clientRes.id, media.id); - } - if (command.Document3?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketClientResponse", $"{clientRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document3.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document3.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateClientResponseMedia(clientRes.id, media.id); - } - if (command.Document4?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketClientResponse", $"{clientRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document4.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document4.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateClientResponseMedia(clientRes.id, media.id); - } - if (command.Document5?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage", - "TicketClientResponse", $"{clientRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document5.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document5.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateClientResponseMedia(clientRes.id, media.id); - } - - if (command.Document6?.Length > 0) - { - var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", - "Storage", - "TicketClientResponse", $"{clientRes.id}"); - Directory.CreateDirectory(path); - - string filepath = Path.Combine(path, command.Document6.FileName); - - using (var stream = new FileStream(filepath, FileMode.Create)) - { - command.Document6.CopyTo(stream); - - } - - var type = Path.GetExtension(filepath); - var media = new Media(filepath, type, "فایل"); - _mediaRepository.Create(media); - _mediaRepository.SaveChanges(); - _mediaRepository.CreateClientResponseMedia(clientRes.id, media.id); - - } #endregion diff --git a/AccountManagement.Domain/MediaAgg/Media.cs b/AccountManagement.Domain/MediaAgg/Media.cs index 9adca572..d1ce763f 100644 --- a/AccountManagement.Domain/MediaAgg/Media.cs +++ b/AccountManagement.Domain/MediaAgg/Media.cs @@ -7,27 +7,35 @@ using AccountManagement.Domain.TicketMediasAgg; namespace AccountManagement.Domain.MediaAgg; -public class Media:EntityBase +public class Media : EntityBase { - public Media( string path, string type, string category) + public Media(string path, string type, string category) { - + Path = path; Type = type; Category = category; } - + //مسیر ذخیره فایل public string Path { get; private set; } - + //نوع ذخیره فایل public string Type { get; private set; } //دسته بندی ذخیره فایل - public string Category { get; set; } + public string Category { get; private set; } public List TaskMedias { get; set; } public List AdminResponseMedias { get; set; } public List ClientResponseMedias { get; set; } public List TicketMedias { get; set; } + + public void Edit(string path, string type, string category) + { + Path = path; + Type = type; + Category = category; + } + } \ No newline at end of file diff --git a/AccountManagement.Domain/TaskAgg/ITaskRepository.cs b/AccountManagement.Domain/TaskAgg/ITaskRepository.cs index 4d8469b6..571c7f6e 100644 --- a/AccountManagement.Domain/TaskAgg/ITaskRepository.cs +++ b/AccountManagement.Domain/TaskAgg/ITaskRepository.cs @@ -11,17 +11,15 @@ public interface ITaskRepository:IRepository void Remove(long id); //گرفتن تمامی وظایف List GetTasks(TaskSearchModel searchModel); - List GetAllRequestedTasks(TaskSearchModel searchModel); + List GetRequestedTasks(TaskSearchModel searchModel); List GetSelfTasks(TaskSearchModel searchModel); List GetAllNotSelfIncludedTasks(TaskSearchModel searchModel); List GetReceivedTasks(TaskSearchModel searchModel); List GetSentTasks(TaskSearchModel searchModel); + List AllRequestedTasks(TaskSearchModel searchModel); string SetTasksColors(DateTime time,bool isCancel); int GetRequestedTasksCount(); TaskViewModel GetRequestDetails(long id); - - - - + string GetWebEnvironmentPath(); } \ No newline at end of file diff --git a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs index eb2f76b2..df1839c3 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs @@ -217,7 +217,7 @@ public class AccountRepository : RepositoryBase, IAccountReposito var account = GetIncludePositions(int.Parse(_contextAccessor.HttpContext.User.FindFirst("AccountId").Value)); return _context.Accounts.Include(x => x.Position) - .Where(x => x.Position.PositionValue > account.Position.PositionValue && x.IsActiveString == "true").Select(x => new AccountViewModel() + .Where(x => x.Position.PositionValue >= account.Position.PositionValue && x.IsActiveString == "true").Select(x => new AccountViewModel() { PositionValue = x.Position.PositionValue, Id = x.id, diff --git a/AccountMangement.Infrastructure.EFCore/Repository/PositionRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/PositionRepository.cs index 844fab90..b50e3ff1 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/PositionRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/PositionRepository.cs @@ -42,15 +42,11 @@ public class PositionRepository : RepositoryBase, IPositionRepos public List GetLowerPosition() { var posValue = int.Parse(_contextAccessor.HttpContext.User.FindFirst("PositionValue").Value); - return _accountContext.Positions.Where(x => x.PositionValue > posValue).Select(x => new PositionViewModel() + return _accountContext.Positions.Where(x => x.PositionValue >= posValue).Select(x => new PositionViewModel() { Value = x.PositionValue, Id = x.id, Name = x.PositionName - - - - }).OrderBy(x => x.Value).ToList(); } diff --git a/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs index 6711fecc..30a588b0 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/TaskRepository.cs @@ -15,6 +15,7 @@ using TaskManager.Domain.PositionAgg; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; using Microsoft.Identity.Client; using Newtonsoft.Json.Linq; +using Microsoft.AspNetCore.Hosting; namespace AccountMangement.Infrastructure.EFCore.Repository; @@ -24,14 +25,16 @@ public class TaskRepository : RepositoryBase, ITaskRepository private readonly IHttpContextAccessor _contextAccessor; private readonly IAccountRepository _accountRepository; public readonly IPositionRepository _PositionRepository; + private readonly IWebHostEnvironment _webHostEnvironment; public TaskRepository(IHttpContextAccessor contextAccessor, AccountContext accountContext, - IAccountRepository accountRepository, IPositionRepository positionRepository) : base(accountContext) + IAccountRepository accountRepository, IPositionRepository positionRepository, IWebHostEnvironment webHostEnvironment) : base(accountContext) { _contextAccessor = contextAccessor; _accountContext = accountContext; _accountRepository = accountRepository; _PositionRepository = positionRepository; + _webHostEnvironment = webHostEnvironment; } public EditTask GetDetails(long TaskId) @@ -69,7 +72,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository - public List GetAllRequestedTasks(TaskSearchModel searchModel) + 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); @@ -84,7 +87,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository { query = _accountContext.Assigns.Include(x => x.Task).Where(x => x.Task.IsDone == false && x.Task.IsActiveString == "true" && - (x.Task.IsCanceledRequest == true || x.Task.TimeRequest == true || x.Task.IsDoneRequest)).Select(x => + (x.Task.IsCanceledRequest == true || x.Task.TimeRequest == true || x.Task.IsDoneRequest) && accountId == x.Task.SenderId).Select(x => new TaskViewModel() { @@ -113,7 +116,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository { query = _accountContext.Assigns.Include(x => x.Task).Where(x => !x.Task.IsDone && x.Task.IsActiveString == "true" && - (x.Task.IsCanceledRequest || x.Task.TimeRequest || x.Task.IsDoneRequest) && (accountId == x.Task.SenderId || positionValue < x.AssignerPositionValue)).Select(x => + (x.Task.IsCanceledRequest || x.Task.TimeRequest || x.Task.IsDoneRequest) && (accountId == x.Task.SenderId || x.AssignedId == accountId)).Select(x => new TaskViewModel() { @@ -160,12 +163,10 @@ public class TaskRepository : RepositoryBase, ITaskRepository SelfName = _accountContext.Accounts.FirstOrDefault(a => a.id == accountId).Fullname, - Assigned = - x.AssignedId == accountId ? - ExtraTools.AddAccountIdToList(_accountContext.Assigns.Where(a => a.TaskId == x.Id && a.AssignerId == accountId).Select(a => a.AssignedId).ToList(), accountId) : _accountContext.Assigns.Where(a => a.TaskId == x.Id) - .Where(x => x.AssignedPositionValue > positionValue).Select(a => a.AssignedId) - .ToList(), - CreateDate = x.CreateDate, + 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, @@ -256,7 +257,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository var AddAssign = finalList.Select(x => new TaskViewModel() { - AssignViewModels = _accountContext.Accounts.Include(x => x.Position).Where(a => x.Assigned.Contains(a.id)) + AssignViewModels = _accountContext.Accounts.Include(x => x.Position).Where(a => x.Assigned.Contains(a.id) && accountId != a.id) .Select(a => new AssignViewModel() { AssignedName = a.Fullname, @@ -294,12 +295,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository var finalAssign = AddAssign.Select(x => new TaskViewModel() { - AssignList = !x.SelfAssigned && !x.SelfAssigner ? x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() - { - AssignViewModels = a.ToList(), - PosValue = a.Key - }).ToList() - : x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() + AssignList = x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() { AssignViewModels = a.ToList(), PosValue = a.Key @@ -382,7 +378,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository { query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias).ThenInclude(x => x.Media) .Where(x => - x.Task.IsActiveString == "true" && (!x.Task.IsCanceledRequest || !x.Task.TimeRequest || !x.Task.IsDoneRequest)) + x.Task.IsActiveString == "true" && (!x.Task.IsCanceledRequest && !x.Task.TimeRequest && !x.Task.IsDoneRequest)) .Select(x => new TaskViewModel() { @@ -412,7 +408,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository { 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) && (!x.Task.IsCanceledRequest || !x.Task.TimeRequest || !x.Task.IsDoneRequest)) + x.Task.IsActiveString == "true" && (x.AssignedId == accountId || x.AssignerId == accountId) && (!x.Task.IsCanceledRequest && !x.Task.TimeRequest && !x.Task.IsDoneRequest)) .Select(x => new TaskViewModel() { @@ -442,230 +438,216 @@ public class TaskRepository : RepositoryBase, ITaskRepository //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)) + var res = query.Select(x => new TaskViewModel() { - query = query.Where(x => - (x.Description != null && x.Description.Contains(searchModel.GeneralSearch)) - || x.ContractingPartyName.Contains(searchModel.GeneralSearch) - || x.Name.Contains(searchModel.GeneralSearch)); + 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))); } - 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), + if (!string.IsNullOrWhiteSpace(searchModel.IsDoneRequest)) + { + bool isDoneReq = bool.Parse(searchModel.IsDoneRequest); + res = res.Where(x => x.IsDoneRequest == isDoneReq); + } - SelfName = _accountContext.Accounts.FirstOrDefault(a => a.id == accountId).Fullname, + if (!string.IsNullOrWhiteSpace(searchModel.IsDone)) + { + bool isDone = bool.Parse(searchModel.IsDone); + res = res.Where(x => x.IsDone == isDone); + } - Assigned = - x.AssignedId == accountId ? - ExtraTools.AddAccountIdToList(_accountContext.Assigns.Where(a => a.TaskId == x.Id && a.AssignerId == accountId).Select(a => a.AssignedId).ToList(), accountId) : _accountContext.Assigns.Where(a => a.TaskId == x.Id) - .Where(x => x.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) && + if (!string.IsNullOrWhiteSpace(searchModel.IsCanceled)) + { + bool isCancel = bool.Parse(searchModel.IsCanceled); + res = res.Where(x => x.IsCancel == isCancel); + } - (end > x.EndTaskDateGE && x.EndTaskDateGE > start)) - || ((start < x.CreateTaskDateGE && x.CreateTaskDateGE < end) && + if (!string.IsNullOrWhiteSpace(searchModel.IsTimeRequest)) + { + bool isTimeRequest = bool.Parse(searchModel.IsTimeRequest); + res = res.Where(x => x.RequestTime == isTimeRequest); + } - (end < x.EndTaskDateGE && x.EndTaskDateGE > start)) - || ((start < x.CreateTaskDateGE && x.CreateTaskDateGE < end) && + if (!string.IsNullOrWhiteSpace(searchModel.TimeRequestAccepted)) + { + res = res.Where(x => x.AcceptedTimeRequest > 0); + } - (end > x.EndTaskDateGE && x.EndTaskDateGE > start)) - || ((start > x.CreateTaskDateGE && x.CreateTaskDateGE < end) && + if (!string.IsNullOrWhiteSpace(searchModel.IsCancelRequest)) + { + bool isCancelReq = bool.Parse(searchModel.IsCancelRequest); + res = res.Where(x => x.IsCancelRequest == isCancelReq); - (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 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 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() - { - AssignViewModels = _accountContext.Accounts.Include(x => x.Position).Where(a => x.Assigned.Contains(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 + 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(); + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + final = final.Select(x => new TaskViewModel() + { - AssignList = !x.SelfAssigned && !x.SelfAssigner ? x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() - { - AssignViewModels = a.ToList(), - PosValue = a.Key - }).ToList() - : 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 = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, - SelfName = x.SelfName, - SelfAssigned = x.SelfAssigned, - SelfAssigner = x.SelfAssigner, - Description = x.Description, - IsDoneRequest = x.IsDoneRequest - }).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.IsDone ? "green" : SetTasksColors(x.EndTaskDateGE, x.IsCancel), + MediaCount = x.MediaCount, + HasAttachment = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, + SelfName = x.SelfName, + SelfAssigned = x.SelfAssigned, + SelfAssigner = x.SelfAssigner, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + 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, - Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname + 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, + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname - }).ToList(); - return final; + }).ToList(); + return final; - } + } public List GetSentTasks(TaskSearchModel searchModel) { @@ -682,7 +664,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository { 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.Task.SenderId == accountId && (!x.Task.IsCanceledRequest || !x.Task.TimeRequest || !x.Task.IsDoneRequest)) + x.Task.IsActiveString == "true" && (x.AssignerId == accountId && x.AssignedId != accountId) && x.Task.SenderId == accountId && (!x.Task.IsCanceledRequest && !x.Task.TimeRequest && !x.Task.IsDoneRequest)) .Select(x => new TaskViewModel() { @@ -739,231 +721,484 @@ public class TaskRepository : RepositoryBase, ITaskRepository } - 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.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 = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, + 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, + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname + + }).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; + + if (positionValue == 1) + { + query = _accountContext.Assigns.Include(x => x.Task).Where(x => + x.Task.IsDone == false && x.Task.IsActiveString == "true" && + (x.Task.IsCanceledRequest == true || x.Task.TimeRequest == true || x.Task.IsDoneRequest)).Select(x => + new TaskViewModel() + { + + AssignedId = x.AssignedId, + AssignerId = x.AssignerId, + CreateDate = x.Task.CreationDate.ToFarsi(), + EndTaskDateFA = x.Task.EndTaskDate.ToFarsi(), + IsDone = x.Task.IsDone, + EndTaskDateGE = x.Task.EndTaskDate, + Name = x.Task.Title, + RequestCancel = x.Task.IsCanceledRequest, + RequestTime = x.Task.TimeRequest, + Id = x.Task.id, + CreateTaskDateGE = x.Task.CreationDate, + IsCancel = x.Task.IsCancel, + AcceptedTimeRequest = x.Task.AcceptedTimeRequest, + IsCancelRequest = x.Task.IsCanceledRequest, + ContractingPartyName = x.Task.ContractingPartyName, + MediaCount = x.Task.TaskMedias.Count(m => m.TaskId == x.id), + Description = x.Task.Description, + IsDoneRequest = x.Task.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)); + } 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), + { + 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 = - x.AssignedId == accountId ? - ExtraTools.AddAccountIdToList(_accountContext.Assigns.Where(a => a.TaskId == x.Id && a.AssignerId == accountId).Select(a => a.AssignedId).ToList(), accountId) : _accountContext.Assigns.Where(a => a.TaskId == x.Id) - .Where(x => x.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) && + Assigned = _accountContext.Assigns.Where(a => a.TaskId == x.Id) + .Where(a => a.AssignedPositionValue >= positionValue).Select(a => a.AssignedId).ToList(), - (end > x.EndTaskDateGE && x.EndTaskDateGE > start)) - || ((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 > end))); - } + (end > x.EndTaskDateGE && x.EndTaskDateGE > start)) + || ((start > x.CreateTaskDateGE && x.CreateTaskDateGE < 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); - - } + (end < x.EndTaskDateGE && x.EndTaskDateGE > end))); + } - 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)); - } + 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 orderResult = result.OrderByDescending(x => x.IsCancel ? 0 : 1).ThenBy(x => x.IsDone ? 1 : 0) - .ThenBy(x => x.EndTaskDateGE); + + 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 final = orderResult.Skip(searchModel.PageIndex).Take(30).ToList(); + var orderResult = result.OrderBy(x => x.IsDone ? 1 : 0) + .ThenBy(x => x.EndTaskDateGE).ThenBy(x => x.IsCancel ? 0 : 1); + var finalList = 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)) - .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 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, - final = final.Select(x => new TaskViewModel() - { - AssignList = !x.SelfAssigned && !x.SelfAssigner ? x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() - { - AssignViewModels = a.ToList(), - PosValue = a.Key - }).ToList() - : 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 = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, - 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, - Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname + }).ToList(); - }).ToList(); - return final; - } - public string SetTasksColors(DateTime date, bool isCancel) + 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 = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0), + SelfName = x.SelfName, + SelfAssigned = x.SelfAssigned, + SelfAssigner = x.SelfAssigner, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest + }).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 + }).ToList(); + return final; + } + + + public string SetTasksColors(DateTime date, bool isCancel) { if (isCancel) { @@ -1016,7 +1251,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository { return _accountContext.Assigns.Include(x => x.Task).Where(x => x.Task.IsDone == false && x.Task.IsActiveString == "true" && - (x.Task.IsCanceledRequest == true || x.Task.TimeRequest == true || x.Task.IsDoneRequest)).GroupBy(x => x.TaskId) + (x.Task.IsCanceledRequest == true || x.Task.TimeRequest == true || x.Task.IsDoneRequest)&& accountId == x.Task.SenderId).GroupBy(x => x.TaskId) .Select(x => x.First()).Count(); } else @@ -1046,6 +1281,12 @@ public class TaskRepository : RepositoryBase, ITaskRepository }).FirstOrDefault(); } + public string GetWebEnvironmentPath() + { + return _webHostEnvironment.ContentRootPath; + } + + public List GetSelfTasks(TaskSearchModel searchModel) { var accountId = long.Parse(_contextAccessor.HttpContext.User.FindFirst("AccountId").Value); @@ -1058,7 +1299,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository 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.Task.IsCanceledRequest || !x.Task.TimeRequest || !x.Task.IsDoneRequest)) + x.Task.IsActiveString == "true" && (x.AssignerId == accountId && x.AssignedId == accountId) && (!x.Task.IsCanceledRequest && !x.Task.TimeRequest && !x.Task.IsDoneRequest)) .Select(x => new TaskViewModel() { @@ -1082,228 +1323,215 @@ public class TaskRepository : RepositoryBase, ITaskRepository IsDoneRequest = x.Task.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), + { + 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 = - x.AssignedId == accountId ? - ExtraTools.AddAccountIdToList(_accountContext.Assigns.Where(a => a.TaskId == x.Id && a.AssignerId == accountId).Select(a => a.AssignedId).ToList(), accountId) : _accountContext.Assigns.Where(a => a.TaskId == x.Id) - .Where(x => x.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) && + 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 > 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()); - if (searchModel.AccountId > 0) - { - result = result.Where(x => x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); - } + 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 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() - { - AssignViewModels = _accountContext.Accounts.Include(x => x.Position).Where(a => x.Assigned.Contains(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 + 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(); + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + final = final.Select(x => new TaskViewModel() + { - AssignList = !x.SelfAssigned && !x.SelfAssigner ? x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() - { - AssignViewModels = a.ToList(), - PosValue = a.Key - }).ToList() - : 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 = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, - SelfName = x.SelfName, - SelfAssigned = x.SelfAssigned, - SelfAssigner = x.SelfAssigner, - Description = x.Description, - IsDoneRequest = x.IsDoneRequest - }).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.IsDone ? "green" : SetTasksColors(x.EndTaskDateGE, x.IsCancel), + MediaCount = x.MediaCount, + HasAttachment = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, + SelfName = x.SelfName, + SelfAssigned = x.SelfAssigned, + SelfAssigner = x.SelfAssigner, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + 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, - Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname + 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, + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname - }).ToList(); - return final; - } + }).ToList(); + return final; + } public List GetAllNotSelfIncludedTasks(TaskSearchModel searchModel) { @@ -1317,7 +1545,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository var query = _accountContext.Assigns.Include(x => x.Task).ThenInclude(x => x.TaskMedias).ThenInclude(x => x.Media) .Where(x => - x.Task.IsActiveString == "true" && (!x.Task.IsCanceledRequest || !x.Task.TimeRequest || !x.Task.IsDoneRequest) && + x.Task.IsActiveString == "true" && (!x.Task.IsCanceledRequest && !x.Task.TimeRequest && !x.Task.IsDoneRequest) && x.AssignerId != accountId) .Select(x => new TaskViewModel() @@ -1343,230 +1571,217 @@ public class TaskRepository : RepositoryBase, ITaskRepository IsDoneRequest = x.Task.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), + { + 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 = - x.AssignedId == accountId ? - ExtraTools.AddAccountIdToList(_accountContext.Assigns.Where(a => a.TaskId == x.Id && a.AssignerId == accountId).Select(a => a.AssignedId).ToList(), accountId) : _accountContext.Assigns.Where(a => a.TaskId == x.Id) - .Where(x => x.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) && + 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 > 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()); - if (searchModel.AccountId > 0) - { - result = result.Where(x => x.Sender.Id == searchModel.AccountId || x.Assigned.Contains(searchModel.AccountId)); - } + 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 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() - { - AssignViewModels = _accountContext.Accounts.Include(x => x.Position).Where(a => x.Assigned.Contains(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 + 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(); + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + final = final.Select(x => new TaskViewModel() + { - AssignList = !x.SelfAssigned && !x.SelfAssigner ? x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() - { - AssignViewModels = a.ToList(), - PosValue = a.Key - }).ToList() - : 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 - }).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.IsDone ? "green" : SetTasksColors(x.EndTaskDateGE, x.IsCancel), + MediaCount = x.MediaCount, + HasAttachment = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, + SelfName = x.SelfName, + SelfAssigned = x.SelfAssigned, + SelfAssigner = x.SelfAssigner, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + 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, - Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname + 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, + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname - }).ToList(); - return final; + }).ToList(); + return final; - } + } public List GetReceivedTasks(TaskSearchModel searchModel) { @@ -1580,7 +1795,7 @@ public class TaskRepository : RepositoryBase, ITaskRepository 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.IsCanceledRequest || !x.Task.TimeRequest || !x.Task.IsDoneRequest)); + x.Task.IsActiveString == "true" && x.AssignedId == accountId && (!x.Task.IsCanceledRequest && !x.Task.TimeRequest && !x.Task.IsDoneRequest)); if (!string.IsNullOrWhiteSpace(searchModel.GeneralSearch)) { raw = raw.Where(x => @@ -1615,229 +1830,215 @@ public class TaskRepository : RepositoryBase, ITaskRepository IsDoneRequest = x.Task.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), + { + 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 = - x.AssignedId == accountId ? - ExtraTools.AddAccountIdToList(_accountContext.Assigns.Where(a => a.TaskId == x.Id && a.AssignerId == accountId).Select(a => a.AssignedId).ToList(), accountId) : _accountContext.Assigns.Where(a => a.TaskId == x.Id) - .Where(x => x.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) && + 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 > 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)); - } + 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() - { - AssignViewModels = _accountContext.Accounts.Include(x => x.Position).Where(a => x.Assigned.Contains(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 + 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(); + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + final = final.Select(x => new TaskViewModel() + { - AssignList = !x.SelfAssigned && !x.SelfAssigner ? x.AssignViewModels.GroupBy(a => a.AssignedPositionValue).Select(a => new AssignList() - { - AssignViewModels = a.ToList(), - PosValue = a.Key - }).ToList() - : 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 = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, - SelfName = x.SelfName, - SelfAssigned = x.SelfAssigned, - SelfAssigner = x.SelfAssigner, - Description = x.Description, - IsDoneRequest = x.IsDoneRequest - }).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.IsDone ? "green" : SetTasksColors(x.EndTaskDateGE, x.IsCancel), + MediaCount = x.MediaCount, + HasAttachment = (!string.IsNullOrWhiteSpace(x.Description) || x.MediaCount > 0) ? true : false, + SelfName = x.SelfName, + SelfAssigned = x.SelfAssigned, + SelfAssigner = x.SelfAssigner, + Description = x.Description, + IsDoneRequest = x.IsDoneRequest + }).ToList(); - final = final.Select(x => new TaskViewModel() - { + 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, - Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname + 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, + Assigner = x.Sender.Id == accountId ? emptyAcc.Fullname : x.Sender.Fullname - }).ToList(); - return final; - } + }).ToList(); + return final; + } } diff --git a/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs index cd9b1ea0..368174f9 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/TicketRepository.cs @@ -6,6 +6,7 @@ using AccountManagement.Application.Contracts.Media; using AccountManagement.Application.Contracts.Ticket; using AccountManagement.Domain.AdminResponseAgg; using AccountManagement.Domain.ClientResponseAgg; +using AccountManagement.Domain.ClientResponseMediaAgg; using AccountManagement.Domain.TicketAgg; using Microsoft.EntityFrameworkCore; @@ -148,6 +149,33 @@ public class TicketRepository : RepositoryBase, ITicketRepository Path = m.Media.Path, Type = m.Media.Type, }).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(), + }).ToList(), + AdminResponseViewModels = _accountContext.AdminResponses.Where(c => c.TicketId == x.id) + .Select(m => new AdminResponseViewModel() + { + Response = m.Response, + TicketId = m.TicketId, + 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(), + }).ToList(), }).FirstOrDefault(x => x.Id == id); } } \ No newline at end of file diff --git a/Company.Domain/empolyerAgg/IEmployerRepository.cs b/Company.Domain/empolyerAgg/IEmployerRepository.cs index 6d79c06b..88973019 100644 --- a/Company.Domain/empolyerAgg/IEmployerRepository.cs +++ b/Company.Domain/empolyerAgg/IEmployerRepository.cs @@ -29,6 +29,12 @@ public interface IEmployerRepository : IRepository bool ExistsEmployerAccountRegisterId(string commandRegisterId); bool ExistsEmployerAccountLName(string commandLName); + #region Mahan + + List GetEmployersHasWorkshop(); + + #endregion + #region NewByHeydari OperationResult DeleteEmployer(long id); List GetEmployerWithFNameOrLName(string searchText); diff --git a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs index 9559b889..32e00882 100644 --- a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs +++ b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs @@ -32,7 +32,10 @@ public interface IEmployerApplication OperationResult EditForClient(EditEmployer command); OperationResult EditLegalForClient(EditEmployer command); + #region Mahan + List GetEmployersHasWorkshop(); + #endregion #region NewByHeydari OperationResult DeleteEmployer(long id); List GetEmployerWithFNameOrLName(string searchText); diff --git a/CompanyManagment.Application/EmployerApplication.cs b/CompanyManagment.Application/EmployerApplication.cs index 9a26118d..d3498c57 100644 --- a/CompanyManagment.Application/EmployerApplication.cs +++ b/CompanyManagment.Application/EmployerApplication.cs @@ -886,6 +886,14 @@ public class EmployerApplication : IEmployerApplication return opration.Succcedded(); } + + #region Mahan + public List GetEmployersHasWorkshop() + { + return _EmployerRepository.GetEmployersHasWorkshop(); + } + #endregion + #region NewByHeydari diff --git a/CompanyManagment.EFCore/Repository/EmployerRepository.cs b/CompanyManagment.EFCore/Repository/EmployerRepository.cs index b514afd8..a5bdf2f6 100644 --- a/CompanyManagment.EFCore/Repository/EmployerRepository.cs +++ b/CompanyManagment.EFCore/Repository/EmployerRepository.cs @@ -17,17 +17,17 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos private readonly IAuthHelper _authHelper; public DateTime initial = new DateTime(1922, 01, 01, 00, 00, 00, 0000000); - + public EmployerRepository(CompanyContext context, IAuthHelper authHelper) : base(context) { _context = context; _authHelper = authHelper; - + } public List GetEmployers() { - return _context.Employers.Where(x=>x.IsActive==true).Select(x => new EmployerViewModel + return _context.Employers.Where(x => x.IsActive == true).Select(x => new EmployerViewModel { Id = x.id, @@ -63,8 +63,8 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos Phone = x.Phone, AgentPhone = x.AgentPhone, Address = x.Address - }).Where(x=> id.Contains(x.Id)) - .Where(x=>x.IsActive).ToList(); + }).Where(x => id.Contains(x.Id)) + .Where(x => x.IsActive).ToList(); //var empList = new List(); //foreach (var item in id) //{ @@ -96,47 +96,47 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos public EditEmployer GetDetails(long id) { return _context.Employers.Select(x => new EditEmployer - { - Id = x.id, - FName = x.FName, - LName = x.LName, - ContractingPartyId = x.ContractingPartyId, - Gender = x.Gender, - Nationalcode = x.Nationalcode, - IdNumber = x.IdNumber, - Nationality = x.Nationality, - FatherName = x.FatherName, - DateOfBirth = x.DateOfBirth == initial ? "" : x.DateOfBirth.ToFarsi(), - DateOfIssue = x.DateOfIssue == initial ? "" : x.DateOfIssue.ToFarsi(), - PlaceOfIssue = x.PlaceOfIssue, - RegisterId = x.RegisterId, - NationalId = x.NationalId, - EmployerLName = x.EmployerLName, - IsLegal = x.IsLegal, - Phone = x.Phone, - AgentPhone = x.AgentPhone, - Address = x.Address, - MclsUserName = x.MclsUserName, - MclsPassword = x.MclsPassword, - EserviceUserName = x.EserviceUserName, - EservicePassword = x.EservicePassword, - TaxOfficeUserName = x.EservicePassword, - SanaUserName = x.SanaUserName, - SanaPassword = x.SanaPassword, - EmployerNo = x.EmployerNo, - FullName = x.FullName + { + Id = x.id, + FName = x.FName, + LName = x.LName, + ContractingPartyId = x.ContractingPartyId, + Gender = x.Gender, + Nationalcode = x.Nationalcode, + IdNumber = x.IdNumber, + Nationality = x.Nationality, + FatherName = x.FatherName, + DateOfBirth = x.DateOfBirth == initial ? "" : x.DateOfBirth.ToFarsi(), + DateOfIssue = x.DateOfIssue == initial ? "" : x.DateOfIssue.ToFarsi(), + PlaceOfIssue = x.PlaceOfIssue, + RegisterId = x.RegisterId, + NationalId = x.NationalId, + EmployerLName = x.EmployerLName, + IsLegal = x.IsLegal, + Phone = x.Phone, + AgentPhone = x.AgentPhone, + Address = x.Address, + MclsUserName = x.MclsUserName, + MclsPassword = x.MclsPassword, + EserviceUserName = x.EserviceUserName, + EservicePassword = x.EservicePassword, + TaxOfficeUserName = x.EservicePassword, + SanaUserName = x.SanaUserName, + SanaPassword = x.SanaPassword, + EmployerNo = x.EmployerNo, + FullName = x.FullName - }) + }) .FirstOrDefault(x => x.Id == id); } public List GetEmployerByWorkshopId(long workshopId) { - - var emps = _context.WorkshopEmployers.Where(x=>x.WorkshopId == workshopId) + + var emps = _context.WorkshopEmployers.Where(x => x.WorkshopId == workshopId) .Select(x => x.EmployerId).ToList(); var employerlist = _context.Employers.Where(x => emps.Contains(x.id)).ToList(); var employers = new List(); @@ -152,11 +152,11 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos IsLegal = element.IsLegal, LName = element.LName, IsBlockContractingParty = _context.PersonalContractingParties.FirstOrDefault(x => x.id == element.ContractingPartyId)?.IsBlock, - }; + }; employers.Add(employer); } - + return employers; } @@ -164,26 +164,26 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos public List GetEmployerByContracrtingPartyID(long contractingPartyId) { return _context.Employers.Select(x => new EmployerViewModel() - { - Id = x.id, - FName = x.FName, - LName = x.LName, - ContractingPartyID = x.ContractingPartyId, - EmployerNo = x.EmployerNo, - Nationalcode = x.Nationalcode, - IdNumber = x.IdNumber, - Nationality = x.Nationality, - - RegisterId = x.RegisterId, - NationalId = x.NationalId, - EmployerLName = x.EmployerLName, - IsLegal = x.IsLegal, - - FullName = x.FName + " " +x.LName, + { + Id = x.id, + FName = x.FName, + LName = x.LName, + ContractingPartyID = x.ContractingPartyId, + EmployerNo = x.EmployerNo, + Nationalcode = x.Nationalcode, + IdNumber = x.IdNumber, + Nationality = x.Nationality, + + RegisterId = x.RegisterId, + NationalId = x.NationalId, + EmployerLName = x.EmployerLName, + IsLegal = x.IsLegal, + + FullName = x.FName + " " + x.LName, - }).Where(x=>x.ContractingPartyID==contractingPartyId) + }).Where(x => x.ContractingPartyID == contractingPartyId) .ToList(); } @@ -210,18 +210,18 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos Address = x.Address, EmployerNo = x.EmployerNo, HasContractingParty = x.ContractingPartyId == 30428 && workshopEmp.Any(n => n == x.id), - HasBlockContractingParty = x.ContractingParty.IsBlock=="true", + HasBlockContractingParty = x.ContractingParty.IsBlock == "true", }); if (searchModel.Id > 0) query = query.Where(x => x.Id == searchModel.Id); if (!string.IsNullOrWhiteSpace(searchModel.LName)) - query = query.Where(x => x.LName.Contains(searchModel.FName)|| x.FName.Contains(searchModel.LName)); - + query = query.Where(x => x.LName.Contains(searchModel.FName) || x.FName.Contains(searchModel.LName)); + if (!string.IsNullOrWhiteSpace(searchModel.Nationalcode) && searchModel.Nationalcode != "0") - query = query.Where(x => x.Nationalcode.Contains(searchModel.Nationalcode)|| x.NationalId.Contains(searchModel.Nationalcode)); + query = query.Where(x => x.Nationalcode.Contains(searchModel.Nationalcode) || x.NationalId.Contains(searchModel.Nationalcode)); if (!string.IsNullOrWhiteSpace(searchModel.IdNumber) && searchModel.IdNumber != "0") query = query.Where(x => x.IdNumber.Contains(searchModel.IdNumber) || x.RegisterId.Contains(searchModel.IdNumber)); @@ -238,7 +238,7 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos if (!string.IsNullOrEmpty(searchModel.ContactingPartyName)) { - var personalContractingPIds = _context.PersonalContractingParties.Where(x => !string.IsNullOrEmpty(x.FName) && (x.FName+" "+x.LName).Contains(searchModel.ContactingPartyName)).Select(x => x.id).ToList(); + var personalContractingPIds = _context.PersonalContractingParties.Where(x => !string.IsNullOrEmpty(x.FName) && (x.FName + " " + x.LName).Contains(searchModel.ContactingPartyName)).Select(x => x.id).ToList(); query = query.Where(x => personalContractingPIds.Contains(x.ContractingPartyID)); } @@ -269,16 +269,16 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos public List GetEmployerByEmployerIds(List employerIds) { return _context.Employers.Select(x => new EmprViewModel() - { - Id = x.id, - FName = x.FName, - LName = x.LName, - EmployerLName = x.EmployerLName, - IsLegal = x.IsLegal, + { + Id = x.id, + FName = x.FName, + LName = x.LName, + EmployerLName = x.EmployerLName, + IsLegal = x.IsLegal, - //FullName = x.FName + " " + x.LName, + //FullName = x.FName + " " + x.LName, - }).Where(x => employerIds.Contains(x.Id)) + }).Where(x => employerIds.Contains(x.Id)) .ToList(); } @@ -556,6 +556,20 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos return false; } + #region Mahan + + public List GetEmployersHasWorkshop() + { + return _context.WorkshopEmployers.Include(x => x.Employer).Select(x => + new EmployerViewModel() + { + FullName = x.Employer.FullName, + Id = x.Employer.id + }).ToList(); + } + + #endregion + #region NewByHeydari public OperationResult DeleteEmployer(long id) { @@ -575,10 +589,10 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos public List GetEmployerWithFNameOrLName(string searchText) { - var result = _context.Employers.Where(x => (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchText))|| + var result = _context.Employers.Where(x => (!string.IsNullOrEmpty(x.FName) && x.FName.StartsWith(searchText)) || (!string.IsNullOrEmpty(x.LName) && x.LName.StartsWith(searchText)) || - (x.IsLegal== "حقیقی" && (!string.IsNullOrEmpty(x.FName)&& !string.IsNullOrEmpty(x.LName)) && - (x.FName +" "+ x.LName).Contains(searchText))) + (x.IsLegal == "حقیقی" && (!string.IsNullOrEmpty(x.FName) && !string.IsNullOrEmpty(x.LName)) && + (x.FName + " " + x.LName).Contains(searchText))) .Select(x => new EmployerViewModel { Id = x.id, @@ -606,7 +620,7 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos .Select(x => new EmployerViewModel { Id = x.id, - Nationalcode =(x.IsLegal== "حقیقی" ? x.Nationalcode:x.NationalId) , + Nationalcode = (x.IsLegal == "حقیقی" ? x.Nationalcode : x.NationalId), }).Take(100).ToList(); return result; @@ -619,12 +633,12 @@ public class EmployerRepository : RepositoryBase, IEmployerRepos { try { - + var employer = _context.Employers.FirstOrDefault(x => x.id == id); employer.DeActive(); - var workshopIds = _context.WorkshopEmployers.Where(x => x.EmployerId==id).Select(x => x.WorkshopId).ToList(); + var workshopIds = _context.WorkshopEmployers.Where(x => x.EmployerId == id).Select(x => x.WorkshopId).ToList(); var workshops = _context.Workshops.Where(x => workshopIds.Contains(x.id)).ToList(); workshops.ForEach(x => x.DeActive(x.ArchiveCode)); diff --git a/CompanyManagment.EFCore/Repository/WorkshopRepository.cs b/CompanyManagment.EFCore/Repository/WorkshopRepository.cs index 8011bfea..b0f9ac63 100644 --- a/CompanyManagment.EFCore/Repository/WorkshopRepository.cs +++ b/CompanyManagment.EFCore/Repository/WorkshopRepository.cs @@ -98,7 +98,7 @@ public class WorkshopRepository : RepositoryBase x.AccountId == AcountID) // .Select(x => x.WorkshopId).ToList(); - var workshopAcountsList = _context.WorkshopAccounts.FromSqlInterpolated($"SelectQuery_WorkshopIdGetAccId {AcountID}").AsNoTracking().ToList(); + var workshopAcountsList = _context.WorkshopAccounts.Where(x => x.AccountId == AcountID); //var res = (e => contractData.Contains(e.Id)) var workshopAcounts = workshopAcountsList.Select(x => x.WorkshopId).ToList(); diff --git a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml index 4e1473a6..3d50367e 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml @@ -698,7 +698,7 @@ ایجاد قرارداد

@**@ - + @*href="#showmodal=@Url.Page("./Index", "PrintAll", new {ids = idss})"*@ diff --git a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs index c71162b4..188ac642 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs @@ -1,4 +1,5 @@ -using _0_Framework.Application; +using System.Diagnostics.CodeAnalysis; +using _0_Framework.Application; using AccountManagement.Application.Contracts.Account; using CompanyManagment.App.Contracts.Employer; using CompanyManagment.App.Contracts.InstitutionContract; @@ -12,6 +13,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using PersianTools.Core; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; //using iText.Html2pdf; //using iText.IO.Source; //using iText.Kernel.Geom; @@ -72,6 +74,8 @@ public class IndexModel : PageModel public string Message { get; set; } + [SuppressMessage("ReSharper.DPA", "DPA0006: Large number of DB commands", MessageId = "count: 270")] + [SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records", MessageId = "count: 16092")] public void OnGet(InstitutionContractSearchModel searchModel) { //var test = _institutionContract.NewSearch(searchModel); @@ -96,7 +100,57 @@ public class IndexModel : PageModel SumOfAmounts = totalAmounts.ToMoney(); TotalBalance = totalBalance.ToMoney(); } + // اصلاح شماره تماس ها + #region CorrectionContactInfo + public IActionResult OnGetCorrection() + { + var getNewContarcts = _institutionContract.NewSearch(new InstitutionContractSearchModel() { }); + foreach (var newContracts in getNewContarcts) + { + var deActiveContracts = _institutionContract.NewSearch(new InstitutionContractSearchModel() + { ContractingPartyId = newContracts.ContractingPartyId, IsActiveString = "false" }); + Thread.Sleep(100); + if (deActiveContracts.Count > 0) + { + var newContactInfo = _contactInfoApplication.GetContactInfolist(newContracts.Id); + foreach (var deactive in deActiveContracts) + { + + _contactInfoApplication.RemoveContactInfo(deactive.Id); + foreach (var phone in newContactInfo) + { + if (phone.PhoneNumber != null) + { + var contactinfo = new CreateContactInfo + { + InstitutionContractId = deactive.Id, + PhoneType = phone.PhoneType, + Position = phone.Position, + PhoneNumber = phone.PhoneNumber, + FnameLname = phone.FnameLname, + SendSms = phone.SendSms, + }; + _contactInfoApplication.Create(contactinfo); + Console.WriteLine(phone.PhoneNumber); + } + + Thread.Sleep(100); + } + } + } + + + + } + + return new JsonResult(new + { + IsSuccedded = true, + }); + } + + #endregion public IActionResult OnPostContractingParties(long id) { @@ -379,11 +433,39 @@ public class IndexModel : PageModel //if (string.IsNullOrWhiteSpace(command.HasValueAddedTax)) // command.HasValueAddedTax = "false"; var result = _institutionContract.Edit(command); + var contractingPartyId = _institutionContract.GetDetails(result.SendId); var counter = command.ContactInformationList.Count; + var getOldContarct = _institutionContract.NewSearch(new InstitutionContractSearchModel() + { ContractingPartyId = contractingPartyId.ContractingPartyId, IsActiveString = "both" }).Where(x=>x.IsActiveString == "false" || x.IsActiveString == "blue").ToList(); if (result.IsSuccedded && counter > 0) { - _contactInfoApplication.RemoveContactInfo(command.Id); + + if (getOldContarct.Count > 0) + { + foreach (var item in getOldContarct) + { + _contactInfoApplication.RemoveContactInfo(item.Id); + foreach (var phone in command.ContactInformationList) + { + if (phone.PhoneNumber != null) + { + var contactinfo = new CreateContactInfo + { + InstitutionContractId = item.Id, + PhoneType = phone.PhoneType, + Position = phone.Position, + PhoneNumber = phone.PhoneNumber, + FnameLname = phone.FnameLname, + SendSms = phone.SendSmsString == "true" ? true : false + }; + _contactInfoApplication.Create(contactinfo); + } + Thread.Sleep(500); + } + } + } + _contactInfoApplication.RemoveContactInfo(command.Id); foreach (var item in command.ContactInformationList) { if (item.PhoneNumber != null) @@ -585,6 +667,7 @@ public class IndexModel : PageModel var result = _institutionContract.Extension(command); if (result.IsSuccedded && counter > 0) + { for (var i = 0; i <= counter - 1; i++) { if (command.ContactInformationList[i].PhoneNumber != null) @@ -603,13 +686,47 @@ public class IndexModel : PageModel Thread.Sleep(500); } + } + if (result.IsSuccedded) { _institutionContract.DeActive(command.PrviousContractId); _institutionContract.ReActiveAllAfterCreateNew(command.ContractingPartyId); } + var contractingPartyId = _institutionContract.GetDetails(result.SendId); + var getOldContarct = _institutionContract.NewSearch(new InstitutionContractSearchModel() + { ContractingPartyId = contractingPartyId.ContractingPartyId, IsActiveString = "both" }).Where(x => x.IsActiveString == "false" || x.IsActiveString == "blue").ToList(); + if (result.IsSuccedded && counter > 0) + { + + if (getOldContarct.Count > 0) + { + foreach (var item in getOldContarct) + { + _contactInfoApplication.RemoveContactInfo(item.Id); + foreach (var phone in command.ContactInformationList) + { + if (phone.PhoneNumber != null) + { + var contactinfo = new CreateContactInfo + { + InstitutionContractId = item.Id, + PhoneType = phone.PhoneType, + Position = phone.Position, + PhoneNumber = phone.PhoneNumber, + FnameLname = phone.FnameLname, + SendSms = phone.SendSmsString == "true" ? true : false + }; + _contactInfoApplication.Create(contactinfo); + } + + Thread.Sleep(500); + } + } + } + } return new JsonResult(result); } diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml b/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml index 36a85b77..7f0059b8 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml +++ b/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml @@ -1,258 +1,305 @@ @page +@model ServiceHost.Areas.AdminNew.Pages.Company.Task.CreateModel @using Version = _0_Framework.Application.Version -@model CreateModel @{ ViewData["title"] = " - وظیفه جدید"; } - @section Styles { - - - + + + } +
-
-
-
- +
+
+
+ +
+

وظایف جدید

+
کارگاه نورداد مهر گستر کاسپین
+
+
-

وظایف جدید

-
کارگاه نورداد مهر گستر کاسپین
+ + بازگشت +
-
-
- -
-
-
+ +
+
+
-
- @* *@ -
-
-
-
-
- - -
-
- - -
-
-
-
- -
- -
-
-
-
-
- -
-
    -
-
-
-
- -
-
- - - - -
-
-
-
    -
-
-
-
-
-
-
-
- @* *@ - - -
- -
-
- - + + @* *@ +
+
+
+
+
+ +
-
- - +
+ +
-
- - +
+
+
+ +
+
-
-
- +
+
+
+ +
+
    +
+
+ +
+
+ + + + +
+
+
+
    +
+
+
+
+
+
+
+
+ @* *@ + + +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+ +
+
+
+
-
- - @*
+ @*
مهلت زمانی:
*@ -
- - -
-
-
- -
-
-
-
-
-
- -
- - - - - - - - - -
-
-
-
-
-
-
-
-
-
-
-
- - -
-
-
-
+
+
+
+
-
-
-
- - انصراف - - + + + + + + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
- - @* ارسال *@ +
-
- + + + +
-
@section Script { - + - + + + + + +} -} \ No newline at end of file + diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs index 9fe08d8f..0d016784 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/Task/Create.cshtml.cs @@ -1,5 +1,4 @@ -using System.Globalization; -using _0_Framework.Application; +using _0_Framework.Application; using AccountManagement.Application.Contracts.Account; using AccountManagement.Application.Contracts.Position; using AccountManagement.Application.Contracts.Task; @@ -7,269 +6,341 @@ using AccountManagement.Application.Contracts.TaskSubject; using CompanyManagment.App.Contracts.Holiday; using CompanyManagment.App.Contracts.HolidayItem; using CompanyManagment.App.Contracts.PersonalContractingParty; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System.Collections.Generic; +using System.Globalization; +using Microsoft.AspNetCore.Authorization; +using Company.Domain.HolidayAgg; +using CompanyManagment.App.Contracts.Employer; +using CompanyManagment.App.Contracts.Workshop; -namespace ServiceHost.Areas.AdminNew.Pages.Company.Task; - -[Authorize] -public class CreateModel : PageModel +namespace ServiceHost.Areas.AdminNew.Pages.Company.Task { - private readonly IAccountApplication _accountApplication; - private readonly IAuthHelper _authHelper; - private readonly IPersonalContractingPartyApp _contractingPartyApp; - private readonly IHolidayItemApplication _holidayItemApplication; - private readonly IPersonalContractingPartyApp _personalContractingPartyApp; - private readonly IPositionApplication _positionApplication; - private readonly ITaskApplication _taskApplication; - private readonly ITaskSubjectApplication _taskSubjectApplication; - private readonly IWebHostEnvironment _webHostEnvironment; - public string DateFa; - - public CreateModel(ITaskApplication taskApplication, IAccountApplication accountApplication, - IPersonalContractingPartyApp personalContractingPartyApp, IAuthHelper authHelper, - IPersonalContractingPartyApp contractingPartyApp, IPositionApplication positionApplication, - ITaskSubjectApplication taskSubjectApplication, IWebHostEnvironment webHostEnvironment, - IHolidayApplication holidayApplication, IHolidayItemApplication holidayItemApplication) - { - _taskApplication = taskApplication; - _accountApplication = accountApplication; - _personalContractingPartyApp = personalContractingPartyApp; - _authHelper = authHelper; - _contractingPartyApp = contractingPartyApp; - _positionApplication = positionApplication; - _taskSubjectApplication = taskSubjectApplication; - _webHostEnvironment = webHostEnvironment; - _holidayItemApplication = holidayItemApplication; - } - - public CreateTask Command { get; set; } - public SelectList AccountsList { get; set; } - public List PositionViewModels { get; set; } - public long Id { get; set; } - - public IActionResult OnGet() - { - var positionValue = _authHelper.CurrentAccountInfo().PositionValue == null - ? 0 - : _authHelper.CurrentAccountInfo().PositionValue; - - if (positionValue > 0) - { - if (_authHelper.GetPermissions().Any(x => x == 903)) - { - var accounts = _accountApplication.GetAccountLowerPositionvalue(); - AccountsList = new SelectList(accounts, "Id", "Fullname"); - PositionViewModels = _positionApplication.GetLowerPosition(); - DateFa = DateTime.Now.ToFarsi(); - Id = _authHelper.CurrentAccountId(); - return Page(); - } - - return Forbid(); - } - - return Forbid(); - } + [Authorize] + public class CreateModel : PageModel + { + private readonly ITaskApplication _taskApplication; + private readonly IAccountApplication _accountApplication; + private readonly IAuthHelper _authHelper; + private readonly IPersonalContractingPartyApp _contractingPartyApp; + private readonly IPositionApplication _positionApplication; + private readonly ITaskSubjectApplication _taskSubjectApplication; + private readonly IHolidayItemApplication _holidayItemApplication; + private readonly IEmployerApplication _employerApplication; + private readonly IWorkshopApplication _workshopApplication; - public IActionResult OnPostCreateSaveTask(CreateTask Command) - { - Command.SenderId = _authHelper.CurrentAccountId(); - var result = _taskApplication.CreateTask(Command); - return new JsonResult(new - { - result.IsSuccedded, - message = result.Message - }); - } + public CreateModel(ITaskApplication taskApplication, IAccountApplication accountApplication, IPersonalContractingPartyApp personalContractingPartyApp, IAuthHelper authHelper, IPersonalContractingPartyApp contractingPartyApp, IPositionApplication positionApplication, ITaskSubjectApplication taskSubjectApplication, IWebHostEnvironment webHostEnvironment, IHolidayApplication holidayApplication, IHolidayItemApplication holidayItemApplication, IEmployerApplication employerApplication, IWorkshopApplication workshopApplication) + { + _taskApplication = taskApplication; + _accountApplication = accountApplication; + _authHelper = authHelper; + _contractingPartyApp = contractingPartyApp; + _positionApplication = positionApplication; + _taskSubjectApplication = taskSubjectApplication; + _holidayItemApplication = holidayItemApplication; + _employerApplication = employerApplication; + _workshopApplication = workshopApplication; + } - public IActionResult OnGetSearchContractingParties(string searchName) - { - var list = new List(); - var contractingParties = _contractingPartyApp.SearchByName(searchName); + public CreateTask Command { get; set; } + public SelectList AccountsList { get; set; } + public List PositionViewModels { get; set; } + public long Id { get; set; } + public string DateFa; - //var test =list.Join(contractingParties, x=>x , c=>c,(first, second)=> new string(first=second)).ToList(); + public IActionResult OnGet() + { + var positionValue = _authHelper.CurrentAccountInfo().PositionValue == null + ? 0 + : _authHelper.CurrentAccountInfo().PositionValue; - return new JsonResult(new - { - isSuccess = true, list - }); - } + if (positionValue > 0) + { + if (_authHelper.GetPermissions().Any(x => x == 903)) + { + var accounts = _accountApplication.GetAccountLowerPositionvalue(); + AccountsList = new SelectList(accounts, "Id", "Fullname"); + PositionViewModels = _positionApplication.GetLowerPosition(); + DateFa = DateTime.Now.ToFarsi(); + Id = _authHelper.CurrentAccountId(); + return Page(); + } + else + { + return Forbid(); + } + + } + else + { + return Forbid(); + } + + } - // برای باز کردن مودال عنوان دلبخواه - public IActionResult OnGetTaskSubject() - { - return Partial("CreateCRUDTaskSubjectModal"); - } + public IActionResult OnPostCreateSaveTask(CreateTask Command) + { + Command.SenderId = _authHelper.CurrentAccountId(); + Command.Description = Command.Description?.Replace("\n", "
"); + var result = _taskApplication.CreateTask(Command); + return new JsonResult(new + { + IsSuccedded = result.IsSuccedded, + message = result.Message, + }); + } - // برای گرفتن عنوان دلبخواه - public IActionResult OnGetListTaskSubject() - { - var result = _taskSubjectApplication.GetAll("").OrderByDescending(x => x.Id); - return new JsonResult(new - { - result - }); - } + public IActionResult OnGetSearchContractingParties(string searchName) + { + var list = new List(); + var contractingParties = _contractingPartyApp.SearchByName(searchName); + var employers = _employerApplication.GetEmployersHasWorkshop().Select(x => x.FullName).ToList(); + var workshops = _workshopApplication.GetWorkshopAll().Select(x => x.WorkshopFullName).ToList(); + + list.Capacity = list.Count + contractingParties.Count + employers.Count + workshops.Count; + list.AddRange(contractingParties); + list.AddRange(employers); + list.AddRange(workshops); - // برای ذخیره عنوان دلبخواه - public IActionResult OnPostCreateTaskSubject(string subject) - { - var result = _taskSubjectApplication.Create(subject); - return new JsonResult(new - { - isSuccess = result.IsSuccedded, - message = result.Message - }); - } - - // برای ویرایش عنوان دلبخواه - public IActionResult OnPostEditTaskSubject(long id, string subject) - { - var model = new TaskSubjectViewModel - { - Id = id, - Subject = subject - }; - var result = _taskSubjectApplication.Edit(model); - return new JsonResult(new - { - isSuccess = result.IsSuccedded, - message = result.Message - }); - } - - // برای حذف عنوان دلبخواه - public IActionResult OnPostRemoveTaskSubject(long id) - { - var result = _taskSubjectApplication.Delete(id); - return new JsonResult(new - { - isSuccess = result.IsSuccedded, - message = result.Message - }); - } + return new JsonResult(new + { + isSuccess = true, + list = list.GroupBy(x=>x).Select(x=>x.First()), + }); + } - public IActionResult OnGetSearchTaskSubject(string searchSubject) - { - var list = _taskSubjectApplication.GetAll(searchSubject); - return new JsonResult(new - { - isSuccess = true, list - }); - } + // برای محاسبه تاریخ و ساعت + #region ComputeDay + //public IActionResult OnGetComputeDay(string date, string time) + //{ - public IActionResult OnGetCheckHoliday(string time) - { - var dateTime = time.ToGeorgianDateTime().Date; - var errorDate = new DateTime(3000, 12, 20, new PersianCalendar()); - var operation = new OperationResult(); - if (dateTime == errorDate) - { - operation.Failed("لطفا تاریخ خود را به درستی وارد کنید"); - return new JsonResult(new - { - operation.IsSuccedded, - operation.Message, - isHoliday = false - }); - } + // if (string.IsNullOrWhiteSpace(time)) + // { + // time = "23:59"; + // } + // if (!string.IsNullOrWhiteSpace(date)) + // { + // var endTime = Convert.ToDateTime(time); + // var dateDeadline = date.ToGeorgianDateTime(); + // dateDeadline = dateDeadline.AddHours(endTime.Hour).AddMinutes(endTime.Minute); - var isHoliday = _holidayItemApplication.GetHoliday(dateTime); + // var dateNow = DateTime.Now; - operation.Succcedded(); - return new JsonResult(new - { - operation.IsSuccedded, - isHoliday - }); - } + // if (dateDeadline > dateNow) + // { + // var daysSpan = ((dateDeadline.Date - dateNow.Date).TotalDays); - // برای محاسبه تاریخ و ساعت - - #region ComputeDay - - //public IActionResult OnGetComputeDay(string date, string time) - //{ - - // if (string.IsNullOrWhiteSpace(time)) - // { - // time = "23:59"; - // } - // if (!string.IsNullOrWhiteSpace(date)) - // { - // var endTime = Convert.ToDateTime(time); - // var dateDeadline = date.ToGeorgianDateTime(); - // dateDeadline = dateDeadline.AddHours(endTime.Hour).AddMinutes(endTime.Minute); - - // var dateNow = DateTime.Now; - - // if (dateDeadline > dateNow) - // { - // var daysSpan = ((dateDeadline.Date - dateNow.Date).TotalDays); + // if (!string.IsNullOrWhiteSpace(time)) + // { - // if (!string.IsNullOrWhiteSpace(time)) - // { + // var hourlyDate = dateDeadline.ToLocalTime() - DateTime.Now.ToLocalTime(); + // var hours = dateDeadline.Hour - DateTime.Now.Hour; - // var hourlyDate = dateDeadline.ToLocalTime() - DateTime.Now.ToLocalTime(); - // var hours = dateDeadline.Hour - DateTime.Now.Hour; + // if (hours > 0&& (int)daysSpan > 0) + // { + // return new JsonResult(new + // { + // res = $"{(int)daysSpan} روز " + hours + " " + "ساعت ", + // }); + // } + // else if (hours == 0&&(int)daysSpan>0) + // { + // return new JsonResult(new + // { + // res = $"{(int)daysSpan} روز " + // }); + // } + // else if (hours>0&& (int)daysSpan == 0) + // { + // return new JsonResult(new + // { + // res = $"{hours} ساعت", + // }); + // } - // if (hours > 0&& (int)daysSpan > 0) - // { - // return new JsonResult(new - // { - // res = $"{(int)daysSpan} روز " + hours + " " + "ساعت ", - // }); - // } - // else if (hours == 0&&(int)daysSpan>0) - // { - // return new JsonResult(new - // { - // res = $"{(int)daysSpan} روز " - // }); - // } - // else if (hours>0&& (int)daysSpan == 0) - // { - // return new JsonResult(new - // { - // res = $"{hours} ساعت", - // }); - // } + // } - // } + // return new JsonResult(new + // { + // res = $"{(int)daysSpan} روز", + // }); + // } + // else + // { + // return new JsonResult(new + // { + // status = false, + // res = "مهلت انجام پروژه نمی تواند کوچکتر از گذشته باشد.", + // }); + // } + // } + + // return new JsonResult(new + // { + // res = "", + // }); + //} - // return new JsonResult(new - // { - // res = $"{(int)daysSpan} روز", - // }); - // } - // else - // { - // return new JsonResult(new - // { - // status = false, - // res = "مهلت انجام پروژه نمی تواند کوچکتر از گذشته باشد.", - // }); - // } - // } + #endregion - // return new JsonResult(new - // { - // res = "", - // }); - //} - #endregion -} \ No newline at end of file + + + // برای باز کردن مودال عنوان دلبخواه + public IActionResult OnGetTaskSubject() + { + + return Partial("CreateCRUDTaskSubjectModal"); + } + + // برای گرفتن عنوان دلبخواه + public IActionResult OnGetListTaskSubject() + { + var result = _taskSubjectApplication.GetAll("").OrderByDescending(x => x.Id); + return new JsonResult(new + { + result + }); + } + + + // برای ذخیره عنوان دلبخواه + public IActionResult OnPostCreateTaskSubject(string subject) + { + var result = _taskSubjectApplication.Create(subject); + return new JsonResult(new + { + isSuccess = result.IsSuccedded, + message = result.Message, + }); + } + + // برای ویرایش عنوان دلبخواه + public IActionResult OnPostEditTaskSubject(long id, string subject) + { + var model = new TaskSubjectViewModel() + { + Id = id, + Subject = subject + }; + var result = _taskSubjectApplication.Edit(model); + return new JsonResult(new + { + isSuccess = result.IsSuccedded, + message = result.Message, + }); + } + + // برای حذف عنوان دلبخواه + public IActionResult OnPostRemoveTaskSubject(long id) + { + var result = _taskSubjectApplication.Delete(id); + return new JsonResult(new + { + isSuccess = result.IsSuccedded, + message = result.Message, + }); + } + + + public IActionResult OnGetSearchTaskSubject(string searchSubject) + { + var list = _taskSubjectApplication.GetAll(searchSubject); + return new JsonResult(new + { + isSuccess = true, + list = list, + }); + } + + public IActionResult OnGetCheckHoliday(string time) + { + + var dateTime = time.ToGeorgianDateTime().Date; + var errorDate = new DateTime(3000, 12, 20, new PersianCalendar()); + var operation = new OperationResult(); + if (dateTime == errorDate) + { + operation.Failed("لطفا تاریخ خود را به درستی وارد کنید"); + return new JsonResult(new + { + IsSuccedded = operation.IsSuccedded, + Message = operation.Message, + isHoliday = false + + }); + } + + var isFriday = (dateTime.DayOfWeek == DayOfWeek.Friday); + var isHoliday = _holidayItemApplication.GetHoliday(dateTime); + if (isFriday) + { + operation.Succcedded(); + return new JsonResult(new + { + IsSuccedded = operation.IsSuccedded, + isHoliday=true + }); + } + else + { + return new JsonResult(new + { + IsSuccedded = operation.IsSuccedded, + isHoliday + }); + } + + + } + + public IActionResult OnPostUploadFile(IFormFile media) + { + var accountId = _authHelper.CurrentAccountId(); + var operation = _taskApplication.UploadMedia(media, accountId); + return new JsonResult(new + { + IsSuccedded = operation.IsSuccedded, + message = operation.Message, + id = operation.SendId, + }); + } + + public IActionResult OnPostDeleteFile(long mediaId) + { + var operation = _taskApplication.RemoveMedia(mediaId); + return new JsonResult(new + { + IsSuccedded = operation.IsSuccedded, + message = operation.Message, + }); + } + + public IActionResult OnPostRemoveAllTempFiles() + { + var accId = _authHelper.CurrentAccountId(); + var operation = new OperationResult(); + _taskApplication.RemoveTempUploadedFiles(accId); + operation.Succcedded(); + return new JsonResult(new + { + IsSuccedded = operation.IsSuccedded, + message = operation.Message, + }); + } + + } +} diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateCRUDTaskSubjectModal.cshtml b/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateCRUDTaskSubjectModal.cshtml index 6e3af629..f0a75c78 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateCRUDTaskSubjectModal.cshtml +++ b/ServiceHost/Areas/AdminNew/Pages/Company/Task/CreateCRUDTaskSubjectModal.cshtml @@ -1,4 +1,8 @@ - +@using Version = _0_Framework.Application.Version + + + + \n\n
\n
\n
\n
\n
\n
\n
\n `,[t,e]}setOptions(t){if(this.options.container!==t.container){const e=this.parentFromOptionsContainer(t.container);e.appendChild(this.container),this.parent=e}!0!==t.dragToSeek&&"object"!=typeof this.options.dragToSeek||this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(t){this.scrollContainer.scrollLeft=t}setScrollPercentage(t){const{scrollWidth:e}=this.scrollContainer,i=e*t;this.setScroll(i)}destroy(){var t,e;this.subscriptions.forEach((t=>t())),this.container.remove(),null===(t=this.resizeObserver)||void 0===t||t.disconnect(),null===(e=this.unsubscribeOnScroll)||void 0===e||e.call(this)}createDelay(t=10){let e,i;const n=()=>{e&&clearTimeout(e),i&&i()};return this.timeouts.push(n),()=>new Promise(((s,r)=>{n(),i=r,e=setTimeout((()=>{e=void 0,i=void 0,s()}),t)}))}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length<2)return t[0]||"";const e=document.createElement("canvas"),i=e.getContext("2d"),n=e.height*(window.devicePixelRatio||1),s=i.createLinearGradient(0,0,0,n),r=1/(t.length-1);return t.forEach(((t,e)=>{const i=e*r;s.addColorStop(i,t)})),s}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,n){const s=t[0],r=t[1]||t[0],o=s.length,{width:a,height:h}=i.canvas,l=h/2,d=this.getPixelRatio(),c=e.barWidth?e.barWidth*d:1,u=e.barGap?e.barGap*d:e.barWidth?c/2:0,p=e.barRadius||0,m=a/(c+u)/o,f=p&&"roundRect"in i?"roundRect":"rect";i.beginPath();let g=0,v=0,b=0;for(let t=0;t<=o;t++){const o=Math.round(t*m);if(o>g){const t=Math.round(v*l*n),s=t+Math.round(b*l*n)||1;let r=l-t;"top"===e.barAlign?r=0:"bottom"===e.barAlign&&(r=h-s),i[f](g*(c+u),r,c,s,p),g=o,v=0,b=0}const a=Math.abs(s[t]||0),d=Math.abs(r[t]||0);a>v&&(v=a),d>b&&(b=d)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,n){const s=e=>{const s=t[e]||t[0],r=s.length,{height:o}=i.canvas,a=o/2,h=i.canvas.width/r;i.moveTo(0,a);let l=0,d=0;for(let t=0;t<=r;t++){const r=Math.round(t*h);if(r>l){const t=a+(Math.round(d*a*n)||1)*(0===e?-1:1);i.lineTo(l,t),l=r,d=0}const o=Math.abs(s[t]||0);o>d&&(d=o)}i.lineTo(l,a)};i.beginPath(),s(0),s(1),i.fill(),i.closePath()}renderWaveform(t,e,i){if(i.fillStyle=this.convertColorValues(e.waveColor),e.renderFunction)return void e.renderFunction(t,i);let n=e.barHeight||1;if(e.normalize){const e=Array.from(t[0]).reduce(((t,e)=>Math.max(t,Math.abs(e))),0);n=e?1/e:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,n):this.renderLineWaveform(t,e,i,n)}renderSingleCanvas(t,e,i,n,s,r,o){const a=this.getPixelRatio(),h=document.createElement("canvas");h.width=Math.round(i*a),h.height=Math.round(n*a),h.style.width=`${i}px`,h.style.height=`${n}px`,h.style.left=`${Math.round(s)}px`,r.appendChild(h);const l=h.getContext("2d");if(this.renderWaveform(t,e,l),h.width>0&&h.height>0){const t=h.cloneNode(),i=t.getContext("2d");i.drawImage(h,0,0),i.globalCompositeOperation="source-in",i.fillStyle=this.convertColorValues(e.progressColor),i.fillRect(0,0,h.width,h.height),o.appendChild(t)}}renderMultiCanvas(t,e,i,n,s,r){const o=this.getPixelRatio(),{clientWidth:a}=this.scrollContainer;if(a*o>=i)return void this.renderSingleCanvas(t,e,a,n,0,s,r);const l=i/o;let d=Math.min(h.MAX_CANVAS_WIDTH,a,l),c={};if(e.barWidth||e.barGap){const t=e.barWidth||.5,i=t+(e.barGap||t/2);d%i!=0&&(d=Math.floor(d/i)*i)}const u=i=>{if(i<0||i>=p)return;if(c[i])return;c[i]=!0;const o=i*d,a=Math.min(l-o,d);if(a<=0)return;const h=t.map((t=>{const e=Math.floor(o/l*t.length),i=Math.floor((o+a)/l*t.length);return t.slice(e,i)}));this.renderSingleCanvas(h,e,a,n,o,s,r)},p=Math.ceil(l/d),m=this.scrollContainer.scrollLeft/l,f=Math.floor(m*p);u(f-1),u(f),u(f+1),p>1&&(this.unsubscribeOnScroll=this.on("scroll",(()=>{const{scrollLeft:t}=this.scrollContainer,e=Math.floor(t/l*p);Object.keys(c).length>h.MAX_NODES&&(s.innerHTML="",r.innerHTML="",c={}),u(e-1),u(e),u(e+1)})))}renderChannel(t,e,i,n){var{overlay:s}=e,r=function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s0&&(o.style.marginTop=`-${a}px`),this.canvasWrapper.style.minHeight=`${a}px`,this.canvasWrapper.appendChild(o);const h=o.cloneNode();this.progressWrapper.appendChild(h),this.renderMultiCanvas(t,r,i,a,o,h)}render(e){return t(this,void 0,void 0,(function*(){var t;this.timeouts.forEach((t=>t())),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",null!=this.options.width&&(this.scrollContainer.style.width="number"==typeof this.options.width?`${this.options.width}px`:this.options.width);const i=this.getPixelRatio(),n=this.scrollContainer.clientWidth,s=Math.ceil(e.duration*(this.options.minPxPerSec||0));this.isScrollable=s>n;const r=this.options.fillParent&&!this.isScrollable,o=(r?n:s)*i;if(this.wrapper.style.width=r?"100%":`${s}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=e,this.emit("render"),this.options.splitChannels)for(let i=0;i1&&t.push(e.getChannelData(1)),this.renderChannel(t,this.options,o,0)}Promise.resolve().then((()=>this.emit("rendered")))}))}reRender(){var t;if(null===(t=this.unsubscribeOnScroll)||void 0===t||t.call(this),delete this.unsubscribeOnScroll,!this.audioData)return;const{scrollWidth:e}=this.scrollContainer,{right:i}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&e!==this.scrollContainer.scrollWidth){const{right:t}=this.progressWrapper.getBoundingClientRect();let e=t-i;e*=2,e=e<0?Math.floor(e):Math.ceil(e),e/=2,this.scrollContainer.scrollLeft+=e}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:n,clientWidth:s}=this.scrollContainer,r=t*n,o=i,a=i+s,h=s/2;if(this.isDragging){const t=30;r+t>a?this.scrollContainer.scrollLeft+=t:r-ta)&&(this.scrollContainer.scrollLeft=r-(this.options.autoCenter?h:0));const t=r-i-h;e&&this.options.autoCenter&&t>0&&(this.scrollContainer.scrollLeft+=Math.min(t,10))}{const t=this.scrollContainer.scrollLeft,e=t/n,i=(t+s)/n;this.emit("scroll",e,i,t,t+s)}}renderProgress(t,e){if(isNaN(t))return;const i=100*t;this.canvasWrapper.style.clipPath=`polygon(${i}% 0, 100% 0, 100% 100%, ${i}% 100%)`,this.progressWrapper.style.width=`${i}%`,this.cursor.style.left=`${i}%`,this.cursor.style.transform=`translateX(-${100===Math.round(i)?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(e,i,n){return t(this,void 0,void 0,(function*(){const t=this.canvasWrapper.querySelectorAll("canvas");if(!t.length)throw new Error("No waveform data");if("dataURL"===n){const n=Array.from(t).map((t=>t.toDataURL(e,i)));return Promise.resolve(n)}return Promise.all(Array.from(t).map((t=>new Promise(((n,s)=>{t.toBlob((t=>{t?n(t):s(new Error("Could not export image"))}),e,i)})))))}))}}h.MAX_CANVAS_WIDTH=8e3,h.MAX_NODES=10;class l extends e{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}class d extends e{constructor(t=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return t(this,void 0,void 0,(function*(){}))}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,this._duration=void 0,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then((e=>{if(e.status>=400)throw new Error(`Failed to fetch ${t}: ${e.status} (${e.statusText})`);return e.arrayBuffer()})).then((e=>this.currentSrc!==t?null:this.audioContext.decodeAudioData(e))).then((e=>{this.currentSrc===t&&(this.buffer=e,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())}))}_play(){var t;if(!this.paused)return;this.paused=!1,null===(t=this.bufferNode)||void 0===t||t.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let e=this.playedDuration*this._playbackRate;e>=this.duration&&(e=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,e),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var t;this.paused=!0,null===(t=this.bufferNode)||void 0===t||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return t(this,void 0,void 0,(function*(){this.paused&&(this._play(),this.emit("play"))}))}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){var e,i;const n=t-this.currentTime;null===(e=this.bufferNode)||void 0===e||e.stop(this.audioContext.currentTime+n),null===(i=this.bufferNode)||void 0===i||i.addEventListener("ended",(()=>{this.bufferNode=null,this.pause()}),{once:!0})}setSinkId(e){return t(this,void 0,void 0,(function*(){return this.audioContext.setSinkId(e)}))}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(t){const e=!this.paused;e&&this._pause(),this.playedDuration=t/this._playbackRate,e&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var t,e;return null!==(t=this._duration)&&void 0!==t?t:(null===(e=this.buffer)||void 0===e?void 0:e.duration)||0}set duration(t){this._duration=t}get volume(){return this.gainNode.gain.value}set volume(t){this.gainNode.gain.value=t,this.emit("volumechange")}get muted(){return this._muted}set muted(t){this._muted!==t&&(this._muted=t,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(t){return/^(audio|video)\//.test(t)}getGainNode(){return this.gainNode}getChannelData(){const t=[];if(!this.buffer)return t;const e=this.buffer.numberOfChannels;for(let i=0;i{this.emit("init");const{peaks:t,duration:e}=this.options;(n||t&&e)&&this.load(n,t,e).catch((()=>null))}))}updateProgress(t=this.getCurrentTime()){return this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),t}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",(()=>{if(!this.isSeeking()){const t=this.updateProgress();this.emit("timeupdate",t),this.emit("audioprocess",t)}})))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",(()=>{const t=this.updateProgress();this.emit("timeupdate",t)})),this.onMediaEvent("play",(()=>{this.emit("play"),this.timer.start()})),this.onMediaEvent("pause",(()=>{this.emit("pause"),this.timer.stop()})),this.onMediaEvent("emptied",(()=>{this.timer.stop()})),this.onMediaEvent("ended",(()=>{this.emit("finish")})),this.onMediaEvent("seeking",(()=>{this.emit("seeking",this.getCurrentTime())})),this.onMediaEvent("error",(t=>{this.emit("error",t.error)})))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",((t,e)=>{this.options.interact&&(this.seekTo(t),this.emit("interaction",t*this.getDuration()),this.emit("click",t,e))})),this.renderer.on("dblclick",((t,e)=>{this.emit("dblclick",t,e)})),this.renderer.on("scroll",((t,e,i,n)=>{const s=this.getDuration();this.emit("scroll",t*s,e*s,i,n)})),this.renderer.on("render",(()=>{this.emit("redraw")})),this.renderer.on("rendered",(()=>{this.emit("redrawcomplete")})),this.renderer.on("dragstart",(t=>{this.emit("dragstart",t)})),this.renderer.on("dragend",(t=>{this.emit("dragend",t)})));{let t;this.subscriptions.push(this.renderer.on("drag",(e=>{if(!this.options.interact)return;let i;this.renderer.renderProgress(e),clearTimeout(t),this.isPlaying()?i=0:!0===this.options.dragToSeek?i=200:"object"==typeof this.options.dragToSeek&&void 0!==this.options.dragToSeek&&(i=this.options.dragToSeek.debounceTime),t=setTimeout((()=>{this.seekTo(e)}),i),this.emit("interaction",e*this.getDuration()),this.emit("drag",e)})))}}initPlugins(){var t;(null===(t=this.options.plugins)||void 0===t?void 0:t.length)&&this.options.plugins.forEach((t=>{this.registerPlugin(t)}))}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach((t=>t())),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),null!=t.mediaControls&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){return t._init(this),this.plugins.push(t),this.subscriptions.push(t.once("destroy",(()=>{this.plugins=this.plugins.filter((e=>e!==t))}))),t}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(t){return this.renderer.setScroll(t)}setScrollTime(t){const e=t/this.getDuration();this.renderer.setScrollPercentage(e)}getActivePlugins(){return this.plugins}loadAudio(e,n,s,r){return t(this,void 0,void 0,(function*(){var t;if(this.emit("load",e),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,!n&&!s){const i=this.options.fetchParams||{};window.AbortController&&!i.signal&&(this.abortController=new AbortController,i.signal=null===(t=this.abortController)||void 0===t?void 0:t.signal);const s=t=>this.emit("loading",t);n=yield o.fetchBlob(e,s,i)}this.setSrc(e,n);const a=yield new Promise((t=>{const e=r||this.getDuration();e?t(e):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",(()=>t(this.getDuration())),{once:!0}))}));if(!e&&!n){const t=this.getMediaElement();t instanceof d&&(t.duration=a)}if(s)this.decodedData=i.createBuffer(s,a||0);else if(n){const t=yield n.arrayBuffer();this.decodedData=yield i.decode(t,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())}))}load(e,i,n){return t(this,void 0,void 0,(function*(){try{return yield this.loadAudio(e,void 0,i,n)}catch(t){throw this.emit("error",t),t}}))}loadBlob(e,i,n){return t(this,void 0,void 0,(function*(){try{return yield this.loadAudio("",e,i,n)}catch(t){throw this.emit("error",t),t}}))}zoom(t){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(t),this.emit("zoom",t)}getDecodedData(){return this.decodedData}exportPeaks({channels:t=2,maxLength:e=8e3,precision:i=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");const n=Math.min(t,this.decodedData.numberOfChannels),s=[];for(let t=0;tMath.abs(s)&&(s=i)}r.push(Math.round(s*i)/i)}s.push(r)}return s}getDuration(){let t=super.getDuration()||0;return 0!==t&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}playPause(){return t(this,void 0,void 0,(function*(){return this.isPlaying()?this.pause():this.play()}))}stop(){this.pause(),this.setTime(0)}skip(t){this.setTime(this.getCurrentTime()+t)}empty(){this.load("",[[0]],.001)}setMediaElement(t){this.unsubscribePlayerEvents(),super.setMediaElement(t),this.initPlayerEvents()}exportImage(){return t(this,arguments,void 0,(function*(t="image/png",e=1,i="dataURL"){return this.renderer.exportImage(t,e,i)}))}destroy(){var t;this.emit("destroy"),null===(t=this.abortController)||void 0===t||t.abort(),this.plugins.forEach((t=>t.destroy())),this.subscriptions.forEach((t=>t())),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}return u.BasePlugin=class extends e{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}_init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}},u.dom=r,u}));