public HubList Post([FromBody] HubList hubList) { HubList hubList1 = new HubList(); hubList1.InsertHubList(hubList); return(hubList); }
//Insert HubList to database public void insertHubList(HubList hList) { SqlConnection con = null; SqlCommand cmd1; SqlCommand cmd2; try { con = connect("DBConnectionString"); // create the connection String cStr1 = BuildInsertCommand(hList); // helper method to build the insert string cmd1 = CreateCommand(cStr1, con); // create the command Int32 CreatedListID = Convert.ToInt32(cmd1.ExecuteScalar()); // execute the command String cStr2 = BuildInsertCommandUser_Lists(hList, CreatedListID); // helper method to build the insert string cmd2 = CreateCommand(cStr2, con); // create the command cmd2.ExecuteScalar(); } catch (Exception ex) { Console.WriteLine("Inside catch block. Exception: {0}", ex.Message); throw (ex); } finally { if (con != null) { con.Close(); } } }
private String BuildInsertCommandUser_Lists(HubList hlist, int CreatedListID) { String command; StringBuilder sb = new StringBuilder(); // use a string builder to create the dynamic string sb.AppendFormat("Values({0},{1})", hlist.OwnerUserID, CreatedListID); String prefix = "INSERT INTO User_Lists_CS " + "(UserID,ListID)"; command = prefix + sb.ToString(); return(command); }
public TypeScriptHubList Create(HubList hubList) { var typeScriptClasslist = new List <TypeScriptHub>(); var typeScriptHubClassFactory = new TypeScriptHubClassFactory(); foreach (var hub in hubList.Hubs) { var typeScriptClass = typeScriptHubClassFactory.Create(hub.HubType, hub.HubClientType); typeScriptClasslist.Add(typeScriptClass); } return(new TypeScriptHubList(typeScriptClasslist)); }
public int Delete(int UserID, int ListID) { HubList myList = new HubList(); User myUser = new User(); int CheckResult = myUser.CheckListOwnerShip(UserID, ListID); //1 Means he is the TableOwner if (CheckResult == 1) { myList.DeleteHubList(ListID, UserID); } return(CheckResult); }
//-------------------------------------------------------------------- // Build the Insert command String //-------------------------------------------------------------------- private String BuildInsertCommand(HubList hlist) { String command; StringBuilder sb = new StringBuilder(); // use a string builder to create the dynamic string sb.AppendFormat("Values({0},'{1}','{2}','{3}')", hlist.OwnerUserID, hlist.ListName, hlist.ImageURL, hlist.ListDescription); String prefix = "INSERT INTO HubList_CS " + "(OwnerUserID,ListName,ImageURL,ListDescription) "; command = prefix + sb.ToString(); command += "SELECT SCOPE_IDENTITY()"; return(command); }
//Get All Lists from DB public List <HubList> getHubList() { SqlConnection con = null; // SqlConnection con2 = null; try { con = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file String selectSTR = "SELECT * FROM HubList_CS"; SqlCommand cmd = new SqlCommand(selectSTR, con); // SqlCommand cmd2; // get a reader SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end // SqlDataReader dr2; List <HubList> HubLists = new List <HubList>(); while (dr.Read()) { // Read till the end of the data into a row HubList hubList = new HubList(); hubList.ListID = Convert.ToInt32(dr["ListID"]); hubList.OwnerUserID = Convert.ToInt32(dr["OwnerUserID"]); hubList.ListName = (string)dr["ListName"]; hubList.ImageURL = (string)dr["ImageURL"]; hubList.ListDescription = (string)dr["ListDescription"]; HubLists.Add(hubList); } con.Close(); cmd.Connection.Close(); return(HubLists); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { con.Close(); } } }
//Get All Lists from DB by USERID public List <HubList> getUserLists(int userID) { SqlConnection con = null; // SqlConnection con2 = null; try { con = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file String selectSTR = "SELECT HL.ListID,ListName,ListDescription,OwnerUserID,ImageURL FROM HubList_CS AS HL"; selectSTR += " INNER JOIN User_Lists_CS AS UL ON HL.ListID = UL.ListID"; selectSTR += " INNER JOIN User_CS AS U ON U.UserID = UL.UserID"; selectSTR += " WHERE U.UserID=" + userID; SqlCommand cmd = new SqlCommand(selectSTR, con); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end List <HubList> HubLists = new List <HubList>(); while (dr.Read()) { HubList hubList = new HubList(); hubList.ListID = Convert.ToInt32(dr["ListID"]); hubList.OwnerUserID = Convert.ToInt32(dr["OwnerUserID"]); hubList.ListName = (string)dr["ListName"]; hubList.ImageURL = (string)dr["ImageURL"]; hubList.ListDescription = (string)dr["ListDescription"]; HubLists.Add(hubList); } con.Close(); cmd.Connection.Close(); return(HubLists); } catch (Exception ex) { throw (ex); } finally { if (con != null) { con.Close(); } } }
public SoftEtherList <HubList> GetList() { var rawData = _softEther.CallMethod("EnumHub"); return(HubList.DeserializeMany(rawData)); }
public void RemoveHub(NodePeer h) { HubList.Remove(h); }
public void AddHub(NodePeer h) { HubList.Add(h); }
public void AddHubs(List <NodePeer> hubs) { HubList.AddRange(hubs); }
// GET api/<controller> public IEnumerable <HubList> Get() { HubList hl = new HubList(); return(hl.getHubLists()); }