/// <summary> /// This getSharedResourceByGivenName() method returns the shared folder model of givenname and uid /// </summary> /// <param name="connection"></param> /// <param name="uid"></param> /// <param name="givenName"></param> /// <returns></returns> public Model.CListModel getSharedResourceByGivenName(SqlConnection connection, int uid, String givenName) { try { command = new SqlCommand("SELECT C.RID, C.UID, C.OWNER, C.READWRITE FROM CLIST C, CONTAINERS CO WHERE C.UID = @UID AND CO.GIVENNAME = @GIVENNAME AND C.RID = CO.RID"); command.CommandType = CommandType.Text; command.Connection = connection; command.Parameters.AddWithValue("@UID", uid); command.Parameters.AddWithValue("@GIVENNAME", givenName); reader = command.ExecuteReader(); //no containers shared by ownerid if (!reader.HasRows) { return(null); } Model.CListModel cl = new Model.CListModel(); while (reader.Read()) { cl.setRid(reader.GetInt32(0)); cl.setUid(reader.GetInt32(1)); cl.setOwner(reader.GetInt32(2)); cl.setReadwrite(reader.GetInt32(3)); } reader.Close(); return(cl); } catch (SqlException ex) { Console.WriteLine("CLISTM class getSharedResouceByGivenName method exception->" + ex.Message); return(null); } }
/// <summary> /// This grantRights() method set the rights to the otheruserID /// </summary> /// <param name="otheruserID"></param> /// <param name="containerID"></param> /// <param name="writeAccess"></param> /// <returns>true/false</returns> public Boolean grantRights(int otheruserID, int containerID, Boolean writeAccess) { DBManager.ResourceM resmgr = new DBManager.ResourceM(); Model.AzureContainerModel rmodel = new Model.AzureContainerModel(); Model.CListModel cmodel = new Model.CListModel(); try { rmodel = resmgr.getResourceById(connection, containerID); DBManager.CListM cmgr = new DBManager.CListM(); Model.CListModel cmodel1 = new Model.CListModel(); cmodel1 = cmgr.getSharedResourceByGivenName(connection, otheruserID, rmodel.getGivenName()); if (cmodel1 != null) { //If permission already granted to otheruser, then check if requested permission is same Boolean test = false; if (cmodel1.getReadwrite() == 1) { test = true; } if (test == writeAccess) { return(true); //already exist with same permission } else { cmgr.deleteUserEntryFromCLIST(connection, otheruserID, containerID); //delete the record and re-enter } } cmodel.setRid(containerID); cmodel.setUid(otheruserID); cmodel.setOwner(rmodel.getOwner()); if (writeAccess) { cmodel.setReadwrite(1); } else { cmodel.setReadwrite(0); } //Insert into CLIST table bool success = cmgr.insertIntoCList(connection, cmodel); return(success); } catch (DBLikeExceptions.CloudContainerNotFoundException) { return(false); } }