// Remove record from db public bool RemoveRecords() { using (MesInbox mi = new MesInbox()) { try { mi.Table.RemoveRange(mi.Table); mi.SaveChanges(); }catch (Exception ex) { WriteToLog(ex.Message); throw new Exception(ex.Message); } } return(true); }
// Add record to db public void AddRecord(string textParam) { using (MesInbox mi = new MesInbox()) { try { Table tb = new Table { Text = textParam, IsRead = false }; mi.Table.Add(tb); mi.SaveChanges(); }catch (Exception ex) { WriteToLog(ex.Message); throw new Exception(ex.Message); } } }
// Get Record from db public List <Table> GetRecords() { List <Table> retTable = new List <Table>(); using (MesInbox mi = new MesInbox()) { try { foreach (Table t in mi.Table) { retTable.Add(t); } }catch (Exception ex) { WriteToLog(ex.Message); throw new Exception(ex.Message); } } return(retTable); }
// Updater record in db public void UpdateRecord(Table tb) { using (MesInbox mi = new MesInbox()) { try { Table tbl = mi.Table.Find(tb.id); if (tbl != null) { tbl = tb; mi.SaveChanges(); } } catch (Exception ex) { WriteToLog(ex.Message); throw new Exception(ex.Message); } } }