Example #1
0
        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));
            }
        }
Example #2
0
        public void PollforEventResultReadyNotification()
        {
            var notificationTypes = _notificationTypeRepository.GetAll();

            var notificationIsActive = notificationTypes.Any(nt => (nt.NotificationTypeAlias == NotificationTypeAlias.EventResultReadyNotification) && nt.IsActive);

            if (!notificationIsActive)
            {
                return;
            }

            if (!_cutofDate.HasValue)
            {
                _logger.Info("Please provide cut of date to sent Corporate Event Result Ready Notification");
                return;
            }

            var eventIds = _eventCustomerResultRepository.GetEventIdsForCorporateAccountEventResultReadyNotiFication(_cutofDate.Value).ToArray();

            if (eventIds.Count() == 0)
            {
                _logger.Info("No Corporate Event found for sending Result Ready notification");
                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 && notificationSent.IsForCorporateAccount)
                    {
                        continue;
                    }

                    var account = _corporateAccountRepository.GetbyEventId(eventId);
                    if (account != null && account.SendEventResultReadyNotification)
                    {
                        var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsersByOrganizationIdAndRoleId(account.Id, (long)Roles.CorporateAccountCoordinator);

                        if (!orgRoleUsers.IsNullOrEmpty())
                        {
                            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,
                                        IsForCorporateAccount = true
                                    };
                                    _eventNotificationRepository.SaveForCorporateAccount(eventNotification);
                                }
                            }
                        }
                        else
                        {
                            _logger.Info(string.Format("No coordinator Attached to Event For Account {0}  is Off", account.Id));
                        }
                    }
                    else
                    {
                        _logger.Info(string.Format("Send Event Result Ready Notification For Account {0}  is Off", account.Id));
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(string.Format("Corporat Event Result Ready Notification Error For Event Id {0} \nMessage:{1} \nStackTrace: {2}", eventId, ex.Message, ex.StackTrace));
                }
            }
        }