Exemplo n.º 1
0
        public ArmyDAL ArmyFindByID(int ArmyID)
        {        // retrieve a Army by ID (we dont expect multiple records here)
            ArmyDAL ReturnValue = null;

            CheckConnection();
            try
            {
                using (SqlCommand command = new SqlCommand("ArmyFindByID", _con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@ArmyID", ArmyID);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        ArmyMapper am    = new ArmyMapper(reader);
                        int        count = 0;
                        while (reader.Read())
                        {
                            ReturnValue = am.ToArmy(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new Exception($"{count} Multiple Army found for ID {ArmyID}");
                        }
                    }
                }
            }
            catch (Exception oops) when(Error.Log(oops))
            {
                //it's all done in the error.log
            }
            return(ReturnValue);
        }
Exemplo n.º 2
0
        public ArmyDAL ToArmy(SqlDataReader reader)
        {           // lets use the checked column numbers to write the info to appropriate fields
            ArmyDAL ReturnValue = new ArmyDAL();

            ReturnValue.ArmyID      = reader.GetInt32(OffsetToArmyID);
            ReturnValue.ArmyName    = reader.GetString(OffsetToArmyName);
            ReturnValue.UserID      = reader.GetInt32(OffsetToUserID);
            ReturnValue.UserName    = reader.GetString(OffsetToUserName);
            ReturnValue.Comments    = reader.GetString(OffsetToComments);
            ReturnValue.FactionID   = reader.GetInt32(OffsetToFactionID);
            ReturnValue.FactionName = reader.GetString(OffsetToFactionName);
            return(ReturnValue);
        }
Exemplo n.º 3
0
 public void ArmyUpdate(ArmyDAL army)
 {        // pretty straightforward. Overwrites data of record of given ArmyID(no output)
     CheckConnection();
     try
     {
         using (SqlCommand command = new SqlCommand("ArmyUpdate", _con))
         {
             command.CommandType = System.Data.CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@ArmyID", army.ArmyID);
             command.Parameters.AddWithValue("@ArmyName", army.ArmyName);
             command.Parameters.AddWithValue("@UserID", army.UserID);
             command.Parameters.AddWithValue("@Comments", army.Comments);
             command.Parameters.AddWithValue("@FactionID", army.FactionID);
             object datareturned = command.ExecuteNonQuery();
         }
     }
     catch (Exception oops) when(Error.Log(oops))
     {
         //it's all done in the error.log
     }
 }
Exemplo n.º 4
0
        public int ArmyCreate(ArmyDAL army)
        {        // create a new Army, return the new ArmyID
            int ReturnValue = 0;

            CheckConnection();
            try
            {
                using (SqlCommand command = new SqlCommand("ArmyCreate", _con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@ArmyName", army.ArmyName);
                    command.Parameters.AddWithValue("@UserID", army.UserID);
                    command.Parameters.AddWithValue("@Comments", army.Comments);
                    command.Parameters.AddWithValue("@FactionID", army.FactionID);
                    ReturnValue = Convert.ToInt32(command.ExecuteScalar());
                }
            }
            catch (Exception oops) when(Error.Log(oops))
            {
                //it's all done in the error.log
            }
            return(ReturnValue);
        }