Exemplo n.º 1
0
        public IHttpActionResult GetHumanById(int humanID)
        {
            var service = new HumanService();
            var human   = service.GetHumanById(humanID);

            return(Ok(human));
        }
Exemplo n.º 2
0
        public IHttpActionResult Get()
        {
            var service = new HumanService();
            var human   = service.GetHumans();

            return(Ok(human));
        }
Exemplo n.º 3
0
        public IHttpActionResult Delete(int id)
        {
            var service = new HumanService();

            if (!service.DeleteHuman(id))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Exemplo n.º 4
0
        public async Task <StatsViewModel> getStats()
        {
            IHumanStats query = new HumanService(_context);
            var         list  = await query.GetHumans();

            StatsViewModel stats = new StatsViewModel();

            stats.count_mutant_dna = list.Where(m => m.mutant).Count();
            stats.count_human_dna  = list.Where(m => !m.mutant).Count();
            stats.ratio            = stats.count_human_dna > 0 ? Math.Round(Convert.ToDouble(stats.count_mutant_dna) / Convert.ToDouble(stats.count_human_dna), 2) : 0;

            return(stats);
        }
Exemplo n.º 5
0
        public IHttpActionResult Put(HumanEdit human)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = new HumanService();

            if (!service.UpdateHuman(human))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Exemplo n.º 6
0
 public void BtnOK()
 {
     if (string.IsNullOrEmpty(Human.Name) || string.IsNullOrWhiteSpace(Human.Name))
     {
         MessageBox.Show("请填写姓名", "提示");
         return;
     }
     if (Human.Age == null)
     {
         MessageBox.Show("请填写年龄", "提示");
         return;
     }
     if (SelSex == null)
     {
         MessageBox.Show("请选择性别", "提示");
         return;
     }
     if (SelSex == "男")
     {
         Human.Sex = 1;
     }
     else
     {
         Human.Sex = 2;
     }
     if (_isAdd == 1)
     {
         if (HumanService.InsertHuman(Human))
         {
             MessageBox.Show("添加成功", "提示");
             this.TryClose();
         }
         else
         {
             MessageBox.Show("添加失败", "提示");
         }
     }
     else if (_isAdd == 2)
     {
         if (HumanService.UpdateHuman(Human))
         {
             MessageBox.Show("修改成功", "提示");
             this.TryClose();
         }
         else
         {
             MessageBox.Show("修改失败", "提示");
         }
     }
 }
Exemplo n.º 7
0
 public void DeleteInfo(HumanEnt ent)
 {
     if (MessageBox.Show("确定删除人员" + ent.Name + "?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
     {
         if (HumanService.DeleteHuman(ent.ID))
         {
             MessageBox.Show("删除成功", "提示");
             HumanList.Remove(ent);
         }
         else
         {
             MessageBox.Show("删除失败", "提示");
         }
     }
 }
Exemplo n.º 8
0
        public async Task <ActionResult> isMutant(DNAViewModel dna)
        {
            bool   mutant = isMutant(dna.dna);
            IHuman query  = new HumanService(_context);
            await query.PostHuman(string.Join(",", dna.dna.ToArray()), mutant);

            if (mutant)
            {
                return(Ok());
            }
            else
            {
                return(StatusCode(403));
            }
        }
Exemplo n.º 9
0
        public void SetDataGrid()
        {
            CloseAllGrid();
            ListVis = Visibility.Visible;
            if (!_isChange)
            {
                ChangeColor();
            }
            HumanList = new BindableCollection <HumanEnt>();
            List <HumanEnt> list = HumanService.GetHumanList();

            if (list?.Count > 0)
            {
                HumanList = new BindableCollection <HumanEnt>(list);
            }
            //List<string> names = new List<string>() { "刘一", "陈二", "张三", "李四", "王五", "赵六", "孙七", "周八", "吴九", "郑十" };
            //Random r = new Random();
            //for (int i = 1; i <= 5; i++)
            //{
            //    HumanEnt human = new HumanEnt() { ID = i, Name = names[r.Next(0, 10)], Sex = r.Next(1, 3), Age = r.Next(18, 61), Phone = r.Next(139123, 139456).ToString(), Education = EducationEnum.本科, Email = "*****@*****.**", Birthday = DateTime.Now.AddDays(i - 1) };
            //    HumanList.Add(human);
            //}
        }
Exemplo n.º 10
0
        private static void DoEverythingSync()
        {
            var           useWcf = true;
            IHumanService humanService;
            IDogService   dogService;

            if (useWcf)
            {
                humanService = InProcFactory.CreateInstance <HumanService, IHumanService>();
                dogService   = InProcFactory.CreateInstance <DogService, IDogService>();
            }
            else
            {
                humanService = new HumanService();
                dogService   = new DogService();
            }

            var humanRecord = new List <Human>();
            var dogRecord   = new List <Dog>();

            for (int i = 0; i < 1000; i++)
            {
                var newHuman = new Human
                {
                    DateOfBirth = DateTime.Today.AddYears(_random.Next(20, 50) * -1),
                    Forename    = _forenames[_random.Next(0, _forenames.Length)],
                    Surname     = _surnames[_random.Next(0, _surnames.Length)]
                };

                newHuman.Id = humanService.AddHumanSync(newHuman);
                humanRecord.Add(newHuman);
            }

            for (int i = 0; i < 1000; i++)
            {
                var newDog = new Dog
                {
                    Breed       = (DogBreed)_random.Next(1, 3),
                    DateOfBirth = DateTime.Today.AddYears(_random.Next(3, 12) * -1),
                    Name        = _dognames[_random.Next(0, _dognames.Length)]
                };

                newDog.Id = dogService.AddDogSync(newDog);
                dogRecord.Add(newDog);
            }

            for (int i = 0; i < 1000; i++)
            {
                var firstFriendId = _random.Next(0, 999);
                dogService.MakeFriendSync(dogRecord[i], dogRecord[firstFriendId]);

                var secondFriendId = _random.Next(0, 999);
                while (secondFriendId == firstFriendId)
                {
                    secondFriendId = _random.Next(0, 999);
                }
                dogService.MakeFriendSync(dogRecord[i], dogRecord[secondFriendId]);
            }

            for (int i = 0; i < 1000; i++)
            {
                humanService.AdoptDogSync(humanRecord[i], dogRecord[i]);
            }

            using (var context = EntityFunDbContext.Create())
            {
                var dogCount = context.Dogs.Count();
                Console.WriteLine("There are {0} dogs in the system", dogCount);

                var humanCount = context.Humans.Count();
                Console.WriteLine("There are {0} humans in the system", humanCount);

                var dogFriends = context.Dogs.SelectMany(x => x.Friends).Count();
                Console.WriteLine(dogFriends);

                var dogsWithManyFriends = context.Dogs.Count(x => x.Friends.Count > 2);
                Console.WriteLine("{0} dogs have more than 2 friends", dogsWithManyFriends);

                Console.WriteLine("{0} dogs have 0 friends", context.Dogs.Count(x => x.Friends.Count == 0));
            }
        }
Exemplo n.º 11
0
        private static async Task DoEverything()
        {
            var           useWcf = true;
            IHumanService humanService;
            IDogService   dogService;

            if (useWcf)
            {
                humanService = InProcFactory.CreateInstance <HumanService, IHumanService>();
                dogService   = InProcFactory.CreateInstance <DogService, IDogService>();
            }
            else
            {
                humanService = new HumanService();
                dogService   = new DogService();
            }

            var humanRecord = new List <Human>();
            var dogRecord   = new List <Dog>();

            var numberOfIterations = 100;

            var humanAddTasks = Enumerable.Range(0, numberOfIterations)
                                .Select(async i =>
            {
                var newHuman = new Human
                {
                    DateOfBirth = DateTime.Today.AddYears(_random.Next(20, 50) * -1),
                    Forename    = _forenames[_random.Next(0, _forenames.Length)],
                    Surname     = _surnames[_random.Next(0, _surnames.Length)]
                };

                newHuman.Id = await humanService.AddHumanAsync(newHuman);
                humanRecord.Add(newHuman);
            });
            await Task.WhenAll(humanAddTasks);

            var dogAddTasks = Enumerable.Range(0, numberOfIterations)
                              .Select(async i =>
            {
                var newDog = new Dog
                {
                    Breed       = (DogBreed)_random.Next(1, 3),
                    DateOfBirth = DateTime.Today.AddYears(_random.Next(3, 12) * -1),
                    Name        = _dognames[_random.Next(0, _dognames.Length)]
                };

                newDog.Id = await dogService.AddDogAsync(newDog);
                dogRecord.Add(newDog);
            });
            await Task.WhenAll(dogAddTasks);

            var dogFriendTasks = Enumerable.Range(0, numberOfIterations)
                                 .Select(async i =>
            {
                var firstFriendId = _random.Next(0, numberOfIterations - 1);
                await dogService.MakeFriendAsync(dogRecord[i], dogRecord[firstFriendId]);

                var secondFriendId = _random.Next(0, numberOfIterations - 1);
                while (secondFriendId == firstFriendId)
                {
                    secondFriendId = _random.Next(0, numberOfIterations - 1);
                }

                await dogService.MakeFriendAsync(new Dog {
                    Id = i
                }, new Dog {
                    Id = secondFriendId
                });
            });
            await Task.WhenAll(dogFriendTasks);

            var adoptDogTasks = Enumerable.Range(0, numberOfIterations)
                                .Select(async i =>
            {
                await humanService.AdoptDogAsync(humanRecord[i], dogRecord[i]);
            });
            await Task.WhenAll(adoptDogTasks);

            using (var context = EntityFunDbContext.Create())
            {
                var dogCount = context.Dogs.Count();
                Console.WriteLine("There are {0} dogs in the system", dogCount);

                var humanCount = context.Humans.Count();
                Console.WriteLine("There are {0} humans in the system", humanCount);

                var dogFriends = context.Dogs.SelectMany(x => x.Friends).Count();
                Console.WriteLine("There are {0} dog friend combos", dogFriends);

                var dogsWithManyFriends = context.Dogs.Count(x => x.Friends.Count > 2);
                Console.WriteLine("{0} dogs have more than 2 friends", dogsWithManyFriends);

                Console.WriteLine("{0} dogs have 0 friends", context.Dogs.Count(x => x.Friends.Count == 0));
            }
        }
Exemplo n.º 12
0
 public HumanManager()
 {
     humanService = new HumanService();
 }