Example #1
0
        private async Task <IEnumerable <BreedMatchViewModel> > MatchBreedsToUser()
        {
            string username    = this.User.Identity.Name;
            User   currentUser = await userManager.FindByNameAsync(username);

            ICollection <UserAnswer>       userAnswers = quizRepository.GetUserAnswers(currentUser);
            List <CharacteristicUserScore> characteristicUserScores = new List <CharacteristicUserScore>();
            List <BreedMatchViewModel>     breedMatches             = new List <BreedMatchViewModel>();

            IEnumerable <Breed> breeds = dogRepository.GetBreeds(true);

            foreach (UserAnswer answer in userAnswers)
            {
                foreach (AnswerCharacteristic answerCharacteristic in answer.Answer.AnswerCharacteristics)
                {
                    characteristicUserScores.Add(new CharacteristicUserScore()
                    {
                        UserScore          = answerCharacteristic.Score,
                        CharacteristicName = answerCharacteristic.Characteristic.Name
                    });
                }
            }

            foreach (Breed breed in breeds)
            {
                double matchScore = 0;

                foreach (CharacteristicUserScore userCharacteristic in characteristicUserScores)
                {
                    int userScore = userCharacteristic.UserScore;
                    if (userScore == 0)
                    {
                        matchScore += 100;
                    }
                    else
                    {
                        int breedScore = breed.BreedCharacteristics.Where(bc => bc.Characteristic.Name == userCharacteristic.CharacteristicName).First().Score;
                        matchScore += 100 - Math.Abs(userScore - breedScore) * 20;
                    }
                }

                breedMatches.Add(new BreedMatchViewModel()
                {
                    BreedId    = breed.Id,
                    BreedName  = breed.Name,
                    MatchScore = matchScore / 26,
                    UserName   = currentUser.FirstName
                });
            }

            return(breedMatches.OrderByDescending(bm => bm.MatchScore));
        }
Example #2
0
 public ActionResult Get(bool includeItems = true)
 {
     try
     {
         var result = repository.GetBreeds(includeItems);
         return(Ok(mapper.Map <IEnumerable <Breed>, IEnumerable <BreedViewModel> >(result)));
     }
     catch (Exception e)
     {
         logger.LogError($"Failed to get breeds: {e}");
         return(BadRequest("Failed to get breeds"));
     }
 }
Example #3
0
        public IActionResult AllDogBreeds()
        {
            var results = repository.GetBreeds(true);

            return(View(results));
        }