Ejemplo n.º 1
0
        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);
        }