Exemple #1
0
        public static AssignmentRole Factory()
        {
            AssignmentRole result = new AssignmentRole(
                id: -1,
                name: "",
                isCompany: false
                );

            return(result);
        }
Exemple #2
0
        public static AssignmentRole Factory(SQLiteDataReader reader)
        {
            AssignmentRole result = new AssignmentRole(
                id: Convert.ToInt32(reader["id"]),
                name: (string)reader["name"],
                isCompany: Convert.ToBoolean(reader["isCompany"])
                );

            return(result);
        }
Exemple #3
0
        public static AssignmentRole Factory(int id, string name,
                                             bool isCompany)
        {
            AssignmentRole result = new AssignmentRole(
                id: id,
                name: name,
                isCompany: isCompany
                );

            return(result);
        }
 /// <summary>
 /// Gets a role by ID
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static AssignmentRole FetchById(int id)
 {
     Datamodel.AssignmentRole ar = null;
     if (Datamodel.AssignmentRole.FetchById(ref ar, id))
     {
         return(new AssignmentRole(ar));
     }
     else
     {
         return(null);
     }
 }
Exemple #5
0
        /// <summary>
        /// Fetches an assignment role by ID
        /// </summary>
        /// <param name="output"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool FetchById(ref AssignmentRole output, int id)
        {
            SQLiteDataReader reader = DBI.DoPreparedQuery(
                @"SELECT * FROM AssignmentRole 
				WHERE id = @id LIMIT 1;"                ,
                new Tuple <string, object>("@id", id));

            if (reader != null && reader.Read())
            {
                output = AssignmentRole.Factory(reader);
                return(true);
            }
            return(false);
        }
Exemple #6
0
        /// <summary>
        /// Fetches a role by name
        /// </summary>
        /// <param name="output"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool FetchByName(ref AssignmentRole output, string name)
        {
            SQLiteDataReader reader = DBI.DoPreparedQuery(
                @"SELECT * FROM AssignmentRole 
				WHERE name = @name LIMIT 1;"                ,
                new Tuple <string, object>("@name", name));

            if (reader != null && reader.Read())
            {
                output = AssignmentRole.Factory(reader);
                return(true);
            }
            return(false);
        }
Exemple #7
0
        /// <summary>
        /// Fetches all possible assignment roles
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public static bool FetchAll(ref List <AssignmentRole> output)
        {
            output = new List <AssignmentRole>();

            SQLiteDataReader reader = DBI.DoQuery(
                "SELECT * FROM AssignmentRole;");

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

            return(true);
        }
Exemple #8
0
        /// <summary>
        /// Creates a new assignment role
        /// </summary>
        /// <param name="output"></param>
        /// <param name="name"></param>
        /// <param name="isCompany"></param>
        /// <returns></returns>
        public static bool Create(ref AssignmentRole output, string name,
                                  bool isCompany)
        {
            int result = DBI.DoPreparedAction(
                @"INSERT INTO AssignmentRole (name, isCompany) 
				VALUES (@name, @company);"                ,
                new Tuple <string, object>("@name", name),
                new Tuple <string, object>("@company", isCompany));

            if (result == 1)
            {
                return(AssignmentRole.FetchById(ref output,
                                                DBI.LastInsertRowId));
            }
            return(false);
        }
Exemple #9
0
        /// <summary>
        /// Updates a role in the table
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool Store(AssignmentRole input)
        {
            int result = DBI.DoPreparedAction(
                @"UPDATE AssignmentRole 
				SET name = @name, isCompany = @company 
				WHERE id = @id;"                ,
                new Tuple <string, object>("@name", input.name),
                new Tuple <string, object>("@company", input.isCompany),
                new Tuple <string, object>("@id", input.id));

            if (result == 1)
            {
                return(true);
            }
            return(false);
        }
Exemple #10
0
        private Assignment(Datamodel.Assignment a)
        {
            id = a.id;

            _userId = a.user;

            _shipId = a.ship;
            Vessel ship = Vessel.FetchById(_shipId);

            if (ship == null)
            {
                throw new ArgumentException(
                          "Assignment does not have valid ship ID");
            }
            shipName       = ship.name;
            shipHullNumber = ship.fullHullNumber;

            _roleId = a.role;
            Datamodel.AssignmentRole role = null;
            if (!Datamodel.AssignmentRole.FetchById(ref role, _roleId))
            {
                throw new ArgumentException(
                          "Assignment does not have valid role ID");
            }
            roleName      = role.name;
            roleIsCompany = role.isCompany;

            startDate = DateTimeOffset.FromUnixTimeSeconds(a.from).DateTime;
            if (a.until != -1)
            {
                hasEndDate = true;
                endDate    = DateTimeOffset.FromUnixTimeSeconds(a.until).DateTime;
            }
            else
            {
                hasEndDate = false;
            }
        }
 private AssignmentRole(Datamodel.AssignmentRole ar)
 {
     id        = ar.id;
     name      = ar.name;
     isCompany = ar.isCompany;
 }