public async Task writeAsync(Contact data) { if (null != data) { var tempData = await readAsync(); tempData.Add(data); FileStream fs = new FileStream(fileName, FileMode.Create); using (StreamWriter sW = new StreamWriter(fs)) { var serializeData = JsonConvert.SerializeObject(tempData); sW.Write(serializeData); } } }
public async Task<ActionResult> Add_contact(Contact contact) { await (new ContactJsonFile()).writeAsync(contact); return RedirectToAction("Index"); }