Exemplo n.º 1
0
        public void Add(Answer answer)
        {
            try {
                int tid = entity.BeginTransaction ();

                List<ColumnValue> columns = new List<ColumnValue> ();
                columns.Add (new ColumnValue () { Item1 = "gameId", Item2 = answer.Game.Id.ToString() });
                columns.Add (new ColumnValue () { Item1 = "questionId", Item2 = answer.Question.Id.ToString()});
                columns.Add (new ColumnValue () { Item1 = "answer", Item2 = answer.Value});
                if (answer.Player != null) {
                    columns.Add (new ColumnValue () { Item1 = "playerId", Item2 = answer.Player.Id.ToString() });
                } else {
                    columns.Add (new ColumnValue () { Item1 = "playerId", Item2 = null });
                }
                answer.Id = (int)this.Insert (columns).LastInsertedId;

                entity.Commit (tid);
            } catch (MySqlException ex) {
                switch (ex.Number) {
                case 0:
                    throw new DatabaseException ("Cannot connect to server.  Contact administrator", ex);
                case 1045:
                    throw new DatabaseException ("Invalid username/password, please try again", ex);
                default:
                    throw new DatabaseException (ex.Message, ex);
                }
            }
        }
Exemplo n.º 2
0
 public void Delete(Answer answer)
 {
     try {
         StatementValue where = new StatementValue ();
         where.Item1 = "id = @StatementValue0";
         where.Item2 = new List<string> ();
         where.Item2.Add (answer.Id.ToString ());
         this.Delete (where);
     } catch (MySqlException ex) {
         switch (ex.Number) {
         case 0:
             throw new DatabaseException ("Cannot connect to server.  Contact administrator", ex);
         case 1045:
             throw new DatabaseException ("Invalid username/password, please try again", ex);
         default:
             throw new DatabaseException (ex.Message, ex);
         }
     }
 }
Exemplo n.º 3
0
        public void Save(Answer answer)
        {
            if (answer.Id < 0) {
                this.Add (answer);
                return;
            }
            try {
                int tid = entity.BeginTransaction ();

                List<ColumnValue> columns = new List<ColumnValue> ();
                columns.Add (new ColumnValue () { Item1 = "gameId", Item2 = answer.Game.Id.ToString() });
                columns.Add (new ColumnValue () { Item1 = "questionId", Item2 = answer.Question.Id.ToString() });
                columns.Add (new ColumnValue () { Item1 = "answer", Item2 = answer.Value });
                if (answer.Player != null) {
                    columns.Add (new ColumnValue () { Item1 = "playerId", Item2 = answer.Player.Id.ToString() });
                } else {
                    columns.Add (new ColumnValue () { Item1 = "playerId", Item2 = null });
                }

                StatementValue where = new StatementValue ();
                where.Item1 = "id = @StatementValue0";
                where.Item2 = new List<string> ();
                where.Item2.Add (answer.Id.ToString ());

                this.Update (columns, where);
                entity.Commit (tid);
            } catch (MySqlException ex) {
                switch (ex.Number) {
                case 0:
                    throw new DatabaseException ("Cannot connect to server.  Contact administrator", ex);
                case 1045:
                    throw new DatabaseException ("Invalid username/password, please try again", ex);
                default:
                    throw new DatabaseException (ex.Message, ex);
                }
            }
        }