예제 #1
0
        //[HttpPost]
        public JsonResult SendConfirmationSms(long eventId, long customerId)
        {
            var currentSession = _sessionContext.UserSession;
            var eventCustomer  = _eventCustomerRepository.Get(eventId, customerId);
            var customer       = _customerRepository.GetCustomer(customerId);
            var message        = string.Empty;

            if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false)
            {
                _logger.Info("customer has not Subscribed for SMS customerId " + customer.CustomerId);

                message = "customer has not Subscribed for SMS";
                _logger.Info(message);

                return(Json(new { message }, JsonRequestBehavior.AllowGet));
            }

            if (eventCustomer.EnableTexting)
            {
                var account = _corporateAccountRepository.GetbyEventId(eventId);
                if (account != null && !account.EnableSms)
                {
                    message = "SMS has been disabled for Corporate Account Tag: " + account.Tag;
                    _logger.Info(message);

                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }

                var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.Id, NotificationTypeAlias.AppointmentConfirmation);
                var messageCount           = (messageAlreadySentList != null && messageAlreadySentList.Any()) ? messageAlreadySentList.Count() : 0;

                if (account != null && messageCount >= account.MaximumSms)
                {
                    _logger.Info("Maximum SMS has Been Sent ");
                    _logger.Info(string.Format("Allowed SMS {0}, SMS Already Sent {0} " + account.MaximumSms, messageCount));
                    message = "Maximum SMS limit has been reached.";
                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }

                if (account == null && messageCount > 0)
                {
                    message = "Appointment confirmation SMS has already been sent.";
                    _logger.Info(message);
                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }

                var eventData           = _eventRepository.GetById(eventId);
                var smsNotificaionModel = _phoneNotificationModelsFactory.GetScreeningReminderSmsNotificationModel(customer, eventData);

                var smsTemplateAlias = EmailTemplateAlias.AppointmentConfirmation;
                if (account != null && account.ConfirmationSmsTemplateId.HasValue && account.ConfirmationSmsTemplateId.Value > 0)
                {
                    var smsTemplate = _emailTemplateRepository.GetById(account.ConfirmationSmsTemplateId.Value);
                    smsTemplateAlias = smsTemplate.Alias;
                }
                var notification = _notifier.NotifyViaSms(NotificationTypeAlias.AppointmentConfirmation, smsTemplateAlias, smsNotificaionModel, customer.Id, currentSession.CurrentOrganizationRole.OrganizationRoleUserId, Request.Url.AbsolutePath);

                if (notification != null)
                {
                    var eventCustomerNotification = new EventCustomerNotification {
                        EventCustomerId = eventCustomer.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id
                    };
                    _eventCustomerNotificationRepository.Save(eventCustomerNotification);
                }
                else
                {
                    message = "Queuing is disabled for Appointment Confirmation SMS.";
                    _logger.Info(message);
                    return(Json(new { message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                message = "Customer has not opted for SMS";
                _logger.Info(message);
                return(Json(new { message }, JsonRequestBehavior.AllowGet));
            }

            message = "Message Sent Successfully";
            return(Json(new { message }, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public void SendAppointmentConfirmationMail(Customer customer, Event eventData, long createdByOrgRoleUserId, string source, CorporateAccount account)
        {
            var sendNotification = false;

            if (eventData.EventType == EventType.Retail)
            {
                sendNotification = true;
            }
            else if (eventData.AccountId.HasValue && eventData.AccountId.Value > 0 && account != null)
            {
                // account = ((IUniqueItemRepository<CorporateAccount>)_corporateAccountRepository).GetById(eventData.AccountId.Value);
                sendNotification = account.SendAppointmentMail && account.AppointmentConfirmationMailTemplateId > 0;
            }

            if (sendNotification)
            {
                var appointmentConfirmationViewModel = _emailNotificationModelsFactory.GetAppointmentConfirmationModel(eventData.Id, customer.CustomerId);

                string emailTemplateAlias = EmailTemplateAlias.AppointmentConfirmationWithEventDetails;
                if (account != null && account.AppointmentConfirmationMailTemplateId > 0)
                {
                    var emailTemplate = _emailTemplateRepository.GetById(account.AppointmentConfirmationMailTemplateId);
                    emailTemplateAlias = emailTemplate.Alias;
                }

                _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.AppointmentConfirmationWithEventDetails, emailTemplateAlias, appointmentConfirmationViewModel, customer.Id, createdByOrgRoleUserId, source, useAlternateEmail: true);
            }

            var eventCustomer = _eventCustomerRepository.Get(eventData.Id, customer.CustomerId);

            if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false)
            {
                _logger.Info("Customer has not subscribed for SMS " + customer.CustomerId);
                return;
            }

            if (account != null && !account.EnableSms)
            {
                _logger.Info("SMS feature has been disabled by corporate account: " + account.Tag + " EventId: " + eventData.Id);
                return;
            }

            var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.Id, NotificationTypeAlias.AppointmentConfirmation);

            var messageCount = (messageAlreadySentList != null && messageAlreadySentList.Any()) ? messageAlreadySentList.Count() : 0;

            if (account != null && messageCount >= account.MaximumSms)
            {
                _logger.Info(string.Format("Maximum Number of reminder message sms has been sent for this event. eventId {0} Customer Id: {1}", eventCustomer.EventId, eventCustomer.Id));
                return;
            }

            var smsTemplateAlias = EmailTemplateAlias.AppointmentConfirmation;

            if (account != null && account.ConfirmationSmsTemplateId.HasValue && account.ConfirmationSmsTemplateId.Value > 0)
            {
                var smsTemplate = _emailTemplateRepository.GetById(account.ConfirmationSmsTemplateId.Value);
                smsTemplateAlias = smsTemplate.Alias;
            }

            if (eventCustomer.EnableTexting)
            {
                var smsAppointmentConfirmation = _smsNotificationModelsFactory.GetScreeningReminderSmsNotificationModel(customer, eventData);
                var notification = _notifier.NotifyViaSms(NotificationTypeAlias.AppointmentConfirmation, smsTemplateAlias, smsAppointmentConfirmation, customer.Id, createdByOrgRoleUserId, source);

                if (notification != null)
                {
                    var eventCustomerNotification = new EventCustomerNotification {
                        EventCustomerId = eventCustomer.Id, NotificationId = notification.Id, NotificationTypeId = notification.NotificationType.Id
                    };
                    _eventCustomerNotificationRepository.Save(eventCustomerNotification);
                }
            }
        }