public bool Save(DeskQuote quote, string filepath) { try { string json = System.IO.File.ReadAllText(filepath); List <DeskQuote> items = JsonConvert.DeserializeObject <List <DeskQuote> >(json); items.Add(quote); json = JsonConvert.SerializeObject(items); System.IO.File.WriteAllText(filepath, json); } catch (Exception) { return(false); } return(true); }
private void buttonSave_Click(object sender, EventArgs e) { if (saveQuote == null) { MessageBox.Show("Please, complete the quote!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool res = DeskQuote.SavaQuote(saveQuote); if (res) { MessageBox.Show("Quote saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Something went wrong while saving the quote", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }