Beispiel #1
0
        public AddPetResponse AddPet(AddPetRequest request)
        {
            var response = new AddPetResponse();
            var breed    = _context.BreedType.FirstOrDefault(b => b.Name == request.BreedName);

            if (breed == null)
            {
                var breed_type = new BreedType()
                {
                    IdBreedType = _context.Pet.Max(p => p.IdBreedType) + 1,
                    Name        = request.BreedName
                };
                _context.BreedType.Add(breed_type);
            }

            var pet = new Pet()
            {
                IdPet                  = _context.Pet.Max(p => p.IdPet) + 1,
                Name                   = request.Name,
                IsMale                 = request.IsMale,
                DateRegistered         = request.DateRegistered,
                ApproximateDateOfBirth = request.ApproximatedDateOfBirth
            };

            _context.Pet.Add(pet);
            response.BreedName               = request.BreedName;
            response.Name                    = pet.Name;
            response.IsMale                  = pet.IsMale;
            response.DateRegistered          = pet.DateRegistered;
            response.ApproximatedDateOfBirth = pet.ApproximateDateOfBirth;
            _context.SaveChanges();
            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Read the list of dogs from the json given and create a list of Dog objects
        /// </summary>
        /// <returns>The list of Dog objects created from the data</returns>
        private List <Dog> getDataFromJsonString()
        {
            // the list sent with the document, " has been replaced with \"
            string  json    = "{\"affenpinscher\": [],\"african\": [],\"airedale\": [],\"akita\": [],\"appenzeller\": [],\"basenji\": [],\"beagle\": [],\"bluetick\": [],\"borzoi\": [],\"bouvier\": [],\"boxer\": [],\"brabancon\": [],\"briard\": [],\"bulldog\": [\"boston\", \"french\"],\"bullterrier\": [\"staffordshire\"],\"cairn\": [],\"chihuahua\": [],\"chow\": [],\"clumber\": [],\"collie\": [\"border\"],\"coonhound\": [],\"corgi\": [\"cardigan\"],\"dachshund\": [],\"dane\": [\"great\"],\"deerhound\": [\"scottish\"],\"dhole\": [],\"dingo\": [],\"doberman\": [],\"elkhound\": [\"norwegian\"],\"entlebucher\": [],\"eskimo\": [],\"germanshepherd\": [],\"greyhound\": [\"italian\"],\"groenendael\": [],\"hound\": [\"Ibizan\", \"afghan\", \"basset\", \"blood\", \"english\", \"walker\"],\"husky\": [],\"keeshond\": [],\"kelpie\": [],\"komondor\": [],\"kuvasz\": [],\"labrador\": [],\"leonberg\": [],\"lhasa\": [],\"malamute\": [],\"malinois\": [],\"maltese\": [],\"mastiff\": [\"bull\", \"tibetan\"],\"mexicanhairless\": [],\"mountain\": [\"bernese\", \"swiss\"],\"newfoundland\": [],\"otterhound\": [],\"papillon\": [],\"pekinese\": [],\"pembroke\": [],\"pinscher\": [\"miniature\"],\"pointer\": [\"german\"],\"pomeranian\": [],\"poodle\": [\"miniature\", \"standard\", \"toy\"],\"pug\": [],\"pyrenees\": [],\"redbone\": [],\"retriever\": [\"chesapeake\", \"curly\", \"flatcoated\", \"golden\"],\"ridgeback\": [\"rhodesian\"],\"rottweiler\": [],\"saluki\": [],\"samoyed\": [],\"schipperke\": [],\"schnauzer\": [\"giant\", \"miniature\"],\"setter\": [\"english\", \"gordon\", \"irish\"],\"sheepdog\": [\"english\", \"shetland\"],\"shiba\": [],\"shihtzu\": [],\"spaniel\": [\"blenheim\", \"brittany\", \"cocker\", \"irish\", \"japanese\", \"sussex\", \"welsh\"],\"springer\": [\"english\"],\"stbernard\": [],\"terrier\": [  \"american\",  \"australian\",  \"bedlington\",  \"border\",  \"dandie\",  \"fox\",  \"irish\",  \"kerryblue\",  \"lakeland\",  \"norfolk\",  \"norwich\",  \"patterdale\",  \"scottish\",  \"sealyham\",  \"silky\",  \"tibetan\",  \"toy\",  \"westhighland\",  \"wheaten\",  \"yorkshire\"],\"vizsla\": [],\"weimaraner\": [],\"whippet\": [],\"wolfhound\": [\"irish\"] } ";
            JObject jObject = JObject.Parse(json);

            List <Dog> dogs = new List <Dog>();

            // go through all the different dog breeds and add them to the list
            foreach (JToken dogJT in jObject.Children())
            {
                Dog dog = new Dog();

                // gets the dog breed
                dog.Breed = dogJT.Path;
                dog.Types = new List <BreedType>();

                // check if any gos types are given for the specific breed
                if (dogJT.Children().FirstOrDefault().HasValues)
                {
                    // add each sub type to the breed types list
                    foreach (var child in dogJT.Children().FirstOrDefault().Children())
                    {
                        BreedType type = new BreedType();
                        type.Type = child.ToString();
                        dog.Types.Add(type);
                    }
                }

                dogs.Add(dog);
            }

            return(dogs);
        }
Beispiel #3
0
        public bool Create(string name, string age, string breed)
        {
            using (KittenDbContext db = new KittenDbContext())
            {
                if (db.Kittens.Any(k => k.Name == name))
                {
                    return(false);
                }

                int parsedAge = this.ParsedAge(age);

                BreedType parsedBreed = this.ParseBreed(breed);

                if (parsedBreed == BreedType.Udefined || parsedAge == -1)
                {
                    return(false);
                }


                Kitten cat = new Kitten
                {
                    Name  = name,
                    Age   = parsedAge,
                    Breed = parsedBreed
                };

                db.Kittens.Add(cat);
                db.SaveChanges();

                return(true);
            }
        }
Beispiel #4
0
        static void Run(int ind, int ind_max, int ind_inc, int total_it, int stringlenbegin, BreedType breed, CrossType cross, string filename)
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(filename, true))
            {
                GenControl cont = new GenControl(breed,cross);
                cont.setFile(filename);

                float average;

                for (int j = ind; j <= ind_max; j += ind_inc)
                {
                    average = 0;

                    Console.WriteLine("String Length: " + j);
                    for (int i = 0; i < total_it; i++)
                    {
                        var gener = cont.defaultInitString(j, stringlenbegin, stringlenbegin*2);
                        average += gener;
                        Console.Write(gener + " ");
                    }
                    average /= ((float)total_it);
                    file.WriteLine(j + "," + average);
                    Console.WriteLine();
                    Console.WriteLine("Average: " + average);
                    Console.WriteLine();
                    Console.WriteLine();
                }

            }
        }
        public void Should_Return_The_Right_Collection()
        {
            var ContextMock = new AnimaniaConsoleContext(Effort.DbConnectionFactory.CreateTransient());

            var LocationMock   = new Mock <ILocationServices>();
            var AnimalTypeMock = new Mock <IAnimalTypeServices>();
            var BreedTypeMock  = new Mock <IBreedTypeServices>();

            postServices = new PostServices(ContextMock, LocationMock.Object, AnimalTypeMock.Object, BreedTypeMock.Object);
            User user = new User()
            {
                Id       = 1,
                UserName = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };
            BreedType breed = new BreedType()
            {
                BreedTypeName = "TestBreed",
                AnimalTypeId  = 1
            };
            AnimalType type = new AnimalType()
            {
                AnimalTypeName = "TestAnimalTypeName",
            };
            Location location = new Location()
            {
                LocationName = "TestLocation",
            };
            var animal = new Animal
            {
                AnimalName   = "TestAnimalTypeName",
                Birthday     = DateTime.Now,
                AnimalTypeId = 1,
                BreedTypeId  = 1,
                LocationId   = 1,
                UserId       = 1
            };

            var post = new CreatePostModel()
            {
                Title          = "1234567890",
                Description    = "12345678901234567890",
                Status         = true,
                Price          = 12.0M,
                LocationName   = location.LocationName,
                AnimalTypeName = "TestAnimalTypeName",
                BreedTypeName  = "TestBreed",
                AnimalName     = "TestAnimalName",
                Birthday       = DateTime.Now
            };



            Assert.IsInstanceOfType(postServices.GetAllMyPosts(1), typeof(IEnumerable <PostModel>));
        }
