/// <summary> /// Naudotojo atnaujinimas duomenų bazėje. /// </summary> /// <param name="user">Atnaujinamas naudotojas</param> private static void UpdateUserDB(User user) { try { using (dlssdb db = new dlssdb()) { User existingUser = db.Users.Where(x => x.id == user.id).FirstOrDefault(); List <Entry> entries = db.Entries.Where(x => x.card_id == existingUser.card_id).ToList(); foreach (var entry in entries) { entry.card_id = user.card_id; } existingUser.name = user.name; existingUser.surname = user.surname; existingUser.password = user.password; existingUser.email = user.email; existingUser.card_id = user.card_id; existingUser.access_level = user.access_level; existingUser.work_hours_in_week = user.work_hours_in_week; db.SaveChanges(); } } catch { MessageBox.Show(Properties.Strings.errUser, Properties.Strings.errTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Naudotojo slaptažodžio atnaujinimas. /// </summary> /// <param name="user_id">Naudotojo ID</param> /// <param name="password">Naujas naudotojo slaptažodis</param> public static void UpdateUserPassword(int user_id, string password) { try { using (dlssdb db = new dlssdb()) { User user = db.Users.Where(x => x.id == user_id).FirstOrDefault(); user.password = BCrypt.Net.BCrypt.EnhancedHashPassword(password); db.SaveChanges(); } } catch { } }
/// <summary> /// Naujo naudotojo išsaugojimas duomenų bazėje. /// </summary> /// <param name="user">Išsaugomas naudotojas</param> private static void InsertNewUserDB(User user) { try { using (dlssdb db = new dlssdb()) { db.Users.Add(user); db.SaveChanges(); } } catch { MessageBox.Show(Properties.Strings.errUser, Properties.Strings.errTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Naudotojo pašalinimas iš duomenų bazės. /// </summary> /// <param name="user">Pašalinamas naudotojas</param> public static void RemoveUserDB(User user) { try { using (dlssdb db = new dlssdb()) { List <Entry> entries = db.Entries.Where(x => x.card_id == user.card_id).ToList(); db.Entries.RemoveRange(entries); User existingUser = db.Users.Where(x => x.card_id == user.card_id).FirstOrDefault(); db.Users.Remove(existingUser); db.SaveChanges(); } } catch { MessageBox.Show(Properties.Strings.errUser, Properties.Strings.errTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Sistemos nustatymų išsaugojimas duomenų bazėje. /// </summary> /// <param name="settings">Įšsaugomi sistemos nustatymai</param> public static void SaveSettings(Settings settings) { try { using (dlssdb db = new dlssdb()) { Settings settingsExisting = db.Settings.FirstOrDefault(); settingsExisting.NVRIP = settings.NVRIP; settingsExisting.NVRPort = settings.NVRPort; settingsExisting.NVRUsername = settings.NVRUsername; settingsExisting.NVRPassword = settings.NVRPassword; settingsExisting.AccessControllerIP = settings.AccessControllerIP; settingsExisting.AccessControllerPort = settings.AccessControllerPort; settingsExisting.AccessControllerUsername = settings.AccessControllerUsername; settingsExisting.AccessControllerPassword = settings.AccessControllerPassword; db.SaveChanges(); } } catch { } }