Exemplo n.º 1
0
 /// <summary>
 /// Fetches a given role
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static OperationRole FetchById(int id)
 {
     Datamodel.OperationRole r = null;
     if (Datamodel.OperationRole.FetchById(ref r, id))
     {
         return(new OperationRole(r));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Fetches a specific operation role
        /// </summary>
        /// <param name="output"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool FetchById(ref OperationRole output, int id)
        {
            SQLiteDataReader reader = DBI.DoPreparedQuery(
                "SELECT * FROM OperationRole WHERE id = @id LIMIT 1;",
                new Tuple <string, object>("@id", id));

            if (reader != null && reader.Read())
            {
                output = OperationRole.Factory(reader);
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public static OperationRole Factory(SQLiteDataReader reader)
        {
            OperationRole result = new OperationRole(
                id: Convert.ToInt32(reader["id"]),
                name: (string)reader["name"],
                rate: Convert.ToInt32(reader["associatedRate"]),
                ships: Convert.ToBoolean(reader["onShips"]),
                boats: Convert.ToBoolean(reader["onBoats"]),
                squads: Convert.ToBoolean(reader["inSquads"]),
                channelCdr: Convert.ToBoolean(reader["channelCdr"])
                );

            return(result);
        }
Exemplo n.º 4
0
        public static OperationRole Factory()
        {
            OperationRole result = new OperationRole(
                id: -1,
                name: "",
                rate: -1,
                ships: false,
                boats: false,
                squads: false,
                channelCdr: false
                );

            return(result);
        }
Exemplo n.º 5
0
        private OperationRole(Datamodel.OperationRole r)
        {
            id   = r.id;
            name = r.name;

            rateId = r.rate;
            Datamodel.Rate rate = null;
            if (!Datamodel.Rate.FetchById(ref rate, rateId))
            {
                throw new ArgumentException("Role does not have valid rate");
            }
            rateAbbrev = rate.abrv;

            channelCdr = r.channelCdr;
        }
Exemplo n.º 6
0
        public static OperationRole Factory(int id, string name, int rate,
                                            bool ships, bool boats, bool squads, bool chanCdr)
        {
            OperationRole result = new OperationRole(
                id: id,
                name: name,
                rate: rate,
                ships: ships,
                boats: boats,
                squads: squads,
                channelCdr: chanCdr
                );

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Fetches all operation roles which can be assigned to a boat
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public static bool FetchAllBoats(ref List <OperationRole> output)
        {
            output = new List <OperationRole>();

            SQLiteDataReader reader = DBI.DoQuery(
                @"SELECT * FROM OperationRole
				WHERE onBoats = 1
				ORDER BY id ASC;"                );

            while (reader != null && reader.Read())
            {
                output.Add(OperationRole.Factory(reader));
            }

            return(true);
        }
Exemplo n.º 8
0
        public static bool Create(ref OperationRole output, string name,
                                  int rate, bool ships, bool boats, bool squads, bool chanCdr)
        {
            int result = DBI.DoPreparedAction(
                @"INSERT INTO OperationRole 
				(name, rate, onShips, onBoats, inSquads, channelCdr)
				VALUES (@name, @rate, @ships, @boats, @squads, @chanCdr);"                ,
                new Tuple <string, object>("@name", name),
                new Tuple <string, object>("@rate", rate),
                new Tuple <string, object>("@ships", ships),
                new Tuple <string, object>("@boats", boats),
                new Tuple <string, object>("@squads", squads),
                new Tuple <string, object>("@chanCdr", chanCdr));

            if (result == 1)
            {
                return(OperationRole.FetchById(ref output, DBI.LastInsertRowId));
            }
            return(false);
        }