Пример #1
0
        public bool SaveNotification(CustomEventNotification notification)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var entity = Mapper.Map <CustomEventNotification, CustomEventNotificationEntity>(notification);

                adapter.SaveEntity(entity, true);
            }

            return(true);
        }
        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");
            }
        }