Exemple #1
0
        public FactionDAL FactionFindByID(int FactionID)
        {        // retrieve a Faction by ID (we dont expect multiple records here)
            FactionDAL ReturnValue = null;

            CheckConnection();
            try
            {
                using (SqlCommand command = new SqlCommand("FactionFindByID", _con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@FactionID", FactionID);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {                    // check for multiple records, throw oops if so. We should only get one
                        FactionMapper fm    = new FactionMapper(reader);
                        int           count = 0;
                        while (reader.Read())
                        {
                            ReturnValue = fm.ToFaction(reader);
                            count++;
                        }
                        if (count > 1)
                        {
                            throw new Exception($"{count} Multiple Factions found for ID {FactionID}");
                        }
                    }
                }
            }
            catch (Exception oops) when(Error.Log(oops))
            {
                //it's all done in the error.log
            }
            return(ReturnValue);
        }
Exemple #2
0
        public List <FactionDAL> FactionsGetAll(int Skip, int Take)
        {        // retrieves all Factions
            List <FactionDAL> ReturnValue = new List <FactionDAL>();

            CheckConnection();
            try
            {
                using (SqlCommand command = new SqlCommand("FactionsGetAll", _con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@skip", Skip);
                    command.Parameters.AddWithValue("@take", Take);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        FactionMapper fm = new FactionMapper(reader);
                        while (reader.Read())
                        {
                            FactionDAL item = fm.ToFaction(reader);
                            ReturnValue.Add(item);
                        }
                    }
                }
            }
            catch (Exception oops) when(Error.Log(oops))
            {
                //it's all done in the error.log
            }
            return(ReturnValue);
        }
Exemple #3
0
        public FactionDAL ToFaction(SqlDataReader reader)
        {           // use the checked offset to write the info to appropriate fields
            FactionDAL ReturnValue = new FactionDAL();

            ReturnValue.FactionID   = reader.GetInt32(OffsetToFactionID);
            ReturnValue.FactionName = reader.GetString(OffsetToFactionName);
            ReturnValue.BackGround  = reader.GetString(OffsetToBackGround);
            return(ReturnValue);
        }
Exemple #4
0
 public void FactionUpdate(FactionDAL Faction)
 {        // pretty straightforward. Overwrites data of record of given FactionID(no output)
     CheckConnection();
     try
     {
         using (SqlCommand command = new SqlCommand("FactionUpdate", _con))
         {
             command.CommandType = System.Data.CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@FactionID", Faction.FactionID);
             command.Parameters.AddWithValue("@FactionName", Faction.FactionName);
             command.Parameters.AddWithValue("@BackGround", Faction.BackGround);
             object datareturned = command.ExecuteNonQuery();
         }
     }
     catch (Exception oops) when(Error.Log(oops))
     {
         //it's all done in the error.log
     }
 }
Exemple #5
0
        public int FactionCreate(FactionDAL NewFaction)
        {        // create a new Faction, return the new FactionID
            int ReturnValue = 0;

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