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); }
/// <summary> /// Saves user feedback. /// </summary> /// <param name="user"></param> /// <param name="userFeedback"></param> /// <returns></returns> public void SaveUserFeedback(UserFeedbackContext context, Core.Models.UserFeedback.UserFeedback userFeedback) { if (context == null) { throw new ArgumentNullException("context"); } if (userFeedback == null) { throw new ArgumentNullException("userFeedback"); } AssertUserFeedback(userFeedback); _userFeedbackRepo.SaveUserFeedback(context, userFeedback); }
/// <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); } }
public FeedbacksController(UserFeedbackContext context) { _context = context; }
/// <summary> /// Create a feedback row for the user /// </summary> /// <param name="user"></param> /// <param name="userFeedback"></param> public void SaveUserFeedback(UserFeedbackContext context, Core.Models.UserFeedback.UserFeedback userFeedback) { if (context == null) { throw new ArgumentNullException("context"); } if (userFeedback == null) { throw new ArgumentNullException("userFeedback"); } string sqlCommand = @" INSERT INTO [Messaging].[UserFeedback] ( [UserId] ,[UserFirstName] ,[UserLastName] ,[BranchId] ,[CustomerNumber] ,[CustomerName] ,[SalesRepName] ,[Audience] ,[SourceName] ,[TargetName] ,[SourceEmailAddress] ,[TargetEmailAddress] ,[Subject] ,[Content] ,[BrowserUserAgent] ,[BrowserVendor] ) OUTPUT Inserted.Id VALUES ( @UserId ,@UserFirstName ,@UserLastName ,@BranchId ,@CustomerNumber ,@CustomerName ,@SalesRepName ,@Audience ,@SourceName ,@TargetName ,@SourceEmailAddress ,@TargetEmailAddress ,@Subject ,@Content ,@BrowserUserAgent ,@BrowserVendor ) SELECT SCOPE_IDENTITY() "; var parameters = new { UserId = context.UserId, UserFirstName = context.UserFirstName, UserLastName = context.UserLastName, BranchId = context.BranchId, CustomerNumber = context.CustomerNumber, CustomerName = context.CustomerName, SalesRepName = context.SalesRepName, SourceName = context.SourceName, TargetName = context.TargetName, SourceEmailAddress = context.SourceEmailAddress, TargetEmailAddress = context.TargetEmailAddress, Subject = userFeedback.Subject, Content = userFeedback.Content, Audience = userFeedback.Audience.ToString(), BrowserUserAgent = userFeedback.BrowserUserAgent, BrowserVendor = userFeedback.BrowserVendor, }; _dbConnection.Execute(sqlCommand, parameters); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, UserFeedbackContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Users}/{action=New}/{id?}"); }); DbInitializer.Initialize(context); }