Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public PetType AddPetType(PetType type)
 {
     if (type != null)
     {
         if ((from x in GetAllPetTypes() where x.Name.ToLower().Equals(type.Name.ToLower()) select x).Count() > 0)
         {
             throw new ArgumentException("Pet type with that name already exists");
         }
         return(PetTypeRepository.AddPetType(type));
     }
     return(null);
 }
        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);
        }
        public void InitData()
        {
            PetType cat = new PetType {
                Name = "Cat"
            };
            PetType dog = new PetType {
                Name = "Dog"
            };
            PetType fish = new PetType {
                Name = "Fish"
            };
            PetType lizard = new PetType {
                Name = "Lizard"
            };
            PetType tarantula = new PetType {
                Name = "Tarantula"
            };
            PetType turtle = new PetType {
                Name = "Turtle"
            };
            PetType goat = new PetType {
                Name = "Goat"
            };

            PetTypeRepository.AddPetType(cat);
            PetTypeRepository.AddPetType(dog);
            PetTypeRepository.AddPetType(fish);
            PetTypeRepository.AddPetType(lizard);
            PetTypeRepository.AddPetType(tarantula);
            PetTypeRepository.AddPetType(turtle);
            PetTypeRepository.AddPetType(goat);

            PetRepository.AddPet(new Pet
            {
                Name      = "Hr. Dingles",
                Type      = cat,
                Birthdate = DateTime.Parse("29-03-2012", CultureInfo.GetCultureInfo("da-DK").DateTimeFormat),
                Color     = "White with black stripes",
                Price     = 750.0
            });
            PetRepository.AddPet(new Pet
            {
                Name      = "SlowPoke",
                Type      = turtle,
                Birthdate = DateTime.Parse("15-01-1982", CultureInfo.GetCultureInfo("da-DK").DateTimeFormat),
                Color     = "Dark green",
                Price     = 365.25
            });
            PetRepository.AddPet(new Pet
            {
                Name      = "Leggy",
                Type      = tarantula,
                Birthdate = DateTime.Parse("05-08-2019", CultureInfo.GetCultureInfo("da-DK").DateTimeFormat),
                Color     = "Brown with orange dots",
                Price     = 650.0
            });

            OwnerRepository.AddOwner(new Owner
            {
                FirstName   = "Mathias",
                LastName    = "Thomsen",
                Address     = "Tulipanvej 33",
                PhoneNumber = "42411722",
                Email       = "*****@*****.**"
            });
            OwnerRepository.AddOwner(new Owner
            {
                FirstName   = "Josefine",
                LastName    = "Thulstrup",
                Address     = "Kastanievej 17",
                PhoneNumber = "23221119",
                Email       = "*****@*****.**"
            });
        }
