示例#1
0
        public AdHocDTO ReadFromBusID(int busID)
        {
            using var connection = Connection.GetConnection();
            {
                connection.OpenAsync();

                using var command   = connection.CreateCommand();
                command.CommandText = "SELECT * FROM `AdHoc` WHERE BusID = @busID";
                command.Parameters.AddWithValue("@busID", busID);

                var reader = command.ExecuteReader();

                if (!reader.Read())
                {
                    return(null);
                }

                var adhocobj = new AdHocDTO()
                {
                    AdHocID       = reader.GetInt32("AdHocID"),
                    BusID         = reader.GetInt32("BusID"),
                    AccountID     = reader.GetInt32("AccountID"),
                    Type          = reader.GetInt32("Type"),
                    Team          = reader.GetInt32("Team"),
                    Description   = reader.GetString("Description"),
                    TimeSubmitted = reader.GetDateTime("TimeSubmitted"),
                    TimeDone      = reader.GetDateTime("TimeDone")
                };
                return(adhocobj);
            }
        }
示例#2
0
        public bool Create(AdHocDTO adHocDTO)
        {
            using var connection = Connection.GetConnection();
            {
                try
                {
                    using var command = connection.CreateCommand();

                    command.CommandText = "INSERT INTO AdHoc(BusID, Type, Team, Description, TimeSubmitted) VALUES(@busID, @type, @team, @description, @timeSubmitted);";
                    command.Parameters.AddWithValue("@busID", adHocDTO.BusID);
                    command.Parameters.AddWithValue("@type", adHocDTO.Type);
                    command.Parameters.AddWithValue("@team", adHocDTO.Team);
                    command.Parameters.AddWithValue("@description", adHocDTO.Description);
                    command.Parameters.AddWithValue("@timeSubmitted", adHocDTO.TimeSubmitted);

                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                    return(true);
                }
                catch { connection.Close(); return(false); }
            }
        }