// POST api/Way_collection_search
        public HttpResponseMessage PostWay_collection(Way_collection way_collection)
        {
            if (ModelState.IsValid)
            {
                db.Way_collections.Add(way_collection);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, way_collection);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = way_collection.id }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
        // PUT api/Way_collection_search/5
        public HttpResponseMessage PutWay_collection(int id, Way_collection way_collection)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != way_collection.id)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            db.Entry(way_collection).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        public Way_collection Return_col_search(int id)
        {
            Way_collection obj = new Way_collection();
               String Start = "", Finish = "";
               String[] ID_transport = {};
               DateTime DataTime_with = DateTime.Parse("21.12.2015"), DataTime_before = DateTime.Parse("21.12.2015");
               using (var connection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL"].ToString()))
               {
               connection1.Open();

               using (var command1 = new SqlCommand(String.Format(@"SELECT Start, Finish,ID_transport, DataTime_with, DataTime_before
                                                                    FROM Inquiry_table WHERE ID_Inquiry =" + id)))
               {
                   command1.Connection = connection1;
                   using (var reader = command1.ExecuteReader())
                   {

                       while (reader.Read())
                       {

                           Start = reader["Start"].ToString();
                           Finish = reader["Finish"].ToString();
                           ID_transport = reader["ID_transport"].ToString().Split('.');
                           DataTime_with = DateTime.Parse(reader["DataTime_with"].ToString());
                           DataTime_before = DateTime.Parse(reader["DataTime_before"].ToString());
                       }
                   }
                   foreach (string element in ID_transport)
                   {
                       if (element.Length != 0)
                       {
                           command1.CommandText = @"SELECT *
                                         FROM WAY
                                         WHERE Start = '" + Start + "' AND Finish = '" + Finish +
                                                 "' AND  Data_Time = '" + DataTime_with +
                                                 "' AND  DataTime_before ='" + DataTime_before +
                                                 "' AND ID_transport = '" + Convert.ToInt32(element) + "'";

                           using (var reader = command1.ExecuteReader())
                           {

                               while (reader.Read())
                               {
                                   obj.Way_col.Add(new Way(Convert.ToInt32(reader["ID_WAY"].ToString()),
                                       (reader["Start"].ToString()),
                                       (reader["Finish"].ToString()),
                                       (reader["Data_Time"].ToString()),
                                       Convert.ToInt32(reader["Count_Free"].ToString()),
                                       (reader["Infa"].ToString()),
                                       Convert.ToInt32(reader["Transport_id"].ToString()),
                                       Convert.ToInt32(reader["ID_main_USER"].ToString())));
                               }
                           }
                       }
                   }
               }
               }
               return obj;
        }
        public Way_collection return_infa_way(int par)
        {
            Way_collection obj = new Way_collection();
               using (var connection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL"].ToString()))
               {
               connection1.Open();
               using (var command1 = new SqlCommand(String.Format("SELECT * FROM WAY WHERE ID_main_USER ="******"ID_WAY"].ToString()),
                               (reader["Start"].ToString()),
                               (reader["Finish"].ToString()),
                               (reader["Data_Time"].ToString()),
                               Convert.ToInt32(reader["Count_Free"].ToString()),
                               (reader["Infa"].ToString()),
                               Convert.ToInt32(reader["Transport_id"].ToString()),
                               Convert.ToInt32(reader["ID_main_USER"].ToString())));
                       }
                   }
               }
               }
               return obj;
        }
        public Way_collection Add_inquiry(Inquiry inquiry)
        {
            String[] ID_transport = inquiry.ID_transport.Split('.'); ;
               Way_collection obj = new Way_collection();
              // DateTime DataTime_with = DateTime.Parse(inquiry.Data + "" + inquiry.Time_with);
             //  DateTime DataTime_before = DateTime.Parse(inquiry.Data + "" + inquiry.Time_with);
               using (var connection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL"].ToString()))
               {
               connection1.Open();
               foreach (string element in ID_transport)
               {
                   if (element.Length != 0)
                   {
                       using (var command1 = new SqlCommand(String.Format(@"SELECT *
                                         FROM WAY
                                         WHERE Start = '" + inquiry.Start + "' AND Finish = '" + inquiry.Finish +
                                                         "' AND  (Data_Time >= '" + (inquiry.Data + " " + inquiry.Time_with) +
                                                         "' AND  Data_Time <='" + (inquiry.Data + " " + inquiry.Time_before) +
                                                         "') AND Transport_id = '" + Convert.ToInt32(element) + "'")))
                       {
                           command1.Connection = connection1;
                           using (var reader = command1.ExecuteReader())
                           {

                               while (reader.Read())
                               {
                                   obj.Way_col.Add(new Way(Convert.ToInt32(reader["ID_WAY"].ToString()),
                                       (reader["Start"].ToString()),
                                       (reader["Finish"].ToString()),
                                       (reader["Data_Time"].ToString()),
                                       Convert.ToInt32(reader["Count_Free"].ToString()),
                                       (reader["Infa"].ToString()),
                                       Convert.ToInt32(reader["Transport_id"].ToString()),
                                       Convert.ToInt32(reader["ID_main_USER"].ToString())));
                               }
                           }
                       }
                   }
               }
               }
               return obj;
        }