Exemplo n.º 5
0
        public void InitData()
        {
            PetType cat = new PetType {
                Name = "Cat"
            };
            PetType dog = new PetType {
                Name = "Dog"
            };
            PetType fish = new PetType {
                Name = "Fish"
            };
            PetType lizard = new PetType {
                Name = "Lizard"
            };
            PetType tarantula = new PetType {
                Name = "Tarantula"
            };
            PetType turtle = new PetType {
                Name = "Turtle"
            };
            PetType goat = new PetType {
                Name = "Goat"
            };

            PetTypeRepository.AddPetType(cat);
            PetTypeRepository.AddPetType(dog);
            PetTypeRepository.AddPetType(fish);
            PetTypeRepository.AddPetType(lizard);
            PetTypeRepository.AddPetType(tarantula);
            PetTypeRepository.AddPetType(turtle);
            PetTypeRepository.AddPetType(goat);

            Color red = new Color {
                ColorDescription = "Red"
            };
            Color blue = new Color {
                ColorDescription = "Blue"
            };

            ColorRepository.AddColor(red);
            ColorRepository.AddColor(blue);

            OwnerRepository.AddOwner(new Owner
            {
                FirstName   = "Mathias",
                LastName    = "Thomsen",
                Address     = "Tulipanvej 33",
                PhoneNumber = "42411722",
                Email       = "*****@*****.**"
            });

            Owner Josefine = OwnerRepository.AddOwner(new Owner
            {
                FirstName   = "Josefine",
                LastName    = "Thulstrup",
                Address     = "Kastanievej 17",
                PhoneNumber = "23221119",
                Email       = "*****@*****.**"
            });

            PetRepository.AddPet(new Pet
            {
                Name      = "Hr. Dingles",
                Type      = cat,
                Birthdate = DateTime.Parse("29-03-2012", CultureInfo.GetCultureInfo("da-DK").DateTimeFormat),
                //    Colors = new List<Color> { blue },
                Price     = 750.0,
                petColors = new List <PetColor> {
                    new PetColor {
                        Color = blue
                    }, new PetColor {
                        Color = red
                    }
                },
                SoldDate = DateTime.Parse("30-03-2012", CultureInfo.GetCultureInfo("da-DK").DateTimeFormat),
            });
            PetRepository.AddPet(new Pet
            {
                Name      = "SlowPoke",
                Type      = turtle,
                Birthdate = DateTime.Parse("15-01-1982", CultureInfo.GetCultureInfo("da-DK").DateTimeFormat),
                //     Colors = new List<Color> { blue },
                Owner = Josefine,
                Price = 365.25
            });
            PetRepository.AddPet(new Pet
            {
                Name      = "Leggy",
                Type      = tarantula,
                Birthdate = DateTime.Parse("05-08-2019", CultureInfo.GetCultureInfo("da-DK").DateTimeFormat),
                //      Colors = new List<Color> { red },
                Price = 650.0
            });

            UserService.AddUser(UserService.CreateUser("Hans", "kodeord", "Admin"));
            UserService.AddUser(UserService.CreateUser("Kurt", "lasagne28", "User"));
        }
        public void InitData()
        {
            List <PetColor> petColors1 = new List <PetColor>();
            List <PetColor> petColors2 = new List <PetColor>();
            List <PetColor> petColors3 = new List <PetColor>();
            List <PetColor> petColors4 = new List <PetColor>();

            List <Pet> pets = new List <Pet>();



            Owner owner1 = new Owner
            {
                Name      = "Harold",
                BirthDate = DateTime.Now.AddYears(-40),
                Email     = "*****@*****.**"
            };

            Owner owner2 = new Owner
            {
                Name      = "Carry",
                BirthDate = DateTime.Now.AddYears(-30),
                Email     = "*****@*****.**"
            };

            Owner owner3 = new Owner
            {
                Name      = "Tom",
                BirthDate = DateTime.Now.AddYears(-25),
                Email     = "*****@*****.**"
            };

            _ownerRepository.AddOwner(owner1);
            _ownerRepository.AddOwner(owner2);
            _ownerRepository.AddOwner(owner3);



            PetType petType1 = new PetType
            {
                Name = "Cat",
            };

            PetType petType2 = new PetType
            {
                Name = "Dog",
            };

            PetType petType3 = new PetType
            {
                Name = "Bird",
            };

            _petTypeRepository.AddPetType(petType1);
            _petTypeRepository.AddPetType(petType2);
            _petTypeRepository.AddPetType(petType3);

            Color color1 = new Color
            {
                Name = "Red"
            };

            Color color2 = new Color
            {
                Name = "Blue"
            };

            Color color3 = new Color
            {
                Name = "Yellow"
            };

            Color color4 = new Color
            {
                Name = "Green"
            };

            _colorRepository.AddColor(color1);
            _colorRepository.AddColor(color2);
            _colorRepository.AddColor(color3);
            _colorRepository.AddColor(color4);


            Pet pet1 = new Pet
            {
                Name      = "Jerry",
                PetType   = petType1,
                BirthDate = DateTime.Now.AddYears(-12),
                Owner     = owner1,
                Price     = 50,
                SoldDate  = DateTime.Now.AddYears(-2),
            };

            Pet pet2 = new Pet
            {
                Name      = "Tom",
                PetType   = petType2,
                BirthDate = DateTime.Now.AddYears(-22),
                Owner     = owner2,
                Price     = 10,
                SoldDate  = DateTime.Now.AddYears(-5),
            };

            Pet pet3 = new Pet
            {
                Name      = "Cinc",
                PetType   = petType3,
                BirthDate = DateTime.Now.AddYears(-1),
                Owner     = owner3,
                Price     = 100,
                SoldDate  = DateTime.Now.AddYears(-4),
            };


            pet1.PetColors = new List <PetColor>
            {
                new PetColor
                {
                    Pet   = pet1,
                    Color = color1,
                }
            };

            pet2.PetColors = new List <PetColor>
            {
                new PetColor
                {
                    Pet   = pet2,
                    Color = color1
                },
                new PetColor
                {
                    Pet   = pet2,
                    Color = color2
                }
            };

            pet3.PetColors = new List <PetColor>
            {
                new PetColor
                {
                    Pet   = pet3,
                    Color = color1
                },
                new PetColor
                {
                    Pet   = pet3,
                    Color = color2
                },

                new PetColor
                {
                    Pet   = pet3,
                    Color = color3
                }
            };

            //pet3.PetColors = new List<PetColor>
            //{
            //    petColor1,
            //    petColor2,
            //    petColor3
            //};

            //pets.Add(pet1);
            //pets.Add(pet2);
            //pets.Add(pet3);

            //_petRepository.AddPets(pets);

            _petRepository.AddPet(pet1);
            _petRepository.AddPet(pet2);
            _petRepository.AddPet(pet3);

            // Create two users with hashed and salted passwords
            string password = "******";

            byte[] passwordHashJoe, passwordSaltJoe, passwordHashAnn, passwordSaltAnn;
            authenticationHelper.CreatePasswordHash(password, out passwordHashJoe, out passwordSaltJoe);
            authenticationHelper.CreatePasswordHash(password, out passwordHashAnn, out passwordSaltAnn);

            User user1 = new User
            {
                Username     = "******",
                PasswordHash = passwordHashJoe,
                PasswordSalt = passwordSaltJoe,
                IsAdmin      = false
            };

            User user2 = new User
            {
                Username     = "******",
                PasswordHash = passwordHashAnn,
                PasswordSalt = passwordSaltAnn,
                IsAdmin      = true
            };


            _userRepository.AddUser(user1);
            _userRepository.AddUser(user2);


            //_petColorRepository.AddPetColor(petColor1);
            //_petColorRepository.AddPetColor(petColor2);
            //_petColorRepository.AddPetColor(petColor3);
            //_petColorRepository.AddPetColor(petColor4);
            //_petColorRepository.AddPetColor(petColor5);
            //    //_petColorRepository.AddPetColor(petColor6);

            //petColors1.Add(petColor1);

            //    petColors2.Add(petColor1);
            //    petColors2.Add(petColor2);

            //    petColors3.Add(petColor1);
            //    petColors3.Add(petColor2);
            //    petColors3.Add(petColor3);

            //    petColors4.Add(petColor1);
            //    petColors4.Add(petColor2);
            //    petColors4.Add(petColor3);
            //    petColors4.Add(petColor4);
        }
