private void btnLogin_Click(object sender, EventArgs e) { using (StreamReader r = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\Employees.json")) { string json = r.ReadToEnd(); AppData appData = JsonConvert.DeserializeObject <AppData>(json); Employee employee = appData.Employees.Where(emp => emp.Email == txtUsername.Text).FirstOrDefault(); if (employee != null) { if (employee.Password == txtPassword.Text) { Program.currentUser = employee; var listEmployeesForm = new ListEmployeesForm(); listEmployeesForm.Show(); this.Hide(); } else { lblMessage.Text = "Username or password incorrect"; } } } }
private void btnSave_Click(object sender, EventArgs e) { AppData appData; using (StreamReader r = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\Employees.json")) { string json = r.ReadToEnd(); appData = JsonConvert.DeserializeObject <AppData>(json); } appData.Employees.Add(new Employee() { Id = appData.Employees.Count + 1, FirstName = txtFirstName.Text, LastName = txtLastName.Text, Department = "IS", Email = txtEmail.Text, Password = txtPassword.Text }); using (StreamWriter writetext = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Employees.json")) { writetext.WriteLine(JsonConvert.SerializeObject(appData)); } var listEmployeesForm = new ListEmployeesForm(); listEmployeesForm.Show(); this.Close(); }