public OperationReturnModel <string> SubmitUserFeedback(UserFeedback userFeedback)
        {
            var retVal = new OperationReturnModel <string>()
            {
                IsSuccess = false
            };

            try
            {
                (string Name, string EmailAddress)target = GetTarget(SelectedUserContext, AuthenticatedUser, userFeedback.Audience);

                var customer = GetCustomer(SelectedUserContext, AuthenticatedUser);

                var context = new UserFeedbackContext
                {
                    UserId             = AuthenticatedUser.UserId,
                    UserFirstName      = AuthenticatedUser.FirstName,
                    UserLastName       = AuthenticatedUser.LastName,
                    BranchId           = customer?.CustomerBranch,
                    CustomerNumber     = customer?.CustomerNumber,
                    CustomerName       = customer?.CustomerName,
                    SalesRepName       = customer?.Dsr?.Name,
                    SourceName         = AuthenticatedUser.Name,
                    TargetName         = target.Name,
                    SourceEmailAddress = AuthenticatedUser.EmailAddress,
                    TargetEmailAddress = target.EmailAddress,
                };

                var notification = new UserFeedbackNotification()
                {
                    BranchId       = customer?.CustomerBranch,
                    CustomerNumber = customer?.CustomerNumber,
                    Audience       = userFeedback.Audience,

                    Context      = context,
                    UserFeedback = userFeedback,
                };

                _userFeedbackLogic.SaveUserFeedback(context, userFeedback);
                _notificationHandler.ProcessNotification(notification);

                retVal.SuccessResponse = "Feedback processed successfully.";
                retVal.IsSuccess       = true;
            }
            catch (ApplicationException axe)
            {
                retVal.ErrorMessage = axe.Message;
                retVal.IsSuccess    = false;
                _log.WriteErrorLog("Application exception", axe);
            }
            catch (Exception ex)
            {
                retVal.ErrorMessage = "Could not complete the request. " + ex.Message;
                retVal.IsSuccess    = false;
                _log.WriteErrorLog("Unhandled exception", ex);
            }

            return(retVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates email message from user feeedback notification.
        /// </summary>
        /// <param name="notification"></param>
        /// <returns></returns>
        private Message CreateEmailMessageForNotification(UserFeedbackNotification notification)
        {
            Message message = new Message();
            MessageTemplateModel template = _messageTemplateLogic.ReadForKey(MESSAGE_TEMPLATE_USERFEEDBACK);

            var context      = notification.Context;
            var userFeedback = notification.UserFeedback;

            message.MessageSubject = template.Subject.Inject(new
            {
                CustomerNumber = context.CustomerNumber,
                CustomerName   = context.CustomerName,
                Audience       = userFeedback.Audience.ToString(),
            });

            Customer customer = _customerRepository.GetCustomerByCustomerNumber(notification.CustomerNumber, notification.BranchId);

            StringBuilder header = _messageTemplateLogic.BuildHeader("Feedback from ", customer);

            message.MessageBody += template.Body.Inject(new
            {
                NotifHeader = header.ToString(),

                UserFirstName      = context.UserFirstName,
                UserLastName       = context.UserLastName,
                SourceEmailAddress = context.SourceEmailAddress,
                SalesRepName       = context.SalesRepName,

                Subject = userFeedback.Subject,
                Content = userFeedback.Content,
            });

            message.BodyIsHtml       = template.IsBodyHtml;
            message.CustomerNumber   = context.CustomerNumber;
            message.CustomerName     = context.CustomerName;
            message.BranchId         = context.BranchId;
            message.NotificationType = NotificationType.UserFeedback;

            return(message);
        }
Esempio n. 3
0
        /// <summary>
        /// Process user feedback notification.
        /// </summary>
        /// <param name="notification"></param>
        public void ProcessNotification(BaseNotification notification)
        {
            try
            {
                if (notification.NotificationType != NotificationType.UserFeedback)
                {
                    throw new ApplicationException("notification/handler type mismatch");
                }

                UserFeedbackNotification feedbackNotification = (UserFeedbackNotification)notification;
                UserFeedbackContext      context = feedbackNotification.Context;

                Message message = CreateEmailMessageForNotification(feedbackNotification);

                try
                {
                    _emailClient.SendEmail(
                        new List <string>()
                    {
                        context.TargetEmailAddress
                    },
                        null,
                        null,
                        context.SourceEmailAddress,
                        message.MessageSubject,
                        message.MessageBody,
                        message.BodyIsHtml
                        );
                }
                catch (Exception ex)
                {
                    _eventLogRepository.WriteErrorLog("EmailMessageProvider: Error sending email", ex);
                }
            }
            catch (Exception ex)
            {
                throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "UserFeedback:ProcessNotification", "Sending user feedback", "There was an exception processing user feedback", ex);
            }
        }