Exemplo n.º 1
0
        public GetPetsResponse GetPets(GetPetsRequest request)
        {
            if (_context.Volunteer.Where(v => v.IdVolunteer == request.IdVolunteer).Count() != 1)
            {
                throw new NoSuchVolunteerException("No volunteer with id " + request.IdVolunteer + " found");
            }

            var res = _context.Volunteer_Pet.Where(v_p => v_p.IdVolunteer == request.IdVolunteer &&
                                                   ((v_p.DateAccepted.Year > request.Year) || (request.Year == 0))
                                                   ).Join(_context.Pet,
                                                          v_p => v_p.IdPet,
                                                          pet => pet.IdPet,
                                                          (v_p, pet) => new PetResponse
            {
                IdPet                  = pet.IdPet,
                IdBreedType            = pet.IdBreedType,
                IsMale                 = pet.IsMale,
                DateAdopted            = pet.DateAdopted,
                Name                   = pet.Name,
                ApprocimateDateOfBirth = pet.ApprocimateDateOfBirth,
                DateRegistred          = pet.DateRegistred,
                Age = DateTime.Now.Year - pet.ApprocimateDateOfBirth.Year
            }).ToList();

            return(new GetPetsResponse()
            {
                Pets = res
            });
        }
Exemplo n.º 2
0
        public IActionResult GetPets(int id, int year)
        {
            var request = new GetPetsRequest()
            {
                IdVolunteer = id,
                Year        = year
            };

            try
            {
                return(Ok(_dbService.GetPets(request)));
            }
            catch (NoSuchVolunteerException ex)
            {
                return(BadRequest(ex.Message));
            }
        }