コード例 #1
0
        public Contest GetWinnerOfContest(Contest contest)
        {
            var result   = 0;
            var database = new DataBaseRepo();

            var players = database
                          .GetAll(new ContestParticipants())
                          .Cast <ContestParticipants>()
                          .Where(p => contest.ContestId == p.ContestId)
                          .ToList();

            var series = database
                         .GetAll(new Serie())
                         .Cast <Serie>()
                         .Where(s => contest.ContestId == s.ContestId)
                         .ToList();

            var scores = database.GetAll(new Score())
                         .Cast <Score>()
                         .ToList();

            var higherScore  = 0;
            var currentScore = 0;

            foreach (var serie in series)
            {
                var listOfSerieIdsAndPartyIds = new Dictionary <int, int>();
                if (players.FirstOrDefault(p => serie.PartyId == p.CompetitorId) != null)
                {
                    listOfSerieIdsAndPartyIds.Add(serie.PartyId, serie.SerieId);
                }

                if (listOfSerieIdsAndPartyIds.Count != 0)
                {
                    foreach (var item in listOfSerieIdsAndPartyIds)
                    {
                        var quantity = (Quantity)database.GetObject(scores.First(sco => item.Value == sco.SerieId).QuantityId.ToString(), new Quantity());
                        higherScore = quantity.Amount;
                        if (higherScore > currentScore)
                        {
                            currentScore = higherScore;
                            result       = item.Key;
                        }
                    }
                }
            }
            contest.WinnerId = result;
            database.Update(contest);
            return(contest);
        }
コード例 #2
0
        public List <Match> SeeMatches(int contestId)
        {
            var database = new DataBaseRepo();
            var result   = database.GetAll(new Match()).Cast <Match>().ToList();

            return(result.Where(m => contestId == m.ContestId).ToList());
        }
コード例 #3
0
        public void GetListFromSearch()
        {
            var party = new Party {
                PartyId = 2026, Address = "Vägen 13", IsManager = false, LegalId = "8705281425", Name = "Test Testsson"
            };
            var dbRepo = new DataBaseRepo();
            var list   = new List <Party>();

            list.Add(party);
            var foundPartyList = dbRepo.GetAll(new Party());
            var list2          = foundPartyList.Cast <Party>().ToList();

            Assert.Equal(party, list2[0]);
        }
コード例 #4
0
        public Unit WhatUnitDoYouNeedBro(string unitName)
        {
            Unit         unit     = new Unit();
            DataBaseRepo database = new DataBaseRepo();

            foreach (Unit item in database.GetAll(new Unit()).Cast <Unit>().ToList())
            {
                if (item.Name.ToLower() == unitName.ToLower())
                {
                    unit = item;
                }
            }
            return(unit);
        }