Exemple #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));
        }
        private string SendCustomNotification(Customer customer, EventCustomer eventCustomer, CorporateAccount account, CustomEventNotification customEventNotification)
        {
            try
            {
                var message = string.Empty;
                _logger.Info("Running Custom SMS for  Customer: " + customer.CustomerId);
                if (!eventCustomer.EnableTexting)
                {
                    message = "Customer has not opted for SMS";
                    _logger.Info(message);
                    return(message);
                }
                if (customer.IsSubscribed == null || customer.IsSubscribed.Value == false)
                {
                    message = "Customer has not subscribed for SMS";
                    _logger.Info(message);
                    return(message);
                }
                var messageAlreadySentList = _eventCustomerNotificationRepository.GetAllByEventCustomerId(eventCustomer.EventId, NotificationTypeAlias.CustomEventSmsNotification);

                var messageCount = (!messageAlreadySentList.IsNullOrEmpty()) ? EnumerableExtensions.Count(messageAlreadySentList) : 0;

                if (account != null)
                {
                    var accountMaxSmscount = (account.MaximumSms.HasValue) ? account.MaximumSms.Value : 0;

                    if (messageCount >= accountMaxSmscount)
                    {
                        _logger.Info("Maximum SMS has Been Sent ");
                        _logger.Info(string.Format("Allowed SMS {0}, SMS Already Sent {0} " + accountMaxSmscount, messageCount));
                        message = "Maximum SMS limit has been reached.";

                        return(message);
                    }
                }
                if (messageAlreadySentList.Any() && (account == null || !account.MaximumSms.HasValue))
                {
                    message = "Maximum SMS limit has been reached.";
                    return(message);
                }
                var smsNotificaionModel = _phoneNotificationModelsFactory.GetCustomEventSmsNotificatonModel(customEventNotification.Body);

                var notification = _notifier.NotifyViaSms(NotificationTypeAlias.CustomEventSmsNotification, EmailTemplateAlias.CustomEventSms, smsNotificaionModel, customer.Id, customEventNotification.CreatedBy, "Event Detail ");

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

                message = "Message has been successfully Queued";

                return(message);
            }
            catch (Exception exception)
            {
                _logger.Error("Some Error occurred while Queuing message");
                _logger.Info("Message: " + exception.Message);
                _logger.Info("Stack Trace: " + exception.StackTrace);

                return("Some Error occurred while Queuing message");
            }
        }
Exemple #3
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);
                }
            }
        }