54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
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}");
|
|
}
|
|
}
|
|
}
|