new task changes and leaveApplcation bug fixed

This commit is contained in:
samsys
2024-07-18 04:31:43 +03:30
parent aafafa27ce
commit 4a84032c16
48 changed files with 4992 additions and 1348 deletions

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
@@ -7,6 +7,8 @@
<ItemGroup>
<ProjectReference Include="..\AccountManagement.Application.Contracts\AccountManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\AccountManagement.Domain\AccountManagement.Domain.csproj" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>
</Project>

View File

@@ -10,9 +10,10 @@ using AccountManagement.Domain.AssignAgg;
using AccountManagement.Domain.MediaAgg;
using AccountManagement.Domain.TaskAgg;
using IPE.SmsIrClient.Models.Results;
using Microsoft.AspNetCore.Http;
using TaskManager.Domain.PositionAgg;
using System.Reflection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
namespace AccountManagement.Application;
@@ -24,9 +25,11 @@ public class TaskApplication : ITaskApplication
private readonly IPositionRepository _positionRepository;
private readonly IAssignRepository _assignRepository;
private readonly IHttpContextAccessor _contextAccessor;
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly IAuthHelper _authHelper;
public TaskApplication(ITaskRepository taskRepository, IAccountRepository accountRepository, IMediaRepository mediaRepository, IAssignRepository assignRepository, IHttpContextAccessor contextAccessor, IPositionRepository positionRepository)
public TaskApplication(ITaskRepository taskRepository, IAccountRepository accountRepository, IMediaRepository mediaRepository, IAssignRepository assignRepository, IHttpContextAccessor contextAccessor, IPositionRepository positionRepository, IWebHostEnvironment webHostEnvironment, IAuthHelper authHelper)
{
_taskRepository = taskRepository;
_accountRepository = accountRepository;
@@ -34,6 +37,8 @@ public class TaskApplication : ITaskApplication
_assignRepository = assignRepository;
_contextAccessor = contextAccessor;
_positionRepository = positionRepository;
_webHostEnvironment = webHostEnvironment;
_authHelper = authHelper;
}
//غیرفعال سازی تسک
public OperationResult DeActiveTask(long TaskId)
@@ -127,12 +132,45 @@ public class TaskApplication : ITaskApplication
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();
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
@@ -162,7 +200,7 @@ public class TaskApplication : ITaskApplication
if (command.Document1?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -185,7 +223,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document2?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -208,7 +246,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document3?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -231,7 +269,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document4?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -254,7 +292,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document5?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -277,7 +315,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document6?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -308,7 +346,7 @@ public class TaskApplication : ITaskApplication
if (command.Voice?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -468,7 +506,7 @@ public class TaskApplication : ITaskApplication
if (command.Document1?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -488,7 +526,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document2?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -508,7 +546,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document3?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -528,7 +566,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document4?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -548,8 +586,8 @@ public class TaskApplication : ITaskApplication
}
if (command.Document5?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
"Task", $"{task.id}");
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
string filepath = Path.Combine(path, command.Document5.FileName);
@@ -568,7 +606,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document6?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -595,7 +633,7 @@ public class TaskApplication : ITaskApplication
if (command.Voice?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -678,8 +716,8 @@ public class TaskApplication : ITaskApplication
if (command.Document1?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
"Task", $"{task.id}");
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
string filepath = Path.Combine(path, command.Document1.FileName);
@@ -698,7 +736,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document2?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -718,7 +756,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document3?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -738,8 +776,8 @@ public class TaskApplication : ITaskApplication
}
if (command.Document4?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
"Task", $"{task.id}");
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
string filepath = Path.Combine(path, command.Document4.FileName);
@@ -758,7 +796,7 @@ public class TaskApplication : ITaskApplication
}
if (command.Document5?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -778,8 +816,8 @@ public class TaskApplication : ITaskApplication
}
if (command.Document6?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
"Task", $"{task.id}");
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
string filepath = Path.Combine(path, command.Document6.FileName);
@@ -805,7 +843,7 @@ public class TaskApplication : ITaskApplication
if (command.Voice?.Length > 0)
{
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
var path = Path.Combine($"{_webHostEnvironment.ContentRootPath}", "Storage",
"Task", $"{task.id}");
Directory.CreateDirectory(path);
@@ -842,9 +880,31 @@ public class TaskApplication : ITaskApplication
return test;
}
public List<TaskViewModel> GetSelfTasks(TaskSearchModel searchModel)
{
return _taskRepository.GetSelfTasks(searchModel);
}
public List<TaskViewModel> GetAllNotSelfIncludedTasks(TaskSearchModel searchModel)
{
return _taskRepository.GetAllNotSelfIncludedTasks(searchModel);
}
public List<TaskViewModel> GetReceivedTasks(TaskSearchModel searchModel)
{
return _taskRepository.GetReceivedTasks(searchModel);
}
public List<TaskViewModel> GetSentTasks(TaskSearchModel searchModel)
{
return _taskRepository.GetSentTasks(searchModel);
}
//ساخت درخواست مهلت
public OperationResult CreateRequestTime(CreateTaskTimeRequest command)
{
var accountId = _authHelper.CurrentAccountId();
var operation = new OperationResult();
if (command.TaskId == 0)
{
@@ -860,10 +920,19 @@ public class TaskApplication : ITaskApplication
{
return operation.Failed("مهلت درخواستی خود را وارد کنید");
}
var task = _taskRepository.Get(command.TaskId);
var requestTime = command.RequestTime.ToGeorgianDateTime();
task.CreateTimeRequest(requestTime, command.Description);
if (task.SenderId==accountId)
{
task.ChangeTimeTask(requestTime);
}
else
{
task.CreateTimeRequest(requestTime, command.Description);
}
_taskRepository.SaveChanges();
return operation.Succcedded(task.id);
}
@@ -893,6 +962,7 @@ public class TaskApplication : ITaskApplication
//ساخت درخواست کنسل
public OperationResult CreateCancelRequest(CreateTaskCancel command)
{
var accountId = _authHelper.CurrentAccountId();
var operation = new OperationResult();
if (string.IsNullOrWhiteSpace(command.Description))
{
@@ -905,6 +975,10 @@ public class TaskApplication : ITaskApplication
}
var task = _taskRepository.Get(command.TaskId);
task.CreateCancelRequest(command.Description);
if (task.SenderId==accountId)
{
task.AcceptCancelRequest();
}
_taskRepository.SaveChanges();
return operation.Succcedded(task.id);
}
@@ -928,6 +1002,7 @@ public class TaskApplication : ITaskApplication
//انجام شدن تسک
public OperationResult CreateCompleteTaskRequest(CompleteTaskViewModel command)
{
var accountId = _authHelper.CurrentAccountId();
var operation = new OperationResult();
if (!_taskRepository.Exists(x => x.id == command.Id))
{
@@ -935,6 +1010,10 @@ public class TaskApplication : ITaskApplication
}
var task = _taskRepository.Get(command.Id);
task.CompleteRequest(command.Description);
if (task.SenderId==accountId)
{
task.Completed();
}
_taskRepository.SaveChanges();
return operation.Succcedded(task.id);
}