public ActionResult seting() { seting myseting = new seting(); try { string path3 = Server.MapPath("~/App_Data/seting.txt"); using (StreamReader JsonText = new StreamReader(path3, true)) { string Jsonstring = JsonText.ReadToEnd(); var serverSettings = JsonConvert.DeserializeObject <seting>(Jsonstring, new JsonSerializerSettings()); myseting.SqlUsername = serverSettings.SqlUsername; myseting.SqlPassword = serverSettings.SqlPassword; myseting.urlServises = serverSettings.urlServises; myseting.FiscalYear = serverSettings.FiscalYear; //var x5 = JsonSerializer.Deserialize<seting>(x4); } ViewBag.testconection = null; return(View(myseting)); } catch (Exception ex) { errors.LogError(ex, getpath()); return(View(myseting)); } }
public bool testconection(seting myseting) { if (myseting.FiscalYear == 95) { throw new Exeptioncs("FiscalYear", myseting.FiscalYear.ToString()); } return(false); }
public ActionResult seting(seting myseting) { if (myseting.button == "save") { try { string path3 = Server.MapPath("~/App_Data/seting.txt"); //FileStream file = new FileStream(path3, FileMode.Open); System.IO.File.Delete(path3); var s = System.IO.File.Exists(path3); //System.IO.File.CreateText(path3); using (StreamWriter writer = new StreamWriter(path3, true)) { //FileStream fileStream = new FileStream(path3, FileMode.Open, FileAccess.Write); writer.Write(""); string json = JsonConvert.SerializeObject(myseting); writer.Write(json); writer.Close(); } myseting.error = false; ViewBag.succes = true; return(View(myseting)); } catch (Exception ex) { errors.LogError(ex, getpath()); myseting.error = true; ViewBag.succes = false; return(View(myseting)); } } else if (myseting.button == "test") { try { string path3 = Server.MapPath("~/App_Data/seting.txt"); using (StreamReader JsonText = new StreamReader(path3, true)) { string Jsonstring = JsonText.ReadToEnd(); var serverSettings = JsonConvert.DeserializeObject <seting>(Jsonstring, new JsonSerializerSettings()); bool succes = testconection(serverSettings); ViewBag.testconection = "true"; return(View(myseting)); } } catch (Exception ex) { errors.LogError(ex, getpath()); ViewBag.testconection = "false"; return(View(myseting)); } } return(View(myseting)); }