Beispiel #6
0
 private BreedType ParseBreed(string breed)
 {
     try
     {
         BreedType content = (BreedType)Enum.Parse(typeof(BreedType), breed);
         return(content);
     }
     catch (Exception)
     {
         return(default(BreedType));
     }
 }
Beispiel #7
0
        public Pet AddPet(PetRequest petRequest)
        {
            var breedTyp = _context.BreedTypes.Where(m => m.Name == petRequest.BreedName).FirstOrDefault();
            int max      = _context.BreedTypes.DefaultIfEmpty().Max(m => m == null ? 0 : m.IdBreedType);
            int maxP     = _context.Pets.DefaultIfEmpty().Max(m => m == null ? 0 : m.IdPet);
            int idBreed  = _context.BreedTypes.Where(m => m.Name == petRequest.BreedName).Select(m => m.IdBreedType).FirstOrDefault();
            var pet      = new Pet();

            if (breedTyp == null)
            {
                var newBreed = new BreedType
                {
                    IdBreedType = max + 1,
                    Name        = petRequest.BreedName
                };

                _context.Attach(newBreed);
                _context.Add(newBreed);


                pet = new Pet

                {
                    IdPet          = maxP + 1,
                    IdBreedType    = max + 1,
                    Name           = petRequest.Name,
                    IsMale         = petRequest.IsMale,
                    DateRegistered = petRequest.DateRegistered,
                    DateOfBirth    = petRequest.DateOfBirth
                };

                _context.Attach(pet);
                _context.Add(pet);
                _context.SaveChanges();
            }
            else
            {
                pet = new Pet

                {
                    IdPet          = maxP + 1,
                    IdBreedType    = idBreed,
                    Name           = petRequest.Name,
                    IsMale         = petRequest.IsMale,
                    DateRegistered = petRequest.DateRegistered,
                    DateOfBirth    = petRequest.DateOfBirth
                };
                _context.Attach(pet);
                _context.Add(pet);
                _context.SaveChanges();
            }
            return(pet);
        }
