コード例 #1
0
 private void AddPetTypes()
 {
     _petTypeRepository.AddNewPetType(new PetType()
     {
         Id = 0, Name = "Dog"
     });
     _petTypeRepository.AddNewPetType(new PetType()
     {
         Id = 1, Name = "Cat"
     });
 }
コード例 #2
0
        public string InitData()
        {
            List <PetType> allPetTypes = new List <PetType>
            {
                new PetType {
                    PetTypeName = "Cat"
                },
                new PetType {
                    PetTypeName = "Dog"
                },
                new PetType {
                    PetTypeName = "Horse"
                },
                new PetType {
                    PetTypeName = "Fish"
                },
                new PetType {
                    PetTypeName = "Gerbil"
                },
                new PetType {
                    PetTypeName = "Hamster"
                },
                new PetType {
                    PetTypeName = "Rabbit"
                }
            };

            List <Owner> allOwners = new List <Owner>
            {
                new Owner {
                    OwnerFirstName = "Lars", OwnerLastName = "Rasmussen", OwnerAddress = "SweetStreet 4, 6700 Esbjerg", OwnerPhoneNr = "+45 1234 5678", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "John", OwnerLastName = "Jackson", OwnerAddress = "The Alley 6, 6705 Esbjerg Ø", OwnerPhoneNr = "+45 2549 6254", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Maria", OwnerLastName = "Saunderson", OwnerAddress = "Kongensgade 33, 6700 Esbjerg", OwnerPhoneNr = "+45 8761 1624", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Belinda", OwnerLastName = "Twain", OwnerAddress = "Nørregade 14, 6700 Esbjerg", OwnerPhoneNr = "+45 7365 5976", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Roald", OwnerLastName = "Schwartz", OwnerAddress = "Lark Road 26, 6715 Esbjerg N", OwnerPhoneNr = "+45 7618 5234", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Shiela", OwnerLastName = "Jesperson", OwnerAddress = "Daniels Road 45, 6700 Esbjerg", OwnerPhoneNr = "+45 7831 2561", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Hansi", OwnerLastName = "Thompson", OwnerAddress = "Spooky Road 666, 6705 Esbjerg Ø", OwnerPhoneNr = "+45 1465 2845", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Victoria", OwnerLastName = "Marks", OwnerAddress = "Birkelunden 8, 6705 Esbjerg Ø", OwnerPhoneNr = "+45 5956 4651", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Niels", OwnerLastName = "Billson", OwnerAddress = "Folevej 3, 6715 Esbjerg N", OwnerPhoneNr = "+45 7286 9435", OwnerEmail = "*****@*****.**"
                },
                new Owner {
                    OwnerFirstName = "Emanuelle", OwnerLastName = "Johnson", OwnerAddress = "Foldgårdsvej 17, 6715 Esbjerg N", OwnerPhoneNr = "+45 7315 4255", OwnerEmail = "*****@*****.**"
                }
            };

            List <Pet> allPets = new List <Pet> {
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-25), PetColor = "grey", PetName = "Hans", PetPreviousOwner = "Aniyah Chan", PetOwner = allOwners[0], PetSoldDate = DateTime.Now.AddMonths(0), PetType = allPetTypes[0], PetPrice = 10
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-400), PetColor = "black and white", PetName = "Katia", PetPreviousOwner = "Alison Melia", PetOwner = allOwners[1], PetSoldDate = DateTime.Now.AddMonths(-3), PetType = allPetTypes[1], PetPrice = 235
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-320), PetColor = "brown", PetName = "Jellybelly", PetPreviousOwner = "Abdallah Dejesus", PetOwner = allOwners[2], PetSoldDate = DateTime.Now.AddMonths(-5), PetType = allPetTypes[2], PetPrice = 2
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-50), PetColor = "black", PetName = "Faithful", PetPreviousOwner = "Teegan Boyer", PetOwner = allOwners[3], PetSoldDate = DateTime.Now.AddMonths(-1), PetType = allPetTypes[1], PetPrice = 41
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-81), PetColor = "orange striped", PetName = "Enigma", PetPreviousOwner = "Vinnie Odling", PetOwner = allOwners[4], PetSoldDate = DateTime.Now.AddMonths(-2), PetType = allPetTypes[3], PetPrice = 56
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-691), PetColor = "purple", PetName = "Bob", PetPreviousOwner = "Amina Brookes", PetOwner = allOwners[4], PetSoldDate = DateTime.Now.AddMonths(-8), PetType = allPetTypes[3], PetPrice = 98
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-259), PetColor = "silver tabby", PetName = "Linea", PetPreviousOwner = "Carmel Livingson", PetOwner = allOwners[5], PetSoldDate = DateTime.Now.AddMonths(-3), PetType = allPetTypes[4], PetPrice = 59
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-856), PetColor = "caramel", PetName = "Tommy", PetPreviousOwner = "Nicole Jaramillo", PetOwner = allOwners[6], PetSoldDate = DateTime.Now.AddMonths(-15), PetType = allPetTypes[5], PetPrice = 76
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-1576), PetColor = "black", PetName = "Beauty", PetPreviousOwner = "Hibah Bartlet", PetOwner = allOwners[7], PetSoldDate = DateTime.Now.AddMonths(-21), PetType = allPetTypes[6], PetPrice = 1090
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-10), PetColor = "white", PetName = "Beatrice", PetPreviousOwner = "Radhika Baird", PetOwner = allOwners[8], PetSoldDate = DateTime.Now, PetType = allPetTypes[3], PetPrice = 28
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-33), PetColor = "beige", PetName = "Jumpy", PetPreviousOwner = "Havin Boyle", PetOwner = allOwners[0], PetSoldDate = DateTime.Now.AddMonths(-1), PetType = allPetTypes[2], PetPrice = 100
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-63), PetColor = "spotted brown", PetName = "Cujo", PetPreviousOwner = "Franklin Barajas", PetOwner = allOwners[9], PetSoldDate = DateTime.Now.AddMonths(-1), PetType = allPetTypes[6], PetPrice = 346
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-18), PetColor = "merle", PetName = "Shenna", PetPreviousOwner = "Jovan Bloggs", PetOwner = allOwners[1], PetSoldDate = DateTime.Now, PetType = allPetTypes[3], PetPrice = 865
                },
                new Pet {
                    PetBirthday = DateTime.Now.AddDays(-156), PetColor = "red", PetName = "Firehoof", PetPreviousOwner = "Aamna Atherton", PetOwner = allOwners[7], PetSoldDate = DateTime.Now.AddMonths(-3), PetType = allPetTypes[0], PetPrice = 2096
                }
            };

            foreach (var petType in allPetTypes)
            {
                _petTypeRepo.AddNewPetType(petType);
            }

            foreach (var owner in allOwners)
            {
                _ownerRepo.AddNewOwner(owner);
            }

            foreach (var pet in allPets)
            {
                _petRepo.AddNewPet(pet);
            }

            return("Fake data injected.");
        }
