public async Task <ICollection <NotificacionQueueItem> > GetByStatusAsync(QueueStatus queueStatus) { using (IDbConnection db = new SqlConnection(connectionString)) { string sqlCommand = "SELECT * FROM dbo.NotificationQ WHERE Status = @status"; string status = queueStatus.ToString(); var notificationQList = await db.QueryAsync <Entities.NotificationQ>(sqlCommand, new { status }); var outputResult = new List <NotificacionQueueItem>(); if (notificationQList == null) { return(outputResult); } foreach (var notificacionQ in notificationQList) { var actionType = (ActionType)Enum.Parse(typeof(ActionType), notificacionQ.ActionType); var qStatus = (QueueStatus)Enum.Parse(typeof(QueueStatus), notificacionQ.Status); outputResult.Add(NotificacionQueueItem.Load(notificacionQ.ID, notificacionQ.FuncionarioID, notificacionQ.UserName, actionType, qStatus, notificacionQ.CreateDate, notificacionQ.ModifyDate, notificacionQ.ErrorMessage)); } return(outputResult); } }
public async Task <NotificationQOutput> Execute(NotificacionQueueItem queueItem) { await _notificacionQueueWriteOnlyRepository.Update(queueItem); return(new NotificationQOutput(queueItem.ID, queueItem.FuncionarioID, queueItem.UserName, queueItem.ActionType.ToString(), queueItem.Status.ToString(), queueItem.CreateDate, queueItem.ModifyDate, queueItem.ErrorMessage)); }
public async Task <NotificationQOutput> Execute(Guid id, int funcionarioID, string userName, string actionType, string queueStatus, DateTime createDate, DateTime modifyDate, string errorMessage) { var actionTypeEnum = (ActionType)Enum.Parse(typeof(ActionType), actionType); var queueStatusEnum = (QueueStatus)Enum.Parse(typeof(QueueStatus), queueStatus); var queueItem = NotificacionQueueItem.Load(id, funcionarioID, userName, actionTypeEnum, queueStatusEnum, createDate, modifyDate, errorMessage); return(new NotificationQOutput(queueItem.ID, queueItem.FuncionarioID, queueItem.UserName, queueItem.ActionType.ToString(), queueItem.Status.ToString(), queueItem.CreateDate, queueItem.ModifyDate, queueItem.ErrorMessage)); }
public async Task <bool> Execute(string webServerURL, string fromAddress) { var queueItems = await _getNotificationQUserCase.ExecuteList(QueueStatus.Queued); var result = false; foreach (var item in queueItems) { try { var userProfile = await _funcionarioUsuarioReadOnlyRepository.Get(item.UserName); if (userProfile == null) { throw new ApplicationException($"El usuario {item.UserName} no tiene un Funcionario asociado"); } var cabeceraNotificacion = new CabeceraEmailOutput(fromAddress, userProfile.Email, String.Empty, "SRDP - Se ha creado un nuevo formulario de Declaración Patrimonial para su usuario", DateTime.Now); var gestionVigente = await _getGestionesUserCase.GestionVigente(); var declaracion = new Declaracion(item.FuncionarioID, new Gestion(gestionVigente.Anio, gestionVigente.FechaInicio, gestionVigente.FechaFinal, gestionVigente.Vigente), DateTime.Now, EstadoDeclaracion.Nueva); await _declaracionWriteOnlyRepository.Add(declaracion); string mensaje = CreateMensajeBody(webServerURL, declaracion); var notificacion = new Notificacion(item.FuncionarioID, TipoNotificacion.Email, cabeceraNotificacion.JsonSerialize(), mensaje, false, false); await _sendNotificacionUserCase.Execute(new NotificacionOutput(notificacion.ID, notificacion.FuncionarioID, notificacion.TipoNotificacion.ToString(), notificacion.Cabecera, notificacion.Mensaje, notificacion.Procesado, notificacion.Leido, notificacion.FechaCreacion, notificacion.FechaModificacion)); var notificacionProcesada = await _updateNotificationQUserCase.Execute(new NotificacionQueueItem(item.FuncionarioID, item.UserName, ActionType.Alta, QueueStatus.Processed)); var queueItem = NotificacionQueueItem.Load(item.ID, item.FuncionarioID, item.UserName, ActionType.Alta, QueueStatus.Processed, item.CreateDate, DateTime.Now, String.Empty); await _updateNotificationQUserCase.Execute(queueItem); result = result && true; } catch (Exception ex) { var queueItem = NotificacionQueueItem.Load(item.ID, item.FuncionarioID, item.UserName, ActionType.Alta, QueueStatus.Error, item.CreateDate, DateTime.Now, ex.Message); await _updateNotificationQUserCase.Execute(queueItem); throw; } } return(result); }
public async Task Update(NotificacionQueueItem notificacionQueueItem) { using (IDbConnection db = new SqlConnection(connectionString)) { string sqlCommand = "UPDATE dbo.NotificationQ SET FuncionarioID = @FuncionarioID, UserName = @UserName, ActionType = @ActionType, Status = @Status, ErrorMessage = @ErrorMessage, CreateDate = @CreateDate, ModifyDate = @ModifyDate WHERE ID = @ID"; DynamicParameters notificationQParameters = new DynamicParameters(); notificationQParameters.Add("@ID", notificacionQueueItem.ID); notificationQParameters.Add("@FuncionarioID", notificacionQueueItem.FuncionarioID, DbType.Int32); notificationQParameters.Add("@UserName", notificacionQueueItem.UserName, DbType.AnsiString); notificationQParameters.Add("@ActionType", notificacionQueueItem.ActionType.ToString(), DbType.AnsiString); notificationQParameters.Add("@Status", notificacionQueueItem.Status.ToString(), DbType.AnsiString); notificationQParameters.Add("@ErrorMessage", notificacionQueueItem.ErrorMessage, DbType.String); notificationQParameters.Add("@CreateDate", notificacionQueueItem.CreateDate, DbType.DateTime); notificationQParameters.Add("@ModifyDate", notificacionQueueItem.ModifyDate, DbType.DateTime); int rows = await db.ExecuteAsync(sqlCommand, notificationQParameters); } }
public async Task <NotificacionQueueItem> GetAsync(Guid id) { using (IDbConnection db = new SqlConnection(connectionString)) { string sqlCommand = "SELECT * FROM dbo.NotificationQ WHERE ID = @id"; var notificacionQ = await db.QueryFirstOrDefaultAsync <Entities.NotificationQ>(sqlCommand, new { id }); if (notificacionQ == null) { return(null); } var actionType = (ActionType)Enum.Parse(typeof(ActionType), notificacionQ.ActionType); var status = (QueueStatus)Enum.Parse(typeof(QueueStatus), notificacionQ.Status); return(NotificacionQueueItem.Load(notificacionQ.ID, notificacionQ.FuncionarioID, notificacionQ.UserName, actionType, status, notificacionQ.CreateDate, notificacionQ.ModifyDate, notificacionQ.ErrorMessage)); } }