Example #1
0
        public Quantity CreateANewQuantity(int amount, int unitId)
        {
            DataBaseRepo database = new DataBaseRepo();
            var          result   = (DatabaseHolder)database.Save(new Quantity {
                Amount = amount, UnitId = unitId
            });
            var quantity = (Quantity)database.GetObject(result.PrimaryKey.ToString(), new Quantity());

            return(quantity);
        }
Example #2
0
        public void GetWinner()
        {
            var database = new DataBaseRepo();
            var sut      = new BowlingSystem();
            var contest  = (Contest)database.GetObject("1011", new Contest());

            contest.WinnerId = 2026;
            var result = sut.GetWinnerOfContest(contest);

            Assert.Equal(contest.ContestId, result.ContestId);
        }
Example #3
0
        public void SelectOne()
        {
            var timePeriod = new TimePeriod {
                TimePeriodId = 1, StartDate = DateTime.Now, EndDate = DateTime.Parse("2018-05-28 07:00")
            };
            //var party = new Party { Address="Vägen 12", IsMana,ger=false, LegalId="8705281425", Name="Test Testsson" };
            var dbRepo = new DataBaseRepo();
            var result = dbRepo.GetObject("1", timePeriod);

            Assert.Equal(timePeriod.ToString(), result.ToString());
        }
Example #4
0
        public void FindPartyWithKnownKey()
        {
            var party = new Party {
                Address = "Vägen 13", IsManager = false, LegalId = "8705281425", Name = "Test Testsson"
            };
            var dbRepo = new DataBaseRepo();
            //var result = dbRepo.Save(party);
            //var pk = ((DatabaseHolder)result).PrimaryKey;
            Party foundParty = (Party)dbRepo.GetObject("2026", new Party());

            Assert.Equal(2026, foundParty.PartyId);
        }
Example #5
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);
        }