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()); }
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()); }