public DogDAL DogFindByID(int DogID)
        {
            DogDAL proposedReturnValue = null;

            EnsureConnected();
            using (SqlCommand command = new SqlCommand("DogFindByID", sec))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@DogID", DogID);
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    DogMapper dm    = new DogMapper(reader);
                    int       count = 0;
                    while (reader.Read())
                    {
                        proposedReturnValue = dm.ToDog(reader);
                        count++;
                    }
                    if (count > 1)
                    {
                        throw new Exception($"{count} many users found for ID {DogID}");
                    }
                }
            }
            return(proposedReturnValue);
        }
Example #2
0
        public DogDAL DogFindByBreed(int BreedID)
        {
            DogDAL proposedReturnValue = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("DogFindByBreed", sec))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@BreedID", BreedID);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        DogMapper dm = new DogMapper(reader);
                        while (reader.Read())
                        {
                            proposedReturnValue = dm.ToDog(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Logger.Log(ex);
            }
            return(proposedReturnValue);
        }
Example #3
0
        public List <DogDAL> DogsGetAll(int Skip, int Take)
        {
            List <DogDAL> proposedReturnValue = new List <DogDAL>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("DogsGetAll", sec))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@Skip", Skip);
                    command.Parameters.AddWithValue("@Take", Take);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        DogMapper dm = new DogMapper(reader);
                        while (reader.Read())
                        {
                            DogDAL item = dm.ToDog(reader);
                            proposedReturnValue.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Logger.Log(ex);
            }
            return(proposedReturnValue);
        }
Example #4
0
 public DogBLL(DataAccessLayer.DogDAL dog)
 {
     DogID         = dog.DogID;
     Name          = dog.Name;
     BreedID       = dog.BreedID;
     IsSmallBreed  = dog.IsSmallBreed;
     IsDogHairless = dog.IsDogHairless;
     Medical       = dog.Medical;
     AdoptDate     = dog.AdoptDate;
     SurrenderDate = dog.SurrenderDate;
 }
Example #5
0
        public DogDAL ToDog(SqlDataReader reader)
        {
            DogDAL proposedReturnValue = new DogDAL
            {
                DogID         = reader.GetInt32(OffsetToDogID),
                Name          = reader.GetString(OffsetToName),
                BreedID       = reader.GetInt32(OffsetToBreedID),
                IsSmallBreed  = reader.GetBoolean(OffsetToIsSmallBreed),
                IsDogHairless = reader.GetBoolean(OffsetToIsDogHairless),
                Medical       = reader.GetString(OffsetToMedical),
                AdoptDate     = reader.GetDateTime(OffsetToAdoptDate),
                SurrenderDate = reader.GetDateTime(OffsetToSurrenderDate)
            };

            return(proposedReturnValue);
        }
Example #6
0
        public DogDAL GetDogsByUserID(int UserID)
        {
            DogDAL proposedReturnValue = null;

            EnsureConnected();
            using (SqlCommand command = new SqlCommand("GetDogsByUserID", sec))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@UserID", UserID);
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    DogMapper dm = new DogMapper(reader);
                    while (reader.Read())
                    {
                        proposedReturnValue = dm.ToDog(reader);
                    }
                }
                return(proposedReturnValue);
            }
        }