Exemplo n.º 7
0
 public PetType CreatePetType(PetType petType)
 {
     return(_petTypeRepository.AddPetType(petType));
 }
        public void InitData()
        {
            List <Pet>     pets;
            List <Owner>   owners;
            List <PetType> petTypes;

            pets = new List <Pet> {
                new Pet
                {
                    Name            = "Jerry",
                    PetTypeID       = 1,
                    BirthDate       = DateTime.Now.AddYears(-12),
                    Color           = "Blue",
                    PreviousOwnerID = 1,
                    Price           = 50,
                    SoldDate        = DateTime.Now.AddYears(-2),
                },
                new Pet
                {
                    Name            = "Tom",
                    PetTypeID       = 2,
                    BirthDate       = DateTime.Now.AddYears(-22),
                    Color           = "Red",
                    PreviousOwnerID = 2,
                    Price           = 10,
                    SoldDate        = DateTime.Now.AddYears(-5),
                },
                new Pet
                {
                    Name            = "Cinc",
                    PetTypeID       = 3,
                    BirthDate       = DateTime.Now.AddYears(-1),
                    Color           = "Purple",
                    PreviousOwnerID = 3,
                    Price           = 100,
                    SoldDate        = DateTime.Now.AddYears(-4),
                }
            };

            foreach (Pet pet in pets)
            {
                _petRepository.AddPet(pet);
            }

            owners = new List <Owner> {
                new Owner
                {
                    Name      = "Harold",
                    BirthDate = DateTime.Now.AddYears(-40),
                    Email     = "*****@*****.**"
                },
                new Owner
                {
                    Name      = "Carry",
                    BirthDate = DateTime.Now.AddYears(-30),
                    Email     = "*****@*****.**"
                },
                new Owner
                {
                    Name      = "Tom",
                    BirthDate = DateTime.Now.AddYears(-25),
                    Email     = "*****@*****.**"
                }
            };

            foreach (Owner owner in owners)
            {
                _ownerRepository.AddOwner(owner);
            }

            petTypes = new List <PetType> {
                new PetType
                {
                    Name = "Cat",
                },
                new PetType
                {
                    Name = "Dog",
                },
                new PetType
                {
                    Name = "Bird",
                }
            };

            foreach (PetType petType in petTypes)
            {
                _petTypeRepository.AddPetType(petType);
            }
        }