public void PollForLockCorporateEvent() { try { var corporateAccounts = _corporateAccountRepository.GetCorporateAccountForLockEvent(); if (corporateAccounts.IsNullOrEmpty()) { _logger.Info("No corporate account has been set for lock event."); return; } var createdByOrgRoleUserId = _organizationRoleUserRepository.GetOrganizationRoleUserIdsForRole((long)Roles.FranchisorAdmin).First(); foreach (var corporateAccount in corporateAccounts) { try { if (!corporateAccount.EventLockDaysCount.HasValue) { continue; } var eventDate = DateTime.Now.AddDays(corporateAccount.EventLockDaysCount.Value).Date; var eventIds = _eventRepository.LockCorporateEvents(corporateAccount.Id, eventDate); if (eventIds != null && eventIds.Any()) { foreach (var eventId in eventIds) { _logger.Info(string.Format("Events locked for Corporate: {0} and EventId : {1}", corporateAccount.Tag, eventId)); } var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationIdAndRoleId(corporateAccount.Id, (long)Roles.CorporateAccountCoordinator); if (orgRoleUsers != null && orgRoleUsers.Any()) { var userIds = orgRoleUsers.Select(oru => oru.UserId).ToList(); var users = _userRepository.GetUsers(userIds); foreach (var eventId in eventIds) { var eventHostViewData = _eventService.GetById(eventId); foreach (var user in users) { if (user.Email == null || string.IsNullOrEmpty(user.Email.ToString())) { continue; } var model = _emailNotificationModelsFactory.GetEventLockedNotificationViewModel(user, eventHostViewData); _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.EventLocked, EmailTemplateAlias.EventLocked, model, new string[] { user.Email.ToString() }, user.Id, createdByOrgRoleUserId, "Event Lock Notification"); } } } else { _logger.Info("No Nurse Practitioner Pr for Corporate: " + corporateAccount.Tag); } } else { _logger.Info("No Events locked for Corporate: " + corporateAccount.Tag); } } catch (Exception ex) { _logger.Error(string.Format("Error while locking events for corporate {0}. Messsage: {1} \n StackTrace {2}", corporateAccount.Tag, ex.Message, ex.StackTrace)); } } } catch (Exception ex) { _logger.Error(string.Format("Error while polling events for corporate. Messsage: {0} \n StackTrace {1}", ex.Message, ex.StackTrace)); } }