public IActionResult Index(string id = null) { List <string> anagrams = new List <string>(); if (String.IsNullOrEmpty(id)) { foreach (var cookie in Request.Cookies) { if (cookie.Key == "inputWord") { return(View(_anagramSolver.GetAnagrams(cookie.Value).ToList())); } } return(View()); } else { CookieOptions options = new CookieOptions { Expires = DateTime.Now.AddDays(1) }; Response.Cookies.Append("inputWord", id, options); } AnagramsSearchInfoModel anagramsSearchResult = _anagramsSearchService.GetAnagrams(id, HttpContext.Connection.LocalIpAddress.ToString()); if (!anagramsSearchResult.isValidToSearch) { return(View("NotAllowedToSearch")); } return(View(anagramsSearchResult.Anagrams)); //return View(_cachedWordsService.CacheWords(id, HttpContext.Connection.LocalIpAddress.ToString())); }
public AnagramsSearchInfoModel GetAnagrams(string requestWord, string userIp) { var anagramsSearchInfoModel = new AnagramsSearchInfoModel(); if (!_userManagingService.CheckIfRegistered(userIp)) { _userContract.SetUser(userIp); } anagramsSearchInfoModel.isValidToSearch = _userManagingService.CheckIfValidToSearch(userIp); if (!anagramsSearchInfoModel.isValidToSearch) { return(anagramsSearchInfoModel); } if (_cachedWords.CheckIfCached(requestWord)) { _logger.Log(requestWord, userIp); anagramsSearchInfoModel.Anagrams = _cachedWords.GetCachedAnagrams(requestWord); return(anagramsSearchInfoModel); } anagramsSearchInfoModel.Anagrams = _anagramSolver.GetAnagrams(requestWord).ToList(); _requestWordContract.SetRequestWord(requestWord); _cachedWords.SetCachedAnagrams(anagramsSearchInfoModel.Anagrams, requestWord); _logger.Log(requestWord, userIp); return(anagramsSearchInfoModel); }