/// <summary> /// This method returns the list of containers which are shared with given user /// each element seems like "CONTAINERNAME:OWNERFULLNAME:GIVENCONTAINERNAME" //User friendly manner /// </summary> /// <param name="connection"></param> /// <param name="userid"></param> /// <returns>null/string array contains the name of containers</returns> public String[] getSharedContainersWithUser(SqlConnection connection, int userid) { String[] sharedContainers = null; try { command = new SqlCommand("SELECT RID, OWNER FROM CLIST WHERE UID = @UID"); command.CommandType = CommandType.Text; command.Connection = connection; command.Parameters.AddWithValue("@UID", userid); reader = command.ExecuteReader(); //no containers shared with user if (!reader.HasRows) { return(null); } ResourceM r = new ResourceM(); UserM u = new UserM(); int currRid = 0; String ownerName = null; Model.AzureContainerModel cont = new Model.AzureContainerModel(); List <String> containersString = new List <String>(); while (reader.Read()) { currRid = reader.GetInt32(0); cont = r.getResourceById(connection, currRid); Console.WriteLine("Owner: " + reader.GetInt32(1)); ownerName = (u.getUserRecordByID(connection, (reader.GetInt32(1)))).getFullName(); containersString.Add((cont.getContainerName()) + ":" + ownerName + ":" + (cont.getGivenName())); } reader.Close(); sharedContainers = containersString.ToArray(); return(sharedContainers); } catch (SqlException ex) { Console.WriteLine("CListM class: getSharedContainersWithUser method Exception->" + ex.Message); } return(null); }
/// <summary> /// This method returns the list of containers which are shared by given ownerid /// each element seems like "CONTAINERNAME:GIVENNAME" //User friendly manner /// </summary> /// <param name="connection"></param> /// <param name="ownerid"></param> /// <returns></returns> public String[] getSharedContainersOwnedByUser(SqlConnection connection, int ownerid) { String[] sharedContainers = null; try { command = new SqlCommand("SELECT RID FROM CLIST WHERE OWNER = @OWNER"); command.CommandType = CommandType.Text; command.Connection = connection; command.Parameters.AddWithValue("@OWNER", ownerid); reader = command.ExecuteReader(); //no containers shared by ownerid if (!reader.HasRows) { return(null); } ResourceM r = new ResourceM(); int currRid = 0; List <String> containersString = new List <String>(); while (reader.Read()) { currRid = reader.GetInt32(0); containersString.Add(((r.getResourceById(connection, currRid)).getContainerName()) + ":" + ((r.getResourceById(connection, currRid)).getGivenName())); } reader.Close(); foreach (string author in containersString) { Console.WriteLine(author); } sharedContainers = containersString.ToArray(); return(sharedContainers); } catch (SqlException ex) { Console.WriteLine("CListM class: getSharedContainersOwnedByUser method Exception->" + ex.Message); } return(null); }