Api/Brizco.Core/EntityServices/Handlers/ShiftPlans/CompleteShiftPlanCommandHan...

30 lines
1.3 KiB
C#

namespace Brizco.Core.EntityServices.Handlers.ShiftPlans;
public class CompleteShiftPlanCommandHandler(IMediator mediator, IRepositoryWrapper repositoryWrapper) : IRequestHandler<CompleteShiftPlanCommand, bool>
{
public async Task<bool> Handle(CompleteShiftPlanCommand request, CancellationToken cancellationToken)
{
var shiftPlan = await repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shiftPlan == null)
throw new AppException("Shift plan not found", ApiResultStatusCode.NotFound);
shiftPlan.CompletePlan(request.CompleteDescription, request.CompletePercent);
repositoryWrapper.SetRepository<ShiftPlan>().Update(shiftPlan);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
await mediator.Send(new CompleteActivitiesCommand(request.CompleteActivities), cancellationToken);
var shiftPlanUsers = await repositoryWrapper.SetRepository<ShiftPlanUser>()
.TableNoTracking.Where(s => s.ShiftPlanId == request.Id)
.Select(ShiftPlanUserMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
foreach (var shiftPlanUser in shiftPlanUsers)
{
var message = $"{shiftPlanUser.UserFullName}";
}
return true;
}
}