public wsSQLResult DeleteNetDevice(string NetDeviceID) { wsSQLResult result = new wsSQLResult(); try { HomeNetworkDataContext dc = new HomeNetworkDataContext(); NetworkDevices_HNND netDevice = dc.NetworkDevices_HNNDs.Where(n => n.NetworkDeviceID == NetDeviceID).FirstOrDefault(); if (netDevice == null) { result.WasSuccessful = -3; result.Exception = "Could not find a [NetworkDevices_HNND] record with ID: " + NetDeviceID.ToString(); return(result); } dc.NetworkDevices_HNNDs.DeleteOnSubmit(netDevice); dc.SubmitChanges(); result.WasSuccessful = 1; result.Exception = ""; return(result); //Success } catch (Exception ex) { result.WasSuccessful = -1; result.Exception = "An exception occurred: " + ex.Message; return(result); //Failed } }
public wsSQLResult InsertNewDevice(Stream JSONdataStream) { wsSQLResult result = new wsSQLResult(); try { //Read JSON Stream into a String.. StreamReader reader = new StreamReader(JSONdataStream); string JSONdata = reader.ReadToEnd(); // Convert to New User record.. JavaScriptSerializer jss = new JavaScriptSerializer(); NetworkDevices netDevice = jss.Deserialize <NetworkDevices>(JSONdata); if (netDevice == null) { // Error: Couldn't deserialize JSON String result.WasSuccessful = 0; result.Exception = "Unable to deserialize the JSON data."; return(result); } HomeNetworkDataContext dc = new HomeNetworkDataContext(); //if (user.UserID == Convert.ToString(dc.Users_HNUs.Where(i => i.UserID == user.UserID).FirstOrDefault())) //{ // // User Already Exists // return -3; //} // Insert Record to SQL Server Table NetworkDevices_HNND newDevice = new NetworkDevices_HNND() { NetworkDeviceID = netDevice.NetworkDeviceID, NetworkDeviceName = netDevice.NetworkDeviceName, MacAddress = netDevice.MacAddress, IPaddress = netDevice.IPaddress, NetworkDeviceTypeID = netDevice.NetworkDeviceTypeID, NetworkPorts = netDevice.NetworkPorts, LocationID = netDevice.LocationID }; dc.NetworkDevices_HNNDs.InsertOnSubmit(newDevice); dc.SubmitChanges(); result.WasSuccessful = 1; result.Exception = ""; return(result); } catch (Exception ex) { result.WasSuccessful = 0; result.Exception = ex.Message; return(result); } }
public wsSQLResult UpdateNetDevice(Stream JSONdataStream) { wsSQLResult result = new wsSQLResult(); try { //Read JSON Stream into a String.. StreamReader reader = new StreamReader(JSONdataStream); string JSONdata = reader.ReadToEnd(); // Convert to New User record.. JavaScriptSerializer jss = new JavaScriptSerializer(); NetworkDevices netDevice = jss.Deserialize <NetworkDevices>(JSONdata); if (netDevice == null) { // Error: Couldn't deserialize JSON String result.WasSuccessful = 0; result.Exception = "Unable to deserialize the JSON data."; return(result); } HomeNetworkDataContext dc = new HomeNetworkDataContext(); NetworkDevices_HNND currentDevice = dc.NetworkDevices_HNNDs.Where(n => n.NetworkDeviceID == netDevice.NetworkDeviceID).FirstOrDefault(); if (currentDevice == null) { // Couldnt Find User to Update result.WasSuccessful = -3; result.Exception = "Could not find a [NetworkDevices_HNND] record with ID: " + netDevice.NetworkDeviceID.ToString(); return(result); } // Update Record to SQL Server Table currentDevice.NetworkDeviceID = netDevice.NetworkDeviceID; currentDevice.NetworkDeviceName = netDevice.NetworkDeviceName; currentDevice.MacAddress = netDevice.MacAddress; currentDevice.IPaddress = netDevice.IPaddress; currentDevice.NetworkDeviceTypeID = netDevice.NetworkDeviceTypeID; currentDevice.NetworkPorts = netDevice.NetworkPorts; currentDevice.LocationID = netDevice.LocationID; dc.SubmitChanges(); result.WasSuccessful = 1; result.Exception = ""; return(result); //Success } catch (Exception ex) { result.WasSuccessful = -1; result.Exception = "An exception occurred: " + ex.Message; return(result); //Failed } }