public void PollforEventResultReadyNotification() { var notificationTypes = _notificationTypeRepository.GetAll(); var notificationIsActive = notificationTypes.Any(nt => (nt.NotificationTypeAlias == NotificationTypeAlias.EventResultReadyNotification) && nt.IsActive); if (!notificationIsActive) { return; } var eventIds = _eventCustomerResultRepository.GetEventIdsForEventResultReadyNotiFication().ToArray(); if (eventIds.Count() == 0) { return; } var createdByOrgRoleUserId = _organizationRoleUserRepository.GetOrganizationRoleUserIdsForRole((long)Roles.FranchisorAdmin).First(); foreach (var eventId in eventIds) { try { var notificationSent = _eventNotificationRepository.GetByEventId(eventId, NotificationTypeAlias.EventResultReadyNotification); if (notificationSent != null) { continue; } var hospitalPartnerId = _hospitalPartnerRepository.GetHospitalPartnerIdForEvent(eventId); if (hospitalPartnerId >= 1) { var partnerReleaseSinged = _eventCustomerResultRepository.CheckAnyCustomerResultsReadyAndSignedPartnerRelease(eventId); if (partnerReleaseSinged) { var allResultsReady = _eventCustomerResultRepository.CheckAllCustomerResultsReadyForEvent(eventId); if (!allResultsReady) { _logger.Info(string.Format("All Results are not ready For Event Id {0}", eventId)); } var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationId(hospitalPartnerId); var hospitalFacilityIds = _hospitalFacilityRepository.GetSelectedHospitalFacilityIdForEvent(eventId); if (hospitalFacilityIds != null && hospitalFacilityIds.Any()) { foreach (var hospitalFacilityId in hospitalFacilityIds) { var hospitalFacilityOrgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationId(hospitalFacilityId); if (hospitalFacilityOrgRoleUsers != null && hospitalFacilityOrgRoleUsers.Any()) { orgRoleUsers = orgRoleUsers.Concat(hospitalFacilityOrgRoleUsers); } } } var userIds = orgRoleUsers.Select(oru => oru.UserId).ToList(); var users = _userRepository.GetUsers(userIds); var eventHostViewData = _eventService.GetById(eventId); foreach (var user in users) { if (user.Email == null || string.IsNullOrEmpty(user.Email.ToString())) { continue; } var model = _emailNotificationModelsFactory.GetEventResultReadyNotificationViewModel(user, eventHostViewData); var notifications = _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EventResultReadyNotification, EmailTemplateAlias.EventResultReadyNotification, model, new string[] { user.Email.ToString() }, user.Id, createdByOrgRoleUserId, "Event Result Ready Notification"); if (notifications != null && notifications.Any()) { var eventNotification = new EventNotification { EventId = eventId, NotificationId = notifications.First().Id }; _eventNotificationRepository.Save(eventNotification); } } } } //var account = _corporateAccountRepository.GetbyEventId(eventId); //if (account != null && account.Id > 0 && account.SendEventResultReadyNotification) //{ // var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationIdAndRoleId(account.Id, (long)Roles.CorporateAccountCoordinator); // var userIds = orgRoleUsers.Select(oru => oru.UserId).ToList(); // var users = _userRepository.GetUsers(userIds); // var eventHostViewData = _eventService.GetById(eventId); // foreach (var user in users) // { // if (user.Email == null || string.IsNullOrEmpty(user.Email.ToString())) // continue; // var model = _emailNotificationModelsFactory.GetEventResultReadyNotificationViewModel(user, eventHostViewData); // var notifications = _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EventResultReadyNotification, EmailTemplateAlias.EventResultReadyNotification, model, new string[] { user.Email.ToString() }, user.Id, createdByOrgRoleUserId, "Event Result Ready Notification"); // if (notifications != null && notifications.Any()) // { // var eventNotification = new EventNotification { EventId = eventId, NotificationId = notifications.First().Id }; // _eventNotificationRepository.Save(eventNotification); // } // } //} } catch (Exception ex) { _logger.Error(string.Format("Event Result Ready Notification Error For Event Id {0} \nMessage:{1} \nStackTrace: {2}", eventId, ex.Message, ex.StackTrace)); } } }