Example #1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken ct)
        {
            using TransactionScope tran    = Tran.BeginScope(IsolationLevel.ReadUncommitted);
            using SqlConnection connection = _dbContextFactory.CreateConnection();
            await connection.OpenAsync(ct);

            SqlCommand cmd = connection.CreateCommand();

            cmd.CommandText =
                "select top(1) MigrationId from Tds.__EFMigrationsHistory order by MigrationId desc";
            object lastMigration = await cmd.ExecuteScalarAsync(ct);

            cmd.CommandText = "select count(*) from Tds.__EFMigrationsHistory";
            object count = await cmd.ExecuteScalarAsync(ct);

            return(HealthCheckResult.Healthy(
                       CompareMigrationHistoryToAssembly(lastMigration.ToString(), int.Parse(count.ToString() !))));
        }
        async Task <ICollection <State> > IStateService.GetStatesAsync()
        {
            try
            {
                List <State> list = new List <State>();

                using (MySqlConnection con = _dbContextFactory.CreateConnection())
                {
                    await con.OpenAsync();

                    using (MySqlCommand cmd = new MySqlCommand("select s.* from State s", con))
                    {
                        using (var reader = await cmd.ExecuteReaderAsync())
                        {
                            while (reader.Read())
                            {
                                list.Add(new State()
                                {
                                    state_id    = Convert.ToInt32(reader["state_id"]),
                                    countryCode = reader["countryCode"].ToString(),
                                    name_id     = Convert.ToInt32(reader["name_id"]),
                                    stateCode   = reader["stateCode"].ToString(),
                                    latitude    = Convert.ToDecimal(reader["latitude"]),
                                    longitude   = Convert.ToDecimal(reader["longitude"]),
                                    polygon     = reader["polygon"].ToString()
                                });
                            }
                        }
                    }
                    await con.CloseAsync();
                }
                return(list);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public async Task <ICollection <GeoTableView> > GetGeoTableViewAsync()
        {
            try
            {
                List <GeoTableView> list = new List <GeoTableView>();

                using (MySqlConnection con = _dbContextFactory.CreateConnection())
                {
                    await con.OpenAsync();

                    using (MySqlCommand cmd = new MySqlCommand("select g.* from GeoTableView g", con))
                    {
                        using (var reader = await cmd.ExecuteReaderAsync())
                        {
                            while (reader.Read())
                            {
                                list.Add(new GeoTableView()
                                {
                                    Id         = Convert.ToInt32(reader["Id"]),
                                    WardId     = Convert.ToInt32(reader["WardId"]),
                                    Ward       = reader["Ward"].ToString(),
                                    DistrictId = Convert.ToInt32(reader["DistrictId"]),
                                    District   = reader["District"].ToString(),
                                    CityId     = Convert.ToInt32(reader["CityId"]),
                                    City       = reader["City"].ToString()
                                });
                            }
                        }
                    }
                    await con.CloseAsync();
                }
                return(list);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }