示例#1
0
        public Pet CreatePet(Pet pet)
        {
            if (pet.PetType != null)
            {
                var petType = _petTypeRepository.GetPetTypes().List.FirstOrDefault(p => p.Id == pet.PetType.Id);
                if (petType == null)
                {
                    throw new InvalidDataException("PetType must exist in the database");
                }


                if (pet.Owner != null)
                {
                    var owner = _ownerRepository.GetOwners().List.FirstOrDefault(o => o.Id == pet.Owner.Id);

                    if (owner == null)
                    {
                        throw new InvalidDataException("Owner must exist in the database");
                    }
                }

                return(_petRepository.AddPet(pet));
            }

            throw new InvalidDataException("PetType must exist in the database");
        }
示例#2
0
        public FilteredList <PetType> GetPetTypes(Filter filter)
        {
            if (!string.IsNullOrEmpty(filter.SearchText) && string.IsNullOrEmpty(filter.SearchField))
            {
                filter.SearchField = "name";
            }

            return(_petTypeRepository.GetPetTypes(filter));
        }