/// <summary> /// Handle /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public override async Task <bool> Handle(CreateAlertByEmployeeRequest request, CancellationToken cancellationToken) { await ValidacionEmpleado(request.IdEmployee).ConfigureAwait(false); AlertaServiciosMedicos newAlerta = new AlertaServiciosMedicos() { Comentario = request.Comment, Titulo = request.Title, FechaNotificacion = request.CurrentDeviceDateTime, IdEmpleado = request.IdEmployee, Leido = false }; repository.Add(newAlerta); await repository.SaveChangesAsync().ConfigureAwait(false); return(true); }
/// <summary> /// Handle /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public override async Task <bool> Handle(CreateAlertByDivisionRequest request, CancellationToken cancellationToken) { var query = repositoryEmpleado.GetAll().Where(c => c.IdFichaLaboralNavigation.IdDivision == request.IdDivision); if (request.InterAcciona.HasValue && request.InterAcciona.Value) { query = query.Where(c => c.InterAcciona.Value); } if (request.IdEstado.HasValue && request.IdEstado.Value > 0) { query = query.Where(c => c.Pasaporte.Any(d => d.Activo.Value && d.IdEstadoPasaporte == request.IdEstado.Value)); } // obtenemos todos los identificadores de todos empleados. List <int> idEmpl = await query.Select(c => c.Id).ToListAsync().ConfigureAwait(false); SendTimeOperationToLogger("GetIdEmployees"); List <AlertaServiciosMedicos> listaAlerts = new List <AlertaServiciosMedicos>(); foreach (var id in idEmpl) { AlertaServiciosMedicos newAlerta = new AlertaServiciosMedicos() { Comentario = request.Comment, Titulo = request.Title, FechaNotificacion = request.CurrentDeviceDateTime, IdEmpleado = id, LastAction = "CREATE", LastActionDate = DateTime.UtcNow, Leido = false }; listaAlerts.Add(newAlerta); } await repository.BulkInsertAsync(listaAlerts).ConfigureAwait(false); SendTimeOperationToLogger("Bulk"); return(true); }
/// <summary> /// Handle /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public override async Task <bool> Handle(AlertReadRequest request, CancellationToken cancellationToken) { AlertaServiciosMedicos alerta = await repository.GetAll().FirstOrDefaultAsync(c => c.Id == request.IdAlert && c.IdEmpleado == request.IdEmployee).ConfigureAwait(false); if (alerta == null) { throw new MultiMessageValidationException(new ErrorMessage() { Code = "NOT_FOUND", Message = string.Format(ValidatorsMessages.NOT_FOUND, ValidatorFields.Alerta) }); } alerta.Leido = true; repository.Update(alerta); await repository.SaveChangesAsync().ConfigureAwait(false); return(true); }
/// <summary> /// Handle /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public override async Task <bool> Handle(PanicRegisterRequest request, CancellationToken cancellationToken) { Empleado empleado = await ValidacionEmpleado(request.IdEmployee).ConfigureAwait(false); // CReamos la alerta al empleado responsable if (empleado.IdFichaLaboralNavigation != null && empleado.IdFichaLaboralNavigation.IdResponsableDirecto.HasValue) { Empleado empleadoRespo = await repositoryEmpleado.GetAll().FirstOrDefaultAsync(c => c.Id == empleado.IdFichaLaboralNavigation.IdResponsableDirecto.Value).ConfigureAwait(false); if (empleadoRespo != null) { // Comprobación de que en los últimos síntomas, alguno fue true---------------------- var resultadosSintomas = await repositoryEmpleado.GetAll() .Include(e => e.IdFichaMedicaNavigation) .ThenInclude(fm => fm.ResultadoEncuestaSintomas) .Where(e => e.Id == request.IdEmployee) .Select(e => e.IdFichaMedicaNavigation) .Where(fm => !fm.Deleted) .SelectMany(fm => fm.ResultadoEncuestaSintomas) .Where(res => !res.Deleted) .ToListAsync().ConfigureAwait(false); var ultimosResul = resultadosSintomas.GroupBy(res => res.LastActionDate.ToString("yyyyMMdd_HHmmss.fff")) .OrderByDescending(x => x.Key) .Select(c => new { c.Key, anyTrue = c.Any(res => res.Valor) }) .FirstOrDefault(); if (ultimosResul == null || ultimosResul.anyTrue == false) { return(true); // lo mejor sería devolver false pero no se sabe que espera la app } // ----------------------------------------------------------------------------------- // creamos la alerta al empleado responsable AlertaServiciosMedicos newAlerta = new AlertaServiciosMedicos() { Comentario = string.Format(ValidatorsMessages.PANIC_COMMIT_ALERT, empleado.NombreCompleto), Titulo = ValidatorsMessages.PANIC_TITLE_ALERT, FechaNotificacion = request.CurrentDeviceDateTime, IdEmpleado = empleadoRespo.Id, Leido = false }; repository.Add(newAlerta); await repository.SaveChangesAsync().ConfigureAwait(false); } else { throw new MultiMessageValidationException(new ErrorMessage() { Code = "PANIC_ALERT_NO_RESPONSABLE", Message = ValidatorsMessages.PANIC_ALERT_NO_RESPONSABLE }); } } else { throw new MultiMessageValidationException(new ErrorMessage() { Code = "PANIC_ALERT_NO_RESPONSABLE", Message = ValidatorsMessages.PANIC_ALERT_NO_RESPONSABLE }); } return(true); }