Beispiel #8
0
        public static string ConvertEnum(BreedType breed)
        {
            switch (breed)
            {
            case BreedType.StreetTranscended: return("Street Transcended");

            case BreedType.AmericanShorthair: return("American Shorthair");

            case BreedType.Munchkin: return("Munchkin");

            case BreedType.Siamese: return("Siamese");

            default: return("Invalid type");
            }
        }
        public void Initialize()
        {
            Mapper.Initialize(config =>
            {
                config.CreateMap <CreatePostModel, Post>().ReverseMap();
            });

            locationServicesMock   = new Mock <ILocationServices>();
            animalTypeServicesMock = new Mock <IAnimalTypeServices>();
            breedTypeServicesMock  = new Mock <IBreedTypeServices>();
            effortContext          = new AnimaniaConsoleContext(Effort.DbConnectionFactory.CreateTransient());

            postService = new PostServices(effortContext, locationServicesMock.Object, animalTypeServicesMock.Object, breedTypeServicesMock.Object);

            User user = new User()
            {
                UserName = "******",
                Password = "******",
                Email    = "*****@*****.**"
            };
            BreedType breed = new BreedType()
            {
                BreedTypeName = "TestBreed",
                AnimalTypeId  = 1
            };
            AnimalType type = new AnimalType()
            {
                AnimalTypeName = "TestAnimalTypeName",
            };
            Location location = new Location()
            {
                LocationName = "TestLocation",
            };

            effortContext.Locations.Add(location);
            effortContext.AnimalTypes.Add(type);
            effortContext.BreedTypes.Add(breed);
            effortContext.Users.Add(user);
            effortContext.SaveChanges();
        }
Beispiel #10
0
        public string AddPet(Pet pet)
        {
            var db = new s19562Context();

            var rasa = pet.IdBreedType;

            var exist = db.BreedType.Any(i => i.IdBreedType == rasa);


            if (!exist)
            {
                var maxId     = db.BreedType.Max(a => a.IdBreedType);
                var BreedType = new BreedType
                {
                    IdBreedType = maxId + 1
                };

                db.BreedType.Add(BreedType);
            }

            db.Pet.Add(pet);
            db.SaveChanges();
            return("zwierze dodane --> sprawdz");
        }
Beispiel #11
0
        public bool AddPet(AddPetReq req)
        {
            var pet = new AddPetReq
            {
                BreedName              = req.BreedName,
                Name                   = req.Name,
                IsMale                 = req.IsMale,
                DateRegistered         = req.DateRegistered,
                ApprocimateDateOfBirth = req.ApprocimateDateOfBirth,
            };
            var idb    = context.BreedType.Where(b => b.Name == pet.BreedName).Select(p => p.IdBreedType).First();
            var idbool = context.BreedType.Where(b => b.Name == pet.BreedName).Select(p => p.IdBreedType).Any();

            if (!idbool)
            {
                var br = new BreedType
                {
                    IdBreedType = context.BreedType.Max(b => b.IdBreedType) + 1,
                    Name        = pet.BreedName,
                };
                context.BreedType.Add(br);
            }
            var np = new Pet
            {
                IdPet                  = context.Pet.Max(p => p.IdPet) + 1,
                IdBreedType            = idb,
                Name                   = pet.Name,
                IsMale                 = pet.IsMale,
                DateRegistered         = pet.DateRegistered,
                ApprocimateDateOfBirth = pet.ApprocimateDateOfBirth
            };

            context.Pet.Add(np);
            context.SaveChanges();
            return(true);
        }
