public async Task SaveNotificationAsync(string actionCode) { try { var action = await AuditUnitOfWork.ActionRepository.GetFirstAsync(a => a.Code == actionCode); if (action.SendNotification) { var ActionUserGroup = await AuditUnitOfWork.ActionUserGroupRepository.GetByActionCode(actionCode); await CreateNotification(actionCode, ActionUserGroup); } } catch (Exception ex) { await ErrorLoger.Log(ex); } }
void GetControllerViewActionsInfo(System.Type controllerType) { var controllerMethods = controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance); if (controllerMethods.IsNullOrEmpty()) { ErrorLoger.Log("Контроллер не содержит методов, пригодных для отображения View", parameters: new LogParameter[] { new LogParameter("Имя типа контроллера", controllerType.FullName) }); } else { foreach (var method in controllerMethods) { //аттрибут методов, которые возвращают View var viewMethodAttribute = method.GetCustomAttribute <AvailableViewActionAttribute>(); if (viewMethodAttribute == null) { continue; } //информация для ссылки на метод и его отображения var cvmi = new ControllerViewMethodInfo(method.Name, viewMethodAttribute.DisplayName); m_actions.Add(cvmi); if (viewMethodAttribute.IsDefault) { DefaultActionInfo = cvmi; } } if (!HasActions) { ErrorLoger.Log("Контроллер не содержит методов, помеченных аттрибутом AvailableViewActionAttribute", parameters: new LogParameter[] { new LogParameter("Имя типа контроллера", controllerType.FullName) }); } } }
public async Task CheckNotificationsAndSend() { try { var notSentNotifications = await AuditUnitOfWork.NotificationRepository.GetAsync(a => a.Sent == false); if (notSentNotifications.Any()) { List <NotificationLog> notificationLogs = new List <NotificationLog>(); notSentNotifications.ForEach(async notification => { var result = await EmailService.SendAsync("", notification.ToEmails.Split(',').ToList(), "", notification.Message); if (result.Succeeded) { notification.Sent = result.Succeeded; AuditUnitOfWork.NotificationRepository.Update(notification); } NotificationLog notificationLog = new NotificationLog(); notificationLog.NotificationId = notification.Id; notificationLog.SendSucceeded = result.Succeeded; notificationLog.ErrorMessage = result.ErrorMessage; notificationLog.TryDate = DateTime.Now; notificationLogs.Add(notificationLog); }); await AuditUnitOfWork.NotificationLogRepository.AddAsync(notificationLogs); await AuditUnitOfWork.SaveAsync(); } } catch (Exception ex) { await ErrorLoger.Log(ex); } }
public async Task SaveNotificationsAsync(string actionCode, List <AuditTrail> auditList) { try { var action = AuditUnitOfWork.ActionRepository.GetBySelector(a => new ActionSendNotificationProj { SendNotification = a.SendNotification }, a => a.Code == actionCode).FirstOrDefault(); if (action != null && action.SendNotification) { if (auditList.Count > 0) { foreach (var audit in auditList) { await SaveNotificationAsync(actionCode, audit.EntityName); } } } } catch (Exception ex) { await ErrorLoger.Log(ex); } }
async Task CreateNotification(string actionCode, ActionUserGroup ActionUserGroup, string EntityName = "") { try { if (ActionUserGroup != null) { Notification Notification = new Notification { Audit_ActionCode = actionCode, From = ActionUserGroup.From, Subject = ActionUserGroup.Subject, ToEmails = ActionUserGroup.ToEmails, Message = ActionUserGroup.Message + (!string.IsNullOrEmpty(EntityName) ? $" - EntityName : {EntityName}" : ""), Sent = false }; await AuditUnitOfWork.NotificationRepository.AddAsync(Notification); } } catch (Exception ex) { await ErrorLoger.Log(ex); } }