コード例 #3
0
        public string InitData()
        {
            List <PetType> allPetTypes = new List <PetType>
            {
                new PetType {
                    NameOfPetTypes = "Dog"
                },
                new PetType {
                    NameOfPetTypes = "Cat"
                },
                new PetType {
                    NameOfPetTypes = "Snake"
                },
                new PetType {
                    NameOfPetTypes = "Hawk"
                },
                new PetType {
                    NameOfPetTypes = "Lion"
                },
                new PetType {
                    NameOfPetTypes = "Goat"
                },
                new PetType {
                    NameOfPetTypes = "Lizard"
                },
                new PetType {
                    NameOfPetTypes = "Rabbit"
                },
                new PetType {
                    NameOfPetTypes = "Dragon"
                },
                new PetType {
                    NameOfPetTypes = "Turtle"
                }
            };
            List <Owner> allOwners = new List <Owner>
            {
                new Owner {
                    FirstName   = "Jack", LastName = "Davidson", Address = "Deadwell 3, 6600 Vejen",
                    PhoneNumber = "3333 44444", Email = "*****@*****.**"
                },
                new Owner {
                    FirstName   = "Peter", LastName = "Parker", Address = "Pride 69, 6969 Someplace",
                    PhoneNumber = "6969 6969", Email = "*****@*****.**"
                },
                new Owner {
                    FirstName   = "Clark", LastName = "Kent", Address = "Shittington 3, Smallville",
                    PhoneNumber = "DC Comics 45", Email = "*****@*****.**"
                },
                new Owner {
                    FirstName   = "Tony", LastName = "Stark", Address = "ExpensivePlace 4, Malibu State",
                    PhoneNumber = "I AM IRONMAN 10", Email = "*****@*****.**"
                },
                new Owner {
                    FirstName   = "Steve", LastName = "Rogers", Address = "Brooklyn 4, 1918",
                    PhoneNumber = "America 5504", Email = "*****@*****.**"
                },
                new Owner {
                    FirstName   = "Natasha", LastName = "Romanoff", Address = "Red Room, Russia",
                    PhoneNumber = "0000 0000", Email = "*****@*****.**"
                },
                new Owner {
                    FirstName   = "Bruce", LastName = "Wayne", Address = "Wayne Manor, Gotham City",
                    PhoneNumber = "1234 5678", Email = "*****@*****.**"
                },
                new Owner {
                    FirstName   = "Arthur", LastName = "Curry", Address = "Coral Reef, Atlantis",
                    PhoneNumber = "9012 3456", Email = "*****@*****.**"
                }
            };

            List <Pet> allPets = new List <Pet>
            {
                new Pet {
                    Name          = "Dante", Birthdate = new DateTime(2013, 7, 8), SoldDate = new DateTime(2014, 7, 8),
                    previousOwner = "Uriel Sorensson", Price = 250, PetType = allPetTypes[0], PetOwner = allOwners[0]
                },
                new Pet {
                    Name          = "Vergil", Birthdate = new DateTime(2015, 2, 4), SoldDate = new DateTime(2016, 2, 4),
                    previousOwner = "Bruce Wayne", Price = 750, PetType = allPetTypes[1], PetOwner = allOwners[1]
                },
                new Pet {
                    Name          = "Lady", Birthdate = new DateTime(2014, 5, 2), SoldDate = new DateTime(2016, 2, 4),
                    previousOwner = "Loki Odinson", Price = 360, PetType = allPetTypes[2], PetOwner = allOwners[2]
                },
                new Pet {
                    Name          = "Trish", Birthdate = new DateTime(2012, 6, 4), SoldDate = new DateTime(2012, 7, 3),
                    previousOwner = "Urizen Sparkles", Price = 70, PetType = allPetTypes[3], PetOwner = allOwners[3]
                },
                new Pet {
                    Name          = "Irish", Birthdate = new DateTime(2011, 4, 6), SoldDate = new DateTime(2013, 3, 1),
                    previousOwner = "Simba", Price = 120, PetType = allPetTypes[4], PetOwner = allOwners[4]
                },
                new Pet {
                    Name          = "Barry", Birthdate = new DateTime(1920, 4, 6), SoldDate = new DateTime(2018, 3, 1),
                    previousOwner = "Henry Allen", Price = 30, PetType = allPetTypes[5], PetOwner = allOwners[5]
                },
                new Pet {
                    Name          = "OLiver", Birthdate = new DateTime(1970, 5, 9), SoldDate = new DateTime(2019, 2, 3),
                    previousOwner = "Moira", Price = 306, PetType = allPetTypes[6], PetOwner = allOwners[6]
                },
            };

            foreach (var pet in allPets)
            {
                _petRepo.Create(pet);
            }
            foreach (var owner in allOwners)
            {
                _ownerRepo.Create(owner);
            }
            foreach (var petType in allPetTypes)
            {
                _petTypeRepo.AddNewPetType(petType);
            }
            return("Data has been made.");
        }
