// Mappers // Note: doesn't expose behavior public static FamilyMemberResponse FromFamilyMember(FamilyMemberDTO item) => new FamilyMemberResponse() { Id = item.Id, LastName = item.LastName, Name = item.Name, Pets = item.Pets == null ? new List <PetResponse>() : PetResponse.FromPetDTO(item.Pets) };
// Mappers // Note: doesn't expose behavior public static EmployeeResponse FromEmployeeDTO(EmployeeDTO item) => new EmployeeResponse() { Id = item.Id, FamilyMembers = item.FamilyMembers == null ? new List <FamilyMemberResponse>() : FamilyMemberResponse.FromFamilyMember(item.FamilyMembers), IsEmployee = item.IsEmployee, LastName = item.LastName, Name = item.Name, Pets = item.Pets == null ? new List <PetResponse>() : PetResponse.FromPetDTO(item.Pets), PetsCount = item.PetsCount };
/* * Deserializes pet specific information and adds to result list */ private void PetResponseCallback(int index, string response) { PetResponse petRepsonse = JsonConvert.DeserializeObject <PetResponse>(response); _petDataList.Pets[index] = petRepsonse.PetData; if (IsFetchCompleted()) { _onSuccessHandler?.Invoke(); } }
public static async Task <PetResponse> GetPetsAsync(string animal_type = null) { PetResponse pets = null; var animalTypeStr = (animal_type == null) ? "" : ("animal_type=" + animal_type + "&"); HttpResponseMessage response = await client.GetAsync("pets?" + animalTypeStr + "limit=100"); if (response.IsSuccessStatusCode) { pets = await response.Content.ReadAsAsync <PetResponse>(); } return(pets); }
public async Task <PetResponse> FindByIdAsync(int petId) { try { var pet = await _petRepository.FindByIdAsync(petId); var aux = new PetResponse(pet); if (pet == null) { aux = new PetResponse(false, "No se encontro a la mascota porque no existe", pet); } return(aux); //var pet = await _petRepository.FindByIdAsync(petId); // return new PetResponse(pet); } catch (Exception ex) { return(new PetResponse($"An error ocurred while deleting the pet: {ex.Message}")); } }
public IActionResult AssignPet(int id, PetRequest request) { if (request.IdPet == null) { throw new Exception("Pet ID is not provided!"); } if (!_context.Pet.Any(e => e.IdPet == id)) { throw new Exception("Such pet doesn't exist!"); } if (!_context.Volunteer.Any(e => e.IdVolunteer == id)) { throw new Exception("Such volunteer doesn't exist"); } var volunteer = _context.Volunteer.Where(v => v.IdVolunteer == id).FirstOrDefault(); if (volunteer.IdSupervisor.HasValue) { throw new Exception("The given volunteer has a supervisor!"); } else { var volunteer_pet = new Volunteer_Pet() { DateAccepted = DateTime.Now, IdPet = request.IdPet, IdVolunteer = id }; _context.Volunteer_Pet.Add(volunteer_pet); _context.SaveChanges(); var petResponse = new PetResponse() { IdPet = request.IdPet }; return(Ok(petResponse)); } }
public IActionResult ListPets(int id, int?year) { if (!_context.Volunteer.Any(e => e.IdVolunteer == id)) { throw new Exception("No volunteer with given ID!"); } else { if (year == null) { var ListOfPets = (from v in _context.Volunteer_Pet join p in _context.Pet on v.IdPet equals p.IdPet join b in _context.BreedType on p.IdBreedType equals b.IdBreedType where (v.IdVolunteer == id) select p).ToList(); if (ListOfPets.Count == 0) { throw new Exception("This volunteer has no history of adopting pets!"); } else { var petListResponse = new PetListResponse() { ListOfPets = new List <PetResponse>() }; foreach (var pet in ListOfPets) { var idBreed = pet.IdBreedType; var Breed = _context.BreedType.Where(b => b.IdBreedType == idBreed).Select(b => b.name).First(); var petResponse = new PetResponse() { IdPet = pet.IdPet, BreedType = Breed, Name = pet.Name, Sex = pet.IsMale ? "male" : "female", DateRegistered = pet.DateRegistered, DateOfBirth = pet.DateOfBirth, DateAdopted = pet.DateAdopted, AgeWhenAdopted = YearsBetween(pet.DateOfBirth, pet.DateAdopted.Value) }; petListResponse.ListOfPets.Add(petResponse); } return(Ok(petListResponse)); } } else { var ListOfPets = (from v in _context.Volunteer_Pet join p in _context.Pet on v.IdPet equals p.IdPet join b in _context.BreedType on p.IdBreedType equals b.IdBreedType where (v.IdVolunteer == id && v.DateAccepted.Year >= year) select p).ToList(); if (ListOfPets.Count == 0) { throw new Exception("This volunteer has no history of adopting pets starting in given year!!"); } else { var petListResponse = new PetListResponse() { ListOfPets = new List <PetResponse>() }; foreach (var pet in ListOfPets) { var petResponse = new PetResponse() { IdPet = pet.IdPet, BreedType = _context.BreedType.Where(b => b.IdBreedType == pet.IdBreedType).Select(b => new { name = b.name }).ToString(), Name = pet.Name, Sex = pet.IsMale ? "male" : "female", DateRegistered = pet.DateRegistered, DateOfBirth = pet.DateOfBirth, DateAdopted = pet.DateAdopted, AgeWhenAdopted = YearsBetween(pet.DateOfBirth, pet.DateAdopted.Value) }; petListResponse.ListOfPets.Add(petResponse); } return(Ok(petListResponse)); } } } }