public CustomerDeviceRelations Get(int id) { DeviceAndCustomerFunctions a = new DeviceAndCustomerFunctions(); CustomerDeviceRelations temp = a.ReturnRelations(id); return(temp); }
public HttpResponseMessage Post([FromBody] CustomerDeviceRelations value) { DeviceAndCustomerFunctions temp = new DeviceAndCustomerFunctions(); int id = temp.NewRelations(value); HttpResponseMessage res = new HttpResponseMessage(System.Net.HttpStatusCode.Created); Regex x = new Regex(@"(\/CustomerAndDevice)"); res.Headers.Location = new Uri(x.Replace(Request.GetDisplayUrl(), "/CustomerAndDevice/" + id.ToString())); return(res); }
//Customer And Device Relationships public int NewRelations(CustomerDeviceRelations custom) { string sqlString = "INSERT INTO CustomerDeviceRelations (Customer_ID,Device_ID) VALUES( @Customer_id , @Device_id)"; System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlString, conn); cmd.Parameters.AddWithValue("@Customer_id", custom.Customer_ID); cmd.Parameters.AddWithValue("@Device_id", custom.Device_ID); cmd.ExecuteNonQuery(); System.Data.SqlClient.SqlDataReader reader = null; sqlString = "SELECT MAX(ID) FROM CustomerDeviceRelations"; cmd = new System.Data.SqlClient.SqlCommand(sqlString, conn); reader = cmd.ExecuteReader(); if (reader.Read()) { int id = reader.GetInt32(0); return(id); } else { return(-1); } }
public CustomerDeviceRelations ReturnRelations(int id) { CustomerDeviceRelations a = new CustomerDeviceRelations(); System.Data.SqlClient.SqlDataReader reader = null; string strSQL = "SELECT * FROM CustomerDeviceRelations WHERE ID = @id"; System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strSQL, conn); cmd.Parameters.AddWithValue("@id", id); reader = cmd.ExecuteReader(); if (reader.Read()) { a.ID = reader.GetInt32(0); a.Customer_ID = reader.GetInt32(1); a.Device_ID = reader.GetInt32(2); return(a); } else { return(null); } }