/// <summary> /// Sets the localized error message in profanity check result object /// </summary> /// <param name="result"></param> /// <returns></returns> public ProfanityCheckResult LocalizeResult(ProfanityCheckResult result, string culture) { if (result == null) { throw new Exception("Null result passed to ProfanityService.LocalizeResult"); } if (culture == null) { result.ErrorMessage = result.DefaultErrorMessage; return(result); } if (result.HasBadCharacters) { // leave variable assignment in case we need to step through. var badCharacters = _resourcesService.GetString(culture, Lines.ERROR_BAD_CHARACTERS); result.ErrorMessage = badCharacters; } if (result.ProfanityWord != null) { // leave variable assignment in case we need to step through. var errorProfanity = _resourcesService.GetString(culture, Lines.ERROR_PROFANITY); result.ErrorMessage = (result.HasBadCharacters ? " " : string.Empty) + errorProfanity + ": " + result.ProfanityWord; } return(result); }
public IActionResult AddAnswer(AddAnswerViewModel addAnswerViewModel) { // Basic checks first if (addAnswerViewModel == null) { return(View("Error")); } if (!ModelState.IsValid) { return(View("Error")); } // Create answer controller because we will just use it var answerController = new AnswerController(_answerService, _profanityService, _suggestionService, _userService, _antiforgery, _statisticsService) { ControllerContext = new ControllerContext() { HttpContext = this.HttpContext } }; // Create object to post var answer = new AnswerDto() { LeftWord = addAnswerViewModel.LeftWord, RightWord = addAnswerViewModel.RightWord, Phrase = addAnswerViewModel.Phrase, UserId = this.GetUserId(this.User, _userService) }; // Roll the dice and post. var task = answerController.AddAnswer(answer); task.Wait(); var resultAnswer = task.Result; // Create the object for passing data between controllers. var navigationData = new NavigationDataDto(); // Read the reason to return it to UI. // All good if (resultAnswer.ErrorMessage == null) { navigationData.Reason = _resourcesService.GetString(this.Culture, Lines.OPINION_WAS_ADDED_SUCCESSFULLY); navigationData.AnswerId = resultAnswer.Answer.Id; navigationData.UserLevelingResult = resultAnswer.UserLevelingResult; // Redirect to show the answer. This will prevent user refreshing the page. return(RedirectToAction("ShowAnswer", "AnswerAction", new { data = NavigationHelper.Encode(navigationData) })); } // All bad else { navigationData.Reason = string.Format(_resourcesService.GetString(this.Culture, Lines.OPINION_WAS_NOT_ADDED), resultAnswer.ErrorMessage); return(RedirectToAction("Index", "Home", new { reason = navigationData.Reason })); } }
public IActionResult Index(ContactUsDto model) { if (!ModelState.IsValid) { return(View(model)); } model.UserName = _userManager.GetUserName(User); string message = "User " + model.UserName + " is contacting us. " + model.Content; _emailSender.SendEmailAsync(model.Subject, message); // Read the reason var reason = _resourcesService.GetString(this.Culture, Lines.THANK_YOU_FOR_CONTACTING); return(RedirectToAction("Index", "Home", new { reason = reason })); }
//SettingsFlyout settings = null; public void OnSettingsPaneCommandsRequested(object sender, object args) { SettingsCommand settingsCommand = new SettingsCommand(0, resourcesService.GetString("Settings"), (x) => { settings = new SettingsFlyout(); settings.Closed += settings_Closed; settings.Content = new SettingsControl(); settings.HeaderText = resourcesService.GetString("Settings"); Window.Current.Activated += Current_Activated; //SolidColorBrush bg = (SolidColorBrush)resourcesService.GetApplicationResource("ApplicationPageBackgroundThemeBrush"); // settings.HeaderBrush = bg; //settings.Background = new SolidColorBrush(Colors.Red); settings.IsOpen = true; }); SettingsPaneCommandsRequestedEventArgs settingsArgs = args as SettingsPaneCommandsRequestedEventArgs; if (!settingsArgs.Request.ApplicationCommands.Contains(settingsCommand)) { settingsArgs.Request.ApplicationCommands.Add(settingsCommand); } }
public IActionResult FlagAnswer(int answerId = 0) { _logger.LogDebug("FlagAnswer answerId = " + answerId); // Create the object for passing data between controllers. var navigationData = new NavigationDataDto(); navigationData.AnswerId = answerId; // Only do something if answer id is not zero if (answerId <= 0) { // Redirect to some random answer that might even not exist return(RedirectToAction("ShowAnswer", "AnswerAction", new { data = NavigationHelper.Encode(navigationData) })); } var user = _userService.FindByUserName(User.Identity.Name); // Check if user statistics is loaded _statisticsService.LoadUserStatictics(user); var result = _flagService.FlagAnswer( new AnswerFlagDto() { AnswerId = answerId, UserId = user.UserId } ); if (result.IsNew) { user.NumberOfFlags++; navigationData.UserLevelingResult = _userService.LevelUser(user, EventType.AnswerFlagAdded); } // Read the reason navigationData.Reason = _resourcesService.GetString(this.Culture, Lines.THANK_YOU_FOR_FLAGING); return(RedirectToAction("ShowAnswer", "AnswerAction", new { data = NavigationHelper.Encode(navigationData) })); }
/// <summary> /// Default home page view. /// </summary> /// <returns></returns> // GET: /<controller>/ public IActionResult Index(string reason = null, string searchPhrase = null) { var model = new HomePageDto(); // Use the search service if search phrase is passed if (!string.IsNullOrEmpty(searchPhrase) && !string.IsNullOrWhiteSpace(searchPhrase)) { // store the phrase that user typed. _searchEntryService.AddSearchEntry(new SearchEntryDto { SearchPhrase = searchPhrase, UserId = GetUserId(User, _userService) }); model.TopToday.Answers = _answerService.FindLastAnswers(searchPhrase).ToList(); model.Keyword = searchPhrase; model.HeaderText = string.Format(_resourcesService.GetString(this.Culture, Lines.SEARCH_RESULTS_FOR), searchPhrase); model.IsSearch = true; } else { model.TopToday.Answers = _answerService.FindAnswersTrendingToday().ToList(); model.HeaderText = _resourcesService.GetString(this.Culture, Lines.TRENDING_TODAY); } // Answer service does not do any stiching. Meaning it can not set user information in the model/answers. // Need to add user info to answers Stitcher <AnswerDto> .Stitch(model.TopToday.Answers, _userService); model.Reason = reason; // Check if we need to debug react model.DebugReactControls = ReadUrlParameterAsBoolean(DEBUG_REACTJS_URL_PARAMETER_NAME); return(View(model)); }
public async Task <IActionResult> CancelProfile(RemoveProfileViewModel model) { // Check the model first if (!ModelState.IsValid) { return(View(model)); } // Find id var currentUserId = _userManager.GetUserId(User); // Find user var user = await _userManager.FindByIdAsync(currentUserId); if (user == null) { // Would be funny if this happens. Someone is hacking us I guess. return(View("Error")); } user.IsCancelled = true; user.DateUpdated = DateTime.Now; user.DateCancelled = DateTime.Now; user.CancellationReason = model.Reason; var updateResult = await _userManager.UpdateAsync(user); // Log out. await _signInManager.SignOutAsync(); // If all good we redirect to home. if (updateResult.Succeeded) { // Read the reason var reason = _resourcesService.GetString(this.Culture, Lines.YOUR_PROFILE_WAS_REMOVED); return(RedirectToAction("Index", "Home", new { reason = reason })); } AddErrors(updateResult); return(View(model)); }
public async Task <Result <GetStringResponseDto> > GetString(string key) => await _resourcesService.GetString(key);
public IActionResult AddDescription(AnswerDescriptionDto answerDescription) { // Basic checks first if (answerDescription == null || answerDescription.AnswerId <= 0 || string.IsNullOrEmpty(answerDescription.Description) || string.IsNullOrWhiteSpace(answerDescription.Description)) { return(View("Error")); } // todo: figure out how to protect from spam posts besides antiforgery // cleanup the input answerDescription.Description = Services.TextCleaner.Clean(answerDescription.Description); // Clean up the endings answerDescription.Description = answerDescription.Description.TrimEnd(new Char[] { ' ', '\n', '\r' }); // Let's first check for profanities. var profanityCheckResult = _profanityService.CheckProfanity(answerDescription.Description, this.Culture); if (profanityCheckResult.HasIssues) { // answer.ErrorMessage = profanityCheckResult.ErrorMessage; // todo: settle on displaying errors from controller posts and gets // Can't use error message from profanity object because it is not localized. // Have to localize ourself // Might have to move this to profanity service. var errorData = new ErrorViewModel(); errorData.AddError(profanityCheckResult.ErrorMessage); return(View("Error", errorData)); } // Save the user in case we need statistics update ApplicationUserDto user = null; // Load user if he is logged in if (User.Identity.IsAuthenticated && User.Identity.Name != null) { user = _userService.FindByUserName(User.Identity.Name); } // Set the user id in the answer if user is found if (user != null) { answerDescription.UserId = user.UserId; // Check if user statistics is loaded _statisticsService.LoadUserStatictics(user); } // Add answer description var operationResult = _answerDescriptionService.AddAnswerDescription(answerDescription); // Create the object for passing data between controllers. var navigationData = new NavigationDataDto(); // Need to update user stats if new answer was added if (operationResult.IsNew && user != null) { user.NumberOfDescriptions++; navigationData.UserLevelingResult = _userService.LevelUser(user, EventType.AnswerDescriptionAdded); } // Read the reason to return it to UI. navigationData.Reason = _resourcesService.GetString(this.Culture, Lines.DESCRIPTION_WAS_ADDED_SUCCESSFULLY); navigationData.AnswerId = answerDescription.AnswerId; // Redirect to show the answer. This will prevent user refreshing the page. return(RedirectToAction("ShowAnswer", new { data = NavigationHelper.Encode(navigationData) })); }