示例#1
0
        public PetType AddPetType(PetType petType)
        {
            PetType addedPetType;

            if (petType.Equals(null))
            {
                throw new InvalidDataException("Pet cannot be null");
            }

            if (petType.Name.Length < 1)
            {
                throw new InvalidDataException("Pet name has to be longer than one");
            }

            if (petType.PetTypeId != 0)
            {
                throw new InvalidDataException("A new petType cannot have an id, that is only for already existing pets");
            }

            if (petType.Pets != null)
            {
                if (petType.Pets.Count > 0)
                {
                    throw new InvalidDataException("You cant add pets to a petType like this, go ad an owner id to a pet instead");
                }
            }

            addedPetType = _petTypeRepository.AddPetType(petType);
            if (addedPetType == null)
            {
                throw new DataBaseException("Something went wrong in the database");
            }

            return(addedPetType);
        }
        public PetType AddPetType(PetType petType)
        {
            PetType addedPetType;

            if (petType.Equals(null))
            {
                throw new InvalidDataException("Pet cannot be null");
            }

            if (petType.Name.Length < 1)
            {
                throw new InvalidDataException("Pet name has to be longer than one");
            }

            addedPetType = _petTypeRepository.AddPetType(petType);
            if (addedPetType == null)
            {
                throw new DataBaseException("Something went wrong in the database");
            }

            return(addedPetType);
        }