Exemplo n.º 1
0
        public Pet CreatePet(string petName, PetType type, DateTime birthDate, List <PetColor> petColors, double price)
        {
            if (string.IsNullOrEmpty(petName))
            {
                throw new ArgumentException("Entered pet name too short");
            }
            if (petColors == null || petColors.Count == 0)
            {
                throw new ArgumentException("Entered color description too short");
            }
            if (price < 0)
            {
                throw new ArgumentException("Pet price can't be negative");
            }
            if (type == null)
            {
                throw new ArgumentException("The type of pet is invalid");
            }
            else
            {
                if (PetTypeRepository.ReadTypes().Where((x) => { return(x.ID == type.ID); }).FirstOrDefault() == null)
                {
                    throw new ArgumentException("No pet type with such an ID found");
                }
                else
                {
                    type = PetTypeRepository.ReadTypes().Where((x) => { return(x.ID == type.ID); }).FirstOrDefault();
                }
            }
            if ((DateTime.Now.Year - birthDate.Year) > 150 || (DateTime.Now.Year - birthDate.Year) < 0)
            {
                throw new ArgumentException("Invalid birthdate selected");
            }

            foreach (PetColor color in petColors)
            {
                if (ColorRepository.GetColorByID(color.ColorID) == null)
                {
                    throw new ArgumentException("Invalid color");
                }
            }


            return(new Pet {
                Name = petName, Type = type, Birthdate = birthDate, petColors = petColors, Price = price
            });
        }
Exemplo n.º 2
0
 public List <PetType> GetAllPetTypes()
 {
     return(PetTypeRepository.ReadTypes().ToList());
 }