/// <summary> /// Insert advanced reminder file(s)/folder(s) options (delete/open) for a specific reminder /// </summary> /// <param name="avr"></param> /// <returns></returns> public static long InsertAVRFilesFolders(AdvancedReminderFilesFolders avr) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { if (db.AdvancedReminderFilesFolders.Where(r => r.Id == avr.Id).Count() > 0) { //Exists already. update. db.AdvancedReminderFilesFolders.Attach(avr); var entry = db.Entry(avr); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update } else { if (db.AdvancedReminderFilesFolders.Count() > 0) { avr.Id = db.AdvancedReminderFilesFolders.Max(i => i.Id) + 1; } else { avr.Id = 0; } db.AdvancedReminderFilesFolders.Add(avr); } db.SaveChanges(); db.Dispose(); } return(avr.Id); }
/// <summary> /// Insert advanced Reminder HttpRequest into the database /// </summary> /// <param name="http">The avr object</param> /// <returns></returns> public static long InsertHttpRequest(HttpRequests http) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { if (db.HttpRequests.Where(r => r.reminderId == http.reminderId).Count() > 0) { //Exists already. update. db.HttpRequests.Attach(http); var entry = db.Entry(http); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update db.SaveChanges(); db.Dispose(); } else { if (db.HttpRequests.Count() > 0) { http.Id = db.HttpRequests.Max(i => i.Id) + 1; } db.HttpRequests.Add(http); db.SaveChanges(); db.Dispose(); } } return(http.Id); }
/// <summary> /// Update an existing reminder. /// </summary> /// <param name="rem">The altered reminder</param> public static void EditReminder(Reminder rem) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { db.Reminder.Attach(rem); var entry = db.Entry(rem); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update SaveAndCloseDataBase(db); } }
/// <summary> /// Deletes multiple reminders from the database. /// </summary> /// <param name="rems"></param> public static void DeleteReminders(List <Reminder> rems) { //We use this method so we can attach and remove the reminders in a foreach loop, and save changes to the database after the loop. //If you use the DeleteReminder method in a foreach loop, it will open and close the database each time using (RemindMeDbEntities db = new RemindMeDbEntities()) { foreach (Reminder rem in rems) { rem.Deleted = 1; db.Reminder.Attach(rem); var entry = db.Entry(rem); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update } SaveAndCloseDataBase(db); } }
public static void UpdateListviewSizes(ListviewColumnSizes sizes) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { var count = db.ListviewColumnSizes.Where(o => o.Id >= 0).Count(); if (count > 0) { db.ListviewColumnSizes.Attach(sizes); var entry = db.Entry(sizes); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update SaveAndCloseDataBase(db); } else {//The dimensions table is still empty db.ListviewColumnSizes.Add(sizes); SaveAndCloseDataBase(db); } } }
/// <summary> /// Update an existing hotkey combination in the SQLite database /// </summary> /// <param name="hotkey">The hotkey object</param> private static void UpdateHotkey(Hotkeys hotkey) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { var count = db.Hotkeys.Where(o => o.Id >= hotkey.Id).Count(); if (count == 1) { db.Hotkeys.Attach(hotkey); var entry = db.Entry(hotkey); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update db.SaveChanges(); //push to database db.Dispose(); } else {//The settings table is still empty db.Hotkeys.Add(hotkey); db.SaveChanges(); db.Dispose(); } } }
public static void UpdateButtonSpacing(ButtonSpaces btn) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { var count = db.ButtonSpaces.Where(o => o.Id >= 0).Count(); if (count == 1) { db.ButtonSpaces.Attach(btn); var entry = db.Entry(btn); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update db.SaveChanges(); //push to database db.Dispose(); } else {//The settings table is still empty db.ButtonSpaces.Add(btn); db.SaveChanges(); db.Dispose(); } } }
public static void UpdateHttpRequest(HttpRequestCondition cond) { using (RemindMeDbEntities db = new RemindMeDbEntities()) { var count = db.HttpRequestCondition.Where(o => o.Id >= 0).Count(); if (count > 0) { db.HttpRequestCondition.Attach(cond); var entry = db.Entry(cond); entry.State = System.Data.Entity.EntityState.Modified; //Mark it for update db.SaveChanges(); //push to database db.Dispose(); } else {//The settings table is still empty db.HttpRequestCondition.Add(cond); db.SaveChanges(); db.Dispose(); } } }