public async Task <IActionResult> CreateStringsAsync([FromBody] StringsViewModel value) { var response = new SingleModelResponse <StringsViewModel>() as ISingleModelResponse <StringsViewModel>; try { var entity = await Task.Run(() => { return(_RESTfulAPI_Repository.AddStrings(value.ToEntity())); }); if (response.DidError == false) { response.Model = entity.ToViewModel(); } } catch (Exception ex) { string webRoot = _hostingEnvironment.WebRootPath; string errorGuid = String.Format(Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 16)); HttpContext.Session.SetString("ErrorGuid", errorGuid); ViewBag.ErrorGuid = HttpContext.Session.GetString("ErrorGuid"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { using (StreamWriter w = new StreamWriter(webRoot + "\\log.txt", append: true)) { Log.Logging(ex.ToString(), w, ViewBag.ErrorGuid); } } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { using (StreamWriter w = new StreamWriter(webRoot + "/log.txt", append: true)) { Log.Logging(ex.ToString(), w, ViewBag.ErrorGuid); } } response.DidError = true; //response.ErrorMessage = ex.ToString(); return(this.Json(new { timestamp = DateTime.Now, errorGuid = ViewBag.ErrorGuid, status = HttpStatusCode.InternalServerError, info = "Error logged in log file." })); } response.Info = "Client " + " " + HttpContext.Connection.RemoteIpAddress.ToString(); return(response.ToHttpResponse()); }
/// <summary> /// /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public static Strings ToEntity(this StringsViewModel viewModel) { return(viewModel == null ? null : new Strings { String_Id = viewModel.String_Id, String_Data = viewModel.String_Data // //RowGuid = viewModel.RowGuid, //ModifiedDate = viewModel.ModifiedDate }); }
public async Task <IActionResult> GetLevenshteinDistanceResult(StringsViewModel stringsViewModel) { LevenshteinDistanceViewModel levenshteinDistanceViewModel = null; LevenshteinDistanceMatrixAndCostResult levenshteinDistanceMatrixAndCostResult = null; StringsModel stringsModel = null; string JWTToken = null; if (stringsViewModel != null) { stringsModel = new StringsModel { FirstString = stringsViewModel.FirstString , SecondString = stringsViewModel.SecondString }; JWTToken = HttpContext.Session.GetString(accessTokenSession).ToString(); ViewData["JWTToken"] = HttpContext.Session.GetString(accessTokenSession); using (LevenshteinDistanceApiClient levenshteinDistanceApiClient = new LevenshteinDistanceApiClient(this.configuration)) { levenshteinDistanceMatrixAndCostResult = await levenshteinDistanceApiClient.GetLevenshteinDistanceMatrixAndCostResult(stringsModel, JWTToken); } if (levenshteinDistanceMatrixAndCostResult != null) { levenshteinDistanceViewModel = new LevenshteinDistanceViewModel { StringsAsCriteria = new StringsViewModel { FirstString = levenshteinDistanceMatrixAndCostResult.StringsAsCriteria.FirstString , SecondString = levenshteinDistanceMatrixAndCostResult.StringsAsCriteria.SecondString }, ResultTable = new LevenshteinResultTableViewModel { Cost = levenshteinDistanceMatrixAndCostResult.Cost , ResultMatrix = levenshteinDistanceMatrixAndCostResult.MatrixResult } }; } } return(View("Index", levenshteinDistanceViewModel)); }
public async Task <IActionResult> UpdateStringsAsync(Int32 id, [FromBody] StringsViewModel value) { var response = new SingleModelResponse <StringsViewModel>() as ISingleModelResponse <StringsViewModel>; try { var entity = await Task.Run(() => { return(_RESTfulAPI_Repository.UpdateStrings(id, value.ToEntity())); }); response.Model = entity.ToViewModel(); response.Info = "The record was updated successfully"; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = ex.Message; } return(response.ToHttpResponse()); }