// POST api/Info_about_way public HttpResponseMessage PostInfo_about_way(Info_about_way info_about_way) { if (ModelState.IsValid) { db.Info_about_ways.Add(info_about_way); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, info_about_way); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = info_about_way.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/Info_about_way/5 public HttpResponseMessage PutInfo_about_way(int id, Info_about_way info_about_way) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != info_about_way.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(info_about_way).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public Info_about_way Return_info_about_way(int par) { Info_about_way obj = new Info_about_way(); using (var connection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL"].ToString())) { connection1.Open(); using (var command1 = new SqlCommand(String.Format("SELECT * FROM WAY WHERE ID_WAY = '{0}'", par))) { command1.Connection = connection1; using (var reader = command1.ExecuteReader()) { while (reader.Read()) { obj.Way_info.Count_Free = Convert.ToInt32(reader["Count_Free"].ToString()); obj.Way_info.Data_Time = DateTime.Parse(reader["Data_Time"].ToString()); obj.Way_info.Finish = reader["Finish"].ToString(); obj.Way_info.Id_main = Convert.ToInt32(reader["ID_main_USER"].ToString()); obj.Way_info.Infa = reader["Infa"].ToString(); obj.Way_info.Start = reader["Start"].ToString(); obj.Way_info.Transport_id = Convert.ToInt32(reader["Transport_id"].ToString()); obj.Way_info.ID_WAY = Convert.ToInt32(reader["ID_WAY"].ToString()); } } } using (var command1 = new SqlCommand(String.Format("SELECT * FROM Registration WHERE ID_USER_proect =" + obj.Way_info.Id_main))) { command1.Connection = connection1; using (var reader = command1.ExecuteReader()) { while (reader.Read()) { obj.User_main.Email = reader["Email"].ToString(); obj.User_main.ID_USER_proect = Convert.ToInt32(reader["ID_USER_proect"].ToString()); obj.User_main.Name_user = reader["Name_user"].ToString(); obj.User_main.Phone_number = reader["Phone_number"].ToString(); obj.User_main.SurName_user = reader["SurName_user"].ToString(); } } } using (var command1 = new SqlCommand(String.Format(@"SELECT * FROM TRIP INNER JOIN Registration ON TRIP.ID_USER_proect = Registration.ID_USER_proect WHERE TRIP.ID_WAY =" + obj.Way_info.ID_WAY))) { command1.Connection = connection1; using (var reader = command1.ExecuteReader()) { while (reader.Read()) { obj.On_me.Add(Convert.ToInt32(reader["With_me"].ToString())); obj.Companion.Add(new Registration( Convert.ToInt32(reader["ID_USER_proect"].ToString()), reader["Name_user"].ToString(), reader["SurName_user"].ToString(), reader["Phone_number"].ToString(), reader["Email"].ToString(), "", "")); } } } } return obj; }