public static TopicAuthentication GetTopicAuthentication(Topic topic) { TopicAuthentication result = new TopicAuthentication(); result._topic = topic; TopicPermissionCollection topicPermissionList = TopicPermissionCollection.GetTopicPermissionCollection(); foreach (TopicPermission item in topicPermissionList) { result._listAuthentication.Add(item, new List <Role>()); } RoleCollection roleList = RoleCollection.GetRoleCollection(); Database database = new Database("PSCPortalConnectionString"); using (DbConnection connection = database.GetConnection()) { DbCommand command = database.GetCommand(connection); #region TopicId DbParameter prTopicId = database.GetParameter(System.Data.DbType.Guid, "@TopicId", topic.Id); command.Parameters.Add(prTopicId); #endregion command.CommandText = "TopicAuthentication_GetAllByTopicId"; command.CommandType = System.Data.CommandType.StoredProcedure; connection.Open(); DbDataReader reader = command.ExecuteReader(); int idtptemp; Guid idrtemp; TopicPermission tptemp; Role rtemp; while (reader.Read()) { idtptemp = (int)reader["TopicPermissionId"]; idrtemp = (Guid)reader["RoleId"]; tptemp = topicPermissionList.Where(tp => tp.Id == idtptemp).Single(); rtemp = roleList.Where(r => r.Id == idrtemp).Single(); result._listAuthentication[tptemp].Add(rtemp); } } return(result); }
public static TopicPermissionCollection GetTopicPermissionCollection() { TopicPermissionCollection result = new TopicPermissionCollection(); Database database = new Database("PSCPortalConnectionString"); using (DbConnection connection = database.GetConnection()) { DbCommand command = database.GetCommand(connection); command.CommandText = "TopicPermission_GetAll"; command.CommandType = System.Data.CommandType.StoredProcedure; connection.Open(); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { result.Add(new TopicPermission(reader)); } } } return(result); }