/// <summary>
        /// Analisa os animais consoante as caracteristicas do utilizadpr
        /// </summary>
        /// <param name="perfectAnimal">The perfect animal.</param>
        /// <param name="animal">The animal.</param>
        /// <returns>O animal com a sua percentagem de compatibilidade</returns>
        public PerfectAnimal HowPerfect(PerfectAnimal perfectAnimal, Animal animal)
        {
            var count = 0;

            if (perfectAnimal.Type == animal.AnimalType)
            {
                count += 20;
            }
            if (perfectAnimal.Gender == animal.Gender)
            {
                count += 20;
            }
            if (perfectAnimal.Age == animal.AgeType)
            {
                count += 20;
            }
            if (perfectAnimal.BreedId == animal.BreedId)
            {
                count += 20;
            }
            if (perfectAnimal.Size == animal.SizeType)
            {
                count += 20;
            }

            perfectAnimal.AnimalId    = animal.Id;
            perfectAnimal.Animal      = animal;
            perfectAnimal.Percentagem = count;
            return(perfectAnimal);
        }
        public async Task <IActionResult> Edit(int id, [Bind("PerfectAnimalId,Size,Gender,BreedId,Age,Type")] PerfectAnimal perfectAnimal)
        {
            if (id != perfectAnimal.PerfectAnimalId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(perfectAnimal);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PerfectAnimalExists(perfectAnimal.PerfectAnimalId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BreedId"] = new SelectList(_context.AnimalBreed, "Id", "Name", perfectAnimal.BreedId);
            return(View(perfectAnimal));
        }
Exemplo n.º 3
0
        public void Edit_ReturnsResult()
        {
            var           controller    = new PerfectAnimalsController(DbContext);
            PerfectAnimal perfectAnimal = new PerfectAnimal();
            var           result        = controller.Edit(1, perfectAnimal);

            var viewResult = Assert.IsType <Task <IActionResult> >(result);
        }
Exemplo n.º 4
0
        public void GetAnimalIdeal_ReturnsTask()
        {
            var           controller    = new PerfectAnimalsController(DbContext);
            PerfectAnimal perfectAnimal = new PerfectAnimal();
            var           result        = controller.GetAnimalIdeal(perfectAnimal);

            var viewResult = Assert.IsType <Task <IActionResult> >(result);
        }
Exemplo n.º 5
0
        public void Details_ReturnsTask()
        {
            var           controller    = new PerfectAnimalsController(DbContext);
            PerfectAnimal perfectAnimal = new PerfectAnimal();
            var           result        = controller.Details(1);

            var viewResult = Assert.IsType <Task <IActionResult> >(result);
        }
Exemplo n.º 6
0
        public void HowPerfect_ReturnsPercentagem()
        {
            var           controller    = new PerfectAnimalsController(DbContext);
            PerfectAnimal perfectAnimal = new PerfectAnimal()
            {
                Age = EnumAgeType.BABY
            };
            Animal animal = new Animal()
            {
                AgeType = EnumAgeType.BABY
            };
            var result = controller.HowPerfect(perfectAnimal, animal);

            PerfectAnimal perfect = new PerfectAnimal()
            {
                Percentagem = 20
            };


            Assert.True(perfect.Percentagem.Equals(perfectAnimal.Percentagem));
        }
        public async Task <IActionResult> GetAnimalIdeal([Bind("PerfectAnimalId,Size,Gender,BreedId,Age,Type")] PerfectAnimal perfectAnimal)
        {
            var percentagem             = 0;
            List <PerfectAnimal> animal = new List <PerfectAnimal>();
            var animaisideais           = from a in _context.Animal select a;
            var animalIdeal             = from a in _context.Animal where a.AnimalType == perfectAnimal.Type && a.Gender == perfectAnimal.Gender && a.AgeType == perfectAnimal.Age && a.BreedId == perfectAnimal.BreedId && a.SizeType == perfectAnimal.Size select a;

            if (animalIdeal.Count() >= 1)
            {
                foreach (var item in animalIdeal)
                {
                    var pA = new PerfectAnimal {
                        Animal = item
                    };
                    pA.Percentagem = 100;
                    animal.Add(pA);
                }
                return(View(animal));
            }
            var animaistipo = from a in _context.Animal where a.AnimalType == perfectAnimal.Type && a.Adopted == false select a;

            if (animaistipo.Count() == 0)
            {
                return(NotFound());
            }
            if (animaistipo.Count() >= 1)
            {
                foreach (var item in animaistipo)
                {
                    animal.Add(HowPerfect(new PerfectAnimal(), item));
                }
            }

            ViewData["BreedId"] = new SelectList(_context.AnimalBreed, "Id", "Name", perfectAnimal.BreedId);
            animal.Distinct().ToList();
            return(View(animal));
        }