public async Task <IActionResult> Search(string search) { if (string.IsNullOrEmpty(search)) { return(RedirectToAction("Error", new { errorTitle = "Invalid input", errorMessage = "Cannot find anagrams with empty strings" })); } if (CheckForInvalidInputs(search)) { return(RedirectToAction("Error", new { errorTitle = "Invalid input", errorMessage = "Input only accepts letters without accents and white spaces" })); } search = search.ToUpper(); _watch.Start(); var anagramsList = await _anagramService.SearchForAnagrams(search); _watch.Stop(); var viewModel = new AnagramViewModel { Anagrams = anagramsList, Search = search, RequestTime = _watch.Elapsed.ToString(@"mm\:ss\:fff") }; return(View("Index", viewModel)); }
public IList <string> Get(string input) { var splitInput = input.Split(" "); // put the strings seperated by spaces into an array so they can be passed to the GetAnagrams function // need to find a better workaround bool success = int.TryParse(ConfigurationManager.AppSettings["MaxResultAmount"], out var _defaultValue); if (!success) { _defaultValue = 100; } var resultList = new AnagramViewModel { WordList = anagramSolver.GetAnagrams(splitInput) }; return(resultList.WordList); }
public IActionResult Index(AnagramViewModel request) { var searchestLeft = _userInfoService.GetUserInfo(); // get amount of searches left or create new user if (request.Input == null || request.Input.Length == 0 || searchestLeft <= 0) { return(Index(searchestLeft)); } Response.Cookies.Append("searchedWord", request.Input); // add cookie var resultList = new AnagramViewModel { WordList = _cacheService.GetMultiple(request.Input) }; //get anagrams _userInfoService.UpdateSearchAmount(); // add +1 search resultList.searchesLeft = _userInfoService.GetUserInfo(); // get updated amount for display in view _userLogService.AddToUserLog(HttpContext.Connection.RemoteIpAddress.ToString(), request.Input); return(View(resultList)); }