public void TestGetDiveType() { var diveType = new DiveType(1, "100a", 1.0f); var testType = DbHandler.GetDiveType("1"); Assert.AreEqual(diveType.Difficulty, testType.Difficulty); Assert.AreEqual(diveType.Code, testType.Code); Assert.AreEqual(diveType.Id, testType.Id); Assert.AreNotEqual("200c", testType.Code); }
public Dive(int id, DiveType diveType, float totalPoints, int order, int diverId) : base(id) { Assessments = new List<Assessment>(); DiverId = diverId; Type = diveType; TotalPoints = new Score(totalPoints); Order = order; //_name = Name; //Skall anropa en funktion som genererar namnet på hoppet från koden. }
public static List<DiveType> GetDiveTypes() { Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}"); const string sql = "SELECT * FROM divetype"; using (var sqlConnection = ConnectToDatabase()) { var tDiveTypes = new List<DiveType>(); using (var sqlQuery = new MySqlCommand(sql, sqlConnection)) { Logger.Info("Running Query: \"{0}\"", sql); var tableReader = sqlQuery.ExecuteReader(); while (tableReader.Read()) { var tDiveType = new DiveType( tableReader.GetInt32("Id"), tableReader.GetString("Code"), tableReader.GetFloat("Difficulty")); tDiveTypes.Add(tDiveType); } } Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); return tDiveTypes; } }
public static DiveType GetDiveType(string data) { Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}"); int id; int.TryParse(data, out id); var sql = id > 0 ? $"SELECT * FROM divetype WHERE ID = {id}" : $"SELECT * FROM divetype WHERE Code = '{data}'"; using (var sqlConnection = ConnectToDatabase()) { var diveType = new DiveType(); using (var sqlQuery = new MySqlCommand(sql, sqlConnection)) { Logger.Info("Running Query: \"{0}\"", sql); var tableReader = sqlQuery.ExecuteReader(); while (tableReader.Read()) { var tDiveType = new DiveType( tableReader.GetInt32("Id"), tableReader.GetString("Code"), tableReader.GetFloat("Difficulty")); diveType = tDiveType; } } Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}"); return diveType; } }