private static void SaveReminders(DSModel db, KeyBinder key, DriverMedicalModel model, DriversMedical poco) { string sqlDelete = @"DELETE FROM drivers_medicals_reminders WHERE DriverMedicalID = @DriverMedicalID AND DriverMedicalReminderID NOT IN (@DriverMedicalReminderID);"; string ids = "0"; if (model.Reminders.Count > 0) { ids = string.Join <uint>(",", model.Reminders.Select(r => r.DriverMedicalReminderID)); } sqlDelete = sqlDelete.Replace("@DriverMedicalReminderID", ids); db.ExecuteNonQuery(sqlDelete, new MySqlParameter("DriverMedicalID", poco.DriverMedicalID)); string sqlInsert = @" INSERT INTO drivers_medicals_reminders (DriverMedicalID, ReminderID, ReminderType, ShouldRemind) VALUES (@DriverMedicalID, @ReminderID, @ReminderType, @ShouldRemind); SELECT LAST_INSERT_ID();"; string sqlUpdate = @" UPDATE drivers_medicals_reminders SET DriverMedicalID = @DriverMedicalID, ReminderID = @ReminderID, ReminderType = @ReminderType, ShouldRemind = @ShouldRemind WHERE DriverMedicalReminderID = @DriverMedicalReminderID;"; foreach (var rem in model.Reminders) { if (rem.DriverMedicalReminderID == 0) { rem.DriverMedicalID = poco.DriverMedicalID; UtilityModel <uint> temp = new UtilityModel <uint>(); temp.Value = db.ExecuteQuery <uint>(sqlInsert, new MySqlParameter("DriverMedicalID", rem.DriverMedicalID), new MySqlParameter("ReminderID", rem.ReminderID), new MySqlParameter("ReminderType", rem.ReminderType), new MySqlParameter("ShouldRemind", rem.ShouldRemind)) .First(); key.AddKey(temp, rem, "Value", rem.GetName(p => p.DriverMedicalReminderID)); } else { rem.DriverMedicalID = poco.DriverMedicalID; db.ExecuteNonQuery(sqlUpdate, new MySqlParameter("DriverMedicalReminderID", rem.DriverMedicalReminderID), new MySqlParameter("DriverMedicalID", rem.DriverMedicalID), new MySqlParameter("ReminderID", rem.ReminderID), new MySqlParameter("ReminderType", rem.ReminderType), new MySqlParameter("ShouldRemind", rem.ShouldRemind)); } } }
public static void SaveBlobView(DSModel db, KeyBinder key, FileBlobViewModel model) { if (db == null) { throw new ArgumentNullException("db"); } if (key == null) { throw new ArgumentNullException("key"); } if (model == null) { throw new ArgumentNullException("model"); } if (model.BlobID == 0) { throw new ArgumentException("BlobID cannot be 0!", "model"); } string sql = @" UPDATE file_blobs f SET f.BlobName = @BlobName, f.BlobDescription = @BlobDescription, f.BlobExtension = @BlobExtension WHERE f.BlobID = @BlobID;"; db.ExecuteNonQuery(sql, new MySqlParameter("BlobID", model.BlobID), new MySqlParameter("BlobName", model.BlobName), new MySqlParameter("BlobDescription", model.BlobDescription), new MySqlParameter("BlobExtension", model.BlobExtension)); }
private static void SaveDriverLicensePermits(DSModel db, KeyBinder key, DriversLicense poco, DriverLicenseModel model) { db.ExecuteNonQuery("DELETE FROM drivers_licenses_permits WHERE DriverLicenseID = @DriverLicenseID;", new MySqlParameter("DriverLicenseID", poco.DriverLicenseID)); string sql = @" INSERT INTO drivers_licenses_permits (DriverLicenseID, PermitID) VALUES (@DriverLicenseID, @PermitID); SELECT LAST_INSERT_ID();"; foreach (var per in model.Permits) { per.DriverLicenseID = poco.DriverLicenseID; per.DriverLicensePermitID = (uint)db.ExecuteScalar <ulong>(sql, new MySqlParameter("DriverLicenseID", per.DriverLicenseID), new MySqlParameter("PermitID", per.PermitID)); } }
private static void SaveDriverLicenseReminders(DSModel db, KeyBinder key, DriversLicense poco, DriverLicenseModel model) { db.ExecuteNonQuery("delete from drivers_licenses_reminders where DriverLicenseID = @DriverLicenseID;", new MySqlParameter("DriverLicenseID", poco.DriverLicenseID)); string sql = @" INSERT INTO drivers_licenses_reminders (DriverLicenseID, ReminderID, ReminderType, ShouldRemind) VALUES (@DriverLicenseID, @ReminderID, @ReminderType, @ShouldRemind); SELECT LAST_INSERT_ID();"; foreach (var rem in model.Reminders) { rem.DriverLicenseID = poco.DriverLicenseID; rem.DriverLicenseReminderID = (uint)db.ExecuteScalar <ulong>(sql, new MySqlParameter("DriverLicenseID", rem.DriverLicenseID), new MySqlParameter("ReminderID", rem.ReminderID), new MySqlParameter("ReminderType", rem.ReminderType), new MySqlParameter("ShouldRemind", rem.ShouldRemind)); } }