Пример #1
0
        /// <summary>
        /// Finds all active dogs where the temperament profile ratings have been completed,
        /// the basic details are completed, and are not owned by request user or the request
        /// dog. Each dog includes dog owner, profile image, and temperament profile
        /// </summary>
        /// <param name="id">Dog Id <see cref="int"/> for current dog to exlcude from match results</param>
        /// <returns><see cref="IEnumerable{Dogs}"/> all active dogs list where temperament ratings are completed</returns>
        public async Task <IEnumerable <Dogs> > FindAllActiveMatchableDogs(int id, string ownerId)
        {
            IEnumerable <Dogs> dogs = await _dbSet
                                      .AsNoTracking()
                                      .Where(d =>
                                             !(d.IsDeleted ?? false) &&
                                             d.Id != id &&            // exclude current dog from results
                                             d.Owner.Id != ownerId && // exclude dogs owned by request user
                                             d.Weight != null &&
                                             !string.IsNullOrWhiteSpace(d.Breed) &&
                                             d.Gender.HasValue)
                                      .Include(d => d.Owner)
                                      .Include(d => d.DogProfileImage)
                                      .Include(d => d.Temperament)
                                      .ToListAsync();

            List <Dogs> dogList = new List <Dogs>();

            foreach (var dog in dogs)
            {
                if (_temperamentRepository.HasCompletedTemperament(dog.Temperament))
                {
                    dogList.Add(dog);
                }
            }

            return(dogList);
        }
Пример #2
0
        /// <summary>
        /// Get's <see cref="DogProfile"/> object for single dog, including basic details,
        /// biography, album images, and generated temperament scores
        /// </summary>
        /// <param name="id">Dog Id <see cref="int"/></param>
        /// <returns>Single <see cref="DogProfile"/> object</returns>
        public async Task <DogProfile> GetDogProfile(int id)
        {
            Dogs dog = await _dogRepository.FindFullDogProfileById(id);

            // if dog doesn't exist, return null
            if (dog == null)
            {
                return(null);
            }

            // initialize dog profile and map dog's basic details and album images
            DogProfile dogProfile = new DogProfile()
            {
                Dog         = _mapper.Map <Dog>(dog),
                AlbumImages = _mapper.Map <List <AlbumImage> >(dog.AlbumImages)
            };

            // if all temperament values are populated (not null or zero), generate and set temperament scores
            if (_temperamentRepository.HasCompletedTemperament(dog.Temperament))
            {
                dogProfile.HasTemperament    = true;
                dogProfile.TemperamentScores = GetTemperamentScores(dog.Temperament);
            }

            // if any biography properties are populated, map and set values
            if (HasBiography(dog.Biography))
            {
                dogProfile.HasBio = true;
                dogProfile.Bio    = _mapper.Map <DogBiography>(dog.Biography);
            }

            return(dogProfile);
        }