예제 #1
0
        private Collection <T> Read(SqlDataReader reader)
        {
            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();

            ManagerFactory         managerFactory  = new ManagerFactory();
            ManagerTable <Manager> instanceManager = (ManagerTable <Manager>)managerFactory.GetManagerInstance();


            Collection <T> messages = new Collection <T>();

            while (reader.Read())
            {
                Message message = new Message();
                int     i       = -1;
                message.id         = reader.GetInt32(++i);
                message.created    = reader.GetDateTime(++i);
                message.text       = reader.GetString(++i);
                message.isRead     = reader.GetBoolean(++i);
                message.dispatcher = instanceDispatcher.Select(reader.GetInt32(++i));
                message.manager    = instanceManager.Select(reader.GetInt32(++i));



                messages.Add((T)message);
            }
            return(messages);
        }
예제 #2
0
        public Manager SelectManagerSession(string token)
        {
            ManagerFactory         managerFactory  = new ManagerFactory();
            ManagerTable <Manager> instanceManager = (ManagerTable <Manager>)managerFactory.GetManagerInstance();

            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_SELECT);

            command.Parameters.AddWithValue("@token", token);
            SqlDataReader reader = db.Select(command);

            Collection <T> sessions = Read(reader);

            if (sessions.Count == 1)
            {
                if (sessions[0].type == "MANAGER")
                {
                    return(instanceManager.Select(sessions[0].user_id));
                }
            }
            reader.Close();
            db.Close();
            return(null);
        }