Esempio n. 1
0
        public void MapFormFieldsToEntity()
        {
            // Save match date/time to entity
            if (MatchDate.HasValue && MatchTimeFrom.HasValue && MatchTimeTo.HasValue)
            {
                var period = new DateTimePeriod(MatchDate?.Add(MatchTimeFrom.Value), MatchDate?.Add(MatchTimeTo.Value));
                Match.SetRealStart(TimeZoneConverter.ToUtc(period.Start), period.Duration());
            }
            else
            {
                Match.SetRealStart(null, TimeSpan.Zero);
            }

            // Add sets to entity
            Match.Sets.Clear(true);
            for (var i = 0; i < Sets.Count; i++)
            {
                // sets where home and guest ball points are NULL, will be ignored
                if (Sets[i].Home.HasValue || Sets[i].Guest.HasValue)
                {
                    // home or guest NULL values are invalidated with -1
                    Match.Sets.Add(new SetEntity {
                        MatchId = Match.Id, SequenceNo = i + 1, HomeBallPoints = Sets[i].Home ?? -1, GuestBallPoints = Sets[i].Guest ?? -1
                    });
                }
            }

            // point calculation must run before validation because of tie-break handling
            Match.Sets.CalculateSetPoints(Round.SetRule, Round.MatchRule);
            Match.Remarks = Remarks;
            Match.ChangeSerial++;
            Match.IsComplete = true;
        }
        public void Duration(DateTime dt1, DateTime dt2, TimeSpan expected)
        {
            var dtp = new DateTimePeriod(dt1, dt2);

            Assert.AreEqual(expected, dtp.Duration());
        }
        public void DurationNullable(DateTime?dt1, DateTime?dt2, TimeSpan?expected)
        {
            var dtp = new DateTimePeriod(dt1, dt2);

            Assert.AreEqual(expected, dtp.Duration(true));
        }