remove add task to phase
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using GozareshgirProgramManager.Application._Common.Interfaces;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Enums;
|
||||
|
||||
namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.AddTaskToPhase;
|
||||
|
||||
/// <summary>
|
||||
/// Command to add a task to an existing phase
|
||||
/// </summary>
|
||||
public record AddTaskToPhaseCommand(
|
||||
Guid PhaseId,
|
||||
string Name,
|
||||
string? Description = null,
|
||||
ProjectTaskPriority Priority = ProjectTaskPriority.Medium,
|
||||
int OrderIndex = 0,
|
||||
DateTime? DueDate = null
|
||||
) : IBaseCommand;
|
||||
@@ -1,53 +0,0 @@
|
||||
using GozareshgirProgramManager.Application._Common.Interfaces;
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Domain._Common;
|
||||
using GozareshgirProgramManager.Domain.ProjectAgg.Repositories;
|
||||
using MediatR;
|
||||
|
||||
namespace GozareshgirProgramManager.Application.Modules.Projects.Commands.AddTaskToPhase;
|
||||
|
||||
public class AddTaskToPhaseCommandHandler : IRequestHandler<AddTaskToPhaseCommand, OperationResult>
|
||||
{
|
||||
private readonly IProjectPhaseRepository _phaseRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public AddTaskToPhaseCommandHandler(
|
||||
IProjectPhaseRepository phaseRepository,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_phaseRepository = phaseRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<OperationResult> Handle(AddTaskToPhaseCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get phase
|
||||
var phase = await _phaseRepository.GetByIdAsync(request.PhaseId);
|
||||
if (phase == null)
|
||||
{
|
||||
return OperationResult.NotFound("فاز یافت نشد");
|
||||
}
|
||||
|
||||
// Add task
|
||||
var task = phase.AddTask(request.Name, request.Description);
|
||||
task.SetPriority(request.Priority);
|
||||
task.SetOrderIndex(request.OrderIndex);
|
||||
|
||||
if (request.DueDate.HasValue)
|
||||
{
|
||||
task.SetDates(dueDate: request.DueDate);
|
||||
}
|
||||
|
||||
// Save changes
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return OperationResult.Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return OperationResult.Failure($"خطا در افزودن تسک: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,15 +41,7 @@ public class ProjectPhase : ProjectHierarchyNode
|
||||
public ProjectDeployStatus DeployStatus { get; set; }
|
||||
|
||||
#region Task Management
|
||||
|
||||
public ProjectTask AddTask(string name, string? description = null)
|
||||
{
|
||||
var task = new ProjectTask(name, Id, description);
|
||||
_tasks.Add(task);
|
||||
AddDomainEvent(new TaskAddedEvent(task.Id, Id, name));
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
public void RemoveTask(Guid taskId)
|
||||
{
|
||||
var task = _tasks.FirstOrDefault(t => t.Id == taskId);
|
||||
|
||||
Reference in New Issue
Block a user