Beispiel #12
0
 public GenControl(BreedType _breed, CrossType _cross)
 {
     breed = _breed;
     cross = _cross;
     targetString = Encoding.ASCII.GetBytes("THE_STRING_MATCH");
 }
 public Generation PairBreed(BreedType breedType, Generation generation, int offSpringPerPair, int maxOffspring)
 {
     return(null);
 }
Beispiel #14
0
 public void SetBreedType(BreedType breed)
 {
     switch (breed)
     {
         case BreedType.RandomTop:
             breedFunc = Breed_RandomTop;
             break;
         case BreedType.ProportionalRating:
             breedFunc = Breed_ProportionalRating;
             break;
         case BreedType.ProportionalRanking:
             breedFunc = Breed_ProportionalRanking;
             break;
         case BreedType.Tournament:
             breedFunc = Breed_Tournament;
             break;
     }
 }
        /// <summary>
        /// 基本的な能力を設定する
        /// </summary>
        /// <param name="i"></param>
        /// <param name="basecValue"></param>
        /// <param name="breedType"></param>
        /// <param name="teamSetting"></param>
        /// <returns></returns>
        private GameMember SetBasicAbility(int i, int basecValue, BreedType breedType, TeamSetting teamSetting)
        {
            Player player = new Player();
            player.Name = i.ToString();
            player.BreedType = breedType;
            player.FielderAbility.Meet = basecValue;
            player.FielderAbility.Power = basecValue;
            player.FielderAbility.Run = basecValue;
            player.FielderAbility.Defense = basecValue;
            player.FielderAbility.Wisdom = basecValue;
            player.PitcherAbility.Fastball = basecValue;
            player.PitcherAbility.Breakingball = basecValue;
            player.PitcherAbility.Control = basecValue;
            player.PitcherAbility.Stamina = basecValue;
            player.IsLeftThrow = false;
            player.IsLeftBox = false;

            // 守備適性の設定
            int defensePositionIntValue = i;
            if (defensePositionIntValue > 9)
            {
                defensePositionIntValue = 0;
            }
            DefensePosition defensePosition = (DefensePosition)defensePositionIntValue;
            switch (defensePosition)
            {
                case DefensePosition.Pitcher:
                    player.FielderAbility.DefenseType = DefenseType.Pitcher;
                    break;
                case DefensePosition.Catcher:
                    player.FielderAbility.DefenseType = DefenseType.Catcher;
                    break;
                case DefensePosition.First:
                case DefensePosition.Second:
                case DefensePosition.Third:
                case DefensePosition.Short:
                    player.FielderAbility.DefenseType = DefenseType.Infielder;
                    break;
                case DefensePosition.Right:
                case DefensePosition.Center:
                case DefensePosition.Left:
                    player.FielderAbility.DefenseType = DefenseType.Outfielder;
                    break;
                case DefensePosition.Sub:
                    if (i <= 12)
                    {
                        // 控え投手3人
                        player.FielderAbility.DefenseType = DefenseType.Pitcher;
                    }
                    else if (i == 13)
                    {
                        player.FielderAbility.DefenseType = DefenseType.Catcher;
                    }
                    else if (i <= 16)
                    {
                        player.FielderAbility.DefenseType = DefenseType.Infielder;
                    }
                    else
                    {
                        player.FielderAbility.DefenseType = DefenseType.Outfielder;
                    }
                    break;
                default:
                    throw new Exception("不明な守備位置");
            }

            // メンバの作成
            GameMember member = new GameMember(player, defensePosition);
            teamSetting.DefaultGameMembers.Add(member);

            return member;
        }
Beispiel #16
0
 /// <summary>
 /// 指定した種族のイメージを取得する
 /// </summary>
 /// <param name="type">種族</param>
 /// <returns>イメージ</returns>
 public static BitmapImage GetPlayerImage(BreedType type)
 {
     // なぜか最初にイメージを読み込んだコントロールでの相対パスが正しくないと
     // その後のすべてのコントロールでイメージが表示されない
     // よって、uriがどの階層から読み込んでも問題ないようにするために
     // いったんルートフォルダに到達してから参照するパスを示す
     string uriString = string.Format("../../../../../../Images/{0}.png", type);
     return new BitmapImage(new Uri(uriString, UriKind.RelativeOrAbsolute));
 }