using Brizco.Domain.Entities.ShiftPlans; namespace Brizco.Core.QuartzServices.Handlers; public class CreateShiftPlanNotificationsCommandHandler(IMediator mediator,IRepositoryWrapper repositoryWrapper) : IRequestHandler { public async Task Handle(CreateShiftPlanNotificationsCommand request, CancellationToken cancellationToken) { if (request.InStart) { await mediator.Send(new SetShiftPlanNotificationScheduleCommand(request.ShiftPlanId), cancellationToken); } else { var shiftPlan = await repositoryWrapper.SetRepository().TableNoTracking .Where(s => s.Id == request.ShiftPlanId) .Select(ShiftPlanMapper.ProjectToSDto) .FirstOrDefaultAsync(cancellationToken); if (shiftPlan == null) throw new BaseApiException(ApiResultStatusCode.NotFound, "ShiftPlan not found in create shift plan notification"); var shiftPlanUsers = await repositoryWrapper.SetRepository() .TableNoTracking .Where(f => f.ShiftPlanId == request.ShiftPlanId) .ToListAsync(cancellationToken); foreach (var shiftPlanUser in shiftPlanUsers) { var completeShiftMessageForUser = $""; await mediator.Send( new CreateNotificationCommand(completeShiftMessageForUser, shiftPlanUser.UserId, shiftPlan.ComplexId), cancellationToken); } } return true; } }