// Mappers // Note: doesn't expose behavior public static FamilyMemberDTO FromFamilyMember(FamilyMember item) => new FamilyMemberDTO() { Id = item.Id, LastName = item.LastName, Name = item.Name, Pets = item.Pets == null ? new List <PetDTO>() : PetDTO.FromPet(item.Pets) };
// Mappers // Note: doesn't expose behavior public static EmployeeDTO FromEmployee(Employee item, bool includePets = true) { var result = new EmployeeDTO() { Id = item.Id, FamilyMembers = item.FamilyMembers == null ? new List <FamilyMemberDTO>() : FamilyMemberDTO.FromFamilyMember(item.FamilyMembers), IsEmployee = item.IsEmployee, LastName = item.LastName, Name = item.Name, PetsCount = item.PetsCount }; if (includePets) { result.Pets = item.Pets == null ? new List <PetDTO>() : PetDTO.FromPet(item.Pets); } return(result); }
public async Task <PetDTO> Create(string name, int animalId, int employeeId) { var animal = await _animalRepository.GetByIdAsync(animalId); if (animal is null) { return(null); } var employee = await _employeeRepository.GetByIdAsync(employeeId); if (employee is null) { return(null); } var petCreated = await _petRepository.AddAsync(new Pet(name, animal, employee)); var result = PetDTO.FromPet(petCreated); return(result); }
public async Task <EmployeeDTO> AddPetAsync(ICollection <PetDTO> pets) { if (!pets.Any()) { return(null); } var employeeId = pets.FirstOrDefault().EmployeeId; var spec = new EmployeeWithPetsSpecification(employeeId); var employee = await _employeeRepository.FirstOrDefaultAsync(spec); if (employee is null) { return(null); } employee.AddPets(PetDTO.FromPetDTO(pets)); await _employeeRepository.UpdateAsync(employee); return(EmployeeDTO.FromEmployee(employee)); }
public async Task <ICollection <PetDTO> > ListAsyncPaged(PetsPaginatedWithOwnerSpecification spec) { var items = await _petRepository.ListAsync(spec); return(items.Select(x => PetDTO.FromPet(x)).ToList()); }
public static Pet FromPetDTO(PetDTO item) => new Pet(item.Name, item.AnimalId, item.EmployeeId);