Esempio n. 1
0
        static async Task Main(string[] args)
        {
            RegisterServices();
            var access = ApplicationServices.GetRequiredService <DatabaseAccess>();
            await access.ReadData(2016);

            await access.ReadData(2017);

            ParkrunModel parkrun = new ParkrunModel
            {
                Race     = 293,
                Grade    = "50.48",
                RaceDate = new DateTime(2019, 1, 5),
                Position = 207,
                Minutes  = 29,
                Seconds  = 13
            };

            //	await access.InsertRace(parkrun);

            await access.GetBestRace();

            Console.WriteLine("Enter the year");
            var year = Console.ReadLine();

            await access.ReadDataUsingStoredProcedure(int.Parse(year));

            Console.ReadLine();
        }
Esempio n. 2
0
        public async Task InsertRace(ParkrunModel parkrun)
        {
            using (SqlConnection connection = new SqlConnection(_config))
            {
                connection.Open();
                string sql = @"INSERT INTO [dbo].[Parkruns] ([RaceDate],[Race],[Position],[Grade],[Minutes],[Seconds])
								VALUES (@RaceDate,@Race,@Position,@Grade,@Minutes,@Seconds)"                                ;

                var command = new SqlCommand(sql, connection);
                command.Parameters.Add("RaceDate", SqlDbType.DateTime);
                command.Parameters["RaceDate"].Value = parkrun.RaceDate;
                command.Parameters.Add("Race", SqlDbType.Int);
                command.Parameters["Race"].Value = parkrun.Race;
                command.Parameters.Add("Position", SqlDbType.Int);
                command.Parameters["Position"].Value = parkrun.Position;
                command.Parameters.Add("Grade", SqlDbType.NVarChar, 50);
                command.Parameters["Grade"].Value = parkrun.Grade;
                command.Parameters.Add("Minutes", SqlDbType.Int);
                command.Parameters["Minutes"].Value = parkrun.Minutes;
                command.Parameters.Add("Seconds", SqlDbType.Int);
                command.Parameters["Seconds"].Value = parkrun.Seconds;

                var result = await command.ExecuteNonQueryAsync();

                _logger.LogInformation("Record successfully inserted");
            }
        }