コード例 #1
0
ファイル: PlaceRepository.cs プロジェクト: m13oas/DevSchool
 public async Task<int> GetId(Place place) {
     using(var client = new HttpClient {
         BaseAddress = new Uri(@"http://localhost:57239/")
     }) {
         var response = client.GetAsync($"api/place/id/country/{place.country}/city/{place.city}/street/{place.street}/house/{place.house}/flat/{place.flat}").Result;
         return await response.Content.ReadAsAsync<int>();
     }
 }
コード例 #2
0
ファイル: MeetRepository.cs プロジェクト: m13oas/DevSchool
        public async Task<int> CreateMeet(Place place, DateTime dateMeet, Guid idUser, int idPlace) {
            using(var client = new HttpClient {
                BaseAddress = new Uri(@"http://localhost:57239/")
            }) {
                var response = client.PostAsJsonAsync($"api/meeting/create/{idPlace}", dateMeet).Result;
                return await response.Content.ReadAsAsync<int>();
//                response = client.PostAsJsonAsync($"api/subscription/subscribe/{idMeet}", idUser).Result;
//                return response.Content.ReadAsAsync<bool>().Result;
            }
        }
コード例 #3
0
ファイル: PlaceRepository.cs プロジェクト: m13oas/DevSchool
        public int GetId(Place place)
        {
            logger.Log(LogLevel.Info, $"Start getting place id");
            using(var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DevSchoolDB"].ConnectionString)) {
                connection.Open();
                using(var command = connection.CreateCommand()) {
                    command.CommandText = "select idPlace from [dbo].[Place] where country = @country and city = @city and street = @street and house = @house and flat = @flat";
                    command.Parameters.AddWithValue("@country", place.country);
                    command.Parameters.AddWithValue("@city", place.city);
                    command.Parameters.AddWithValue("@street", place.street);
                    command.Parameters.AddWithValue("@house", place.house);
                    command.Parameters.AddWithValue("@flat", place.flat);

                    using(var reader = command.ExecuteReader()) {
                        reader.Read();
                        logger.Log(LogLevel.Info, $"End getting place id");
                        return reader.HasRows ? reader.GetInt32(0) : 0;
                    }
                }
            }
        }
コード例 #4
0
ファイル: PlaceRepository.cs プロジェクト: m13oas/DevSchool
 public void Add(Place place)
 {
     logger.Log(LogLevel.Info, $"Start adding new place with id = {place.idPlace}");
     if(place == null) {
         logger.Log(LogLevel.Error, $"Adding place is null");
         throw new ArgumentNullException();
     }
     using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DevSchoolDB"].ConnectionString)) {
         connection.Open();
         using (var command = connection.CreateCommand()) {
             command.CommandText = "insert into [dbo].[Place] (country, city, street, house, flat) values (@country, @city, @street, @house, @flat)";
             command.Parameters.AddWithValue("@country", place.country);
             command.Parameters.AddWithValue("@city", place.city);
             command.Parameters.AddWithValue("@street", place.street);
             command.Parameters.AddWithValue("@house", place.house);
             command.Parameters.AddWithValue("@flat", place.flat);
             command.ExecuteNonQuery();
         }
     }
     logger.Log(LogLevel.Info, $"End adding new place with id = {place.idPlace}");
 }