Beispiel #1
0
        public wsSQLResult InsertNewRouterSetup(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();
                RouterSetups         rs  = jss.Deserialize <RouterSetups>(JSONdata);
                if (rs == 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
                RouterSetups_HNR newRS = new RouterSetups_HNR()
                {
                    SetupID        = rs.SetupID,
                    SetupName      = rs.SetupName,
                    Name           = rs.Name,
                    IPaddress      = rs.IPaddress,
                    UserID         = rs.UserID,
                    Password       = rs.Passwd,
                    SSID24         = rs.SS24,
                    Password24     = rs.PW24,
                    SSID50         = rs.SS50,
                    Password50     = rs.PW50,
                    EncryptionType = rs.EncryptionType,
                    Mode           = rs.Mode,
                    Comments       = rs.Comments
                };

                dc.RouterSetups_HNRs.InsertOnSubmit(newRS);
                dc.SubmitChanges();

                result.WasSuccessful = 1;
                result.Exception     = "";
                return(result);
            }
            catch (Exception ex)
            {
                result.WasSuccessful = 0;
                result.Exception     = ex.Message;
                return(result);
            }
        }
Beispiel #2
0
        public wsSQLResult UpdateRouterSetup(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();
                RouterSetups         rs  = jss.Deserialize <RouterSetups>(JSONdata);
                if (rs == null)
                {
                    // Error: Couldn't deserialize JSON String
                    result.WasSuccessful = 0;
                    result.Exception     = "Unable to deserialize the JSON data.";
                    return(result);
                }
                HomeNetworkDataContext dc        = new HomeNetworkDataContext();
                RouterSetups_HNR       currentRS = dc.RouterSetups_HNRs.Where(r => r.SetupID == rs.SetupID).FirstOrDefault();
                if (currentRS == null)
                {
                    // Couldnt Find User to Update
                    result.WasSuccessful = -3;
                    result.Exception     = "Could not find a [RouterSetups_HNR] record with ID: " + rs.SetupID.ToString();
                    return(result);
                }

                // Update Record to SQL Server Table
                currentRS.SetupID        = rs.SetupID;
                currentRS.SetupName      = rs.SetupName;
                currentRS.Name           = rs.Name;
                currentRS.IPaddress      = rs.IPaddress;
                currentRS.UserID         = rs.UserID;
                currentRS.Password       = rs.Passwd;
                currentRS.SSID24         = rs.SS24;
                currentRS.Password24     = rs.PW24;
                currentRS.SSID50         = rs.SS50;
                currentRS.Password50     = rs.PW50;
                currentRS.EncryptionType = rs.EncryptionType;
                currentRS.Mode           = rs.Mode;
                currentRS.Comments       = rs.Comments;
                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
            }
        }