コード例 #4
0
 public bool AddNewPetType(PetType type)
 {
     return(_petTypeRepository.AddNewPetType(type));
 }
コード例 #5
0
 public PetType AddNewPetType(PetType newPetType)
 {
     return(_petTypeRepo.AddNewPetType(newPetType));
 }
コード例 #6
0
 public PetType AddNewPetType(PetType theNewType)
 {
     return(_petTypeRepo.AddNewPetType(theNewType));
 }
コード例 #7
0
        // Adds a new pet, Owner, Color and Type are added unless their ID is given, in which case they are found by Id.
        public Pet AddNewPet(Pet theNewPet)
        {
            List <PetType> theType = null;

            if (theNewPet.PetType.PetTypeId != 0)
            {
                theType = _petTypeRepo.FindPetTypeById(theNewPet.PetType.PetTypeId);
                if (theType.Count != 1)
                {
                    throw new Exception("Sorry can't find that type.");
                }
            }
            else
            {
                theType = new List <PetType> {
                    _petTypeRepo.AddNewPetType(theNewPet.PetType)
                };
            }

            if (theType.Count != 1)
            {
                throw new Exception(message: "Could not find the type.");
            }
            else
            {
                theNewPet.PetType = theType[0];
            }

            List <Owner> theOwners = null;

            if (theNewPet.PetOwner.OwnerId == 0)
            {
                theOwners = new List <Owner> {
                    _ownerRepo.AddNewOwner(theNewPet.PetOwner)
                };
            }
            else
            {
                theOwners = _ownerRepo.FindOwnerByID(theNewPet.PetOwner.OwnerId);
            }

            if (theOwners.Count != 1)
            {
                throw new Exception(message: "Could not find the right owner");
            }
            else
            {
                theNewPet.PetOwner = theOwners[0];
            }

            List <PetColor> theColors = null;

            foreach (var color in theNewPet.PetColor)
            {
                PetColor theColor;
                if (color.petColorId != 0)
                {
                    var allColors = _petColorRepo.FindPetColorById(color.petColorId);
                    if (allColors.Count() != 1)
                    {
                        throw new Exception(message: "Wrong nr of id's found");
                    }
                    else
                    {
                        theColor = allColors[0];
                    }
                }
                else
                {
                    theColor = _petColorRepo.AddNewPetColor(color.petColor);
                }
                if (theColors == null)
                {
                    theColors = new List <PetColor> {
                        theColor
                    };
                }
                else
                {
                    theColors.Add(theColor);
                }
            }
            List <PetColorPet> thePetColorPets = new List <PetColorPet>();

            foreach (var color in theColors)
            {
                thePetColorPets.Add(new PetColorPet {
                    petColor = color
                });
            }
            theNewPet.PetColor = thePetColorPets;

            return(_petRepo.AddNewPet(theNewPet));
        }
コード例 #8
0
ファイル: PetTypeService.cs プロジェクト: domco545/PetShop
 public bool AddNewPetType(PetType type)
 {
     _validator.PetTypeValidator(type);
     return(_petTypeRepository.AddNewPetType(type));
 }