コード例 #1
0
        public void AddNewContestantWithScoreToEvent(string firstName, string lastName, string onlineNickname, string country, int rank, string score, int eventId)
        {
            if (string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName))
            {
                throw new ArgumentException("You must specify at least one of first name and last name");
            }

            var context = DataEntitiesProvider.Provide();

            var contestant = new Contestant()
            {
                Firstname       = firstName ?? "",
                Lastname        = lastName ?? "",
                Nationality     = country ?? "",
                OnlineNicknames = onlineNickname ?? "",
                Male            = true // The default, to exclude unknown people from Women's Pentamind until we have confirmed they are eligible
            };

            context.Contestants.Add(contestant);

            var evt = context.Events.First(x => x.EIN == eventId);

            var newEntrant = new Entrant()
            {
                EventId    = eventId,
                OlympiadId = evt.OlympiadId,
                Name       = contestant,
                Score      = score,
                Rank       = rank,
                Absent     = false
            };

            context.Entrants.Add(newEntrant);
            context.SaveChanges();
        }
コード例 #2
0
        public void AddContestantWithScoreToEvent(int contestantId, int rank, string score, string tiebreak, int eventId)
        {
            var context          = DataEntitiesProvider.Provide();
            var existingEntrants = context.Entrants.Where(e => e.Mind_Sport_ID == contestantId && e.EventId == eventId).ToList();

            if (existingEntrants.Any())
            {
                return;                          // no need
            }
            var evt        = context.Events.First(x => x.EIN == eventId);
            var contestant = context.Contestants.First(x => x.Mind_Sport_ID == contestantId);

            var newEntrant = new Entrant()
            {
                EventId    = eventId,
                OlympiadId = evt.OlympiadId,
                Name       = contestant,
                Absent     = false,
                Rank       = rank,
                Score      = score,
                Tie_break  = tiebreak
            };

            context.Entrants.Add(newEntrant);
            context.SaveChanges();
        }
コード例 #3
0
        /// <summary>
        /// Reindex the events in this olympiad. Those with sessions get numbers in sequence, in
        /// order of start time. Those without (pentamind, non-events) get 0 and don't appear in
        /// event-type reports.
        /// </summary>
        /// <param name="olympiadId"></param>
        public void IndexEvents(int olympiadId)
        {
            var context = DataEntitiesProvider.Provide();
            var events  = context.Events.Where(x => x.OlympiadId == olympiadId && x.Event_Sess.Any())
                          .OrderBy(x => x.Event_Sess.Min(es => es.Date))
                          .ThenBy(x => x.Event_Sess.Min(es => es.Session1.StartTime))
                          .ThenBy(x => x.Code)
                          .ToList();

            var index = 1;

            foreach (var evt in events)
            {
                evt.Number = index;
                index++;
            }

            var nonevents = context.Events.Where(x => x.OlympiadId == olympiadId && !x.Event_Sess.Any());

            foreach (var evt in nonevents)
            {
                evt.Number = 0;
            }

            context.SaveChanges();
        }
コード例 #4
0
        public void UpdateContestant(ContestantVm model)
        {
            var context = DataEntitiesProvider.Provide();
            var c       = context.Contestants.SingleOrDefault(x => x.Mind_Sport_ID == model.ContestantId);

            if (c == null)
            {
                throw new ArgumentOutOfRangeException("Contestant ID " + model.ContestantId + " not recognised");
            }
            if (!context.Nationalities.Any(x => x.Name == model.Nationality))
            {
                throw new ArgumentOutOfRangeException("Nationality " + model.Nationality + " not recognised");
            }

            c.Title           = model.Title;
            c.Firstname       = model.Firstname;
            c.Initials        = model.Initials;
            c.Lastname        = model.Lastname;
            c.DateofBirth     = model.DateOfBirth;
            c.Male            = model.IsMale;
            c.OnlineNicknames = model.OnlineNicknames;
            c.BgaNickname     = model.BgaNickname;
            c.Nationality     = model.Nationality;
            c.Notes           = model.Notes;

            context.SaveChanges();
        }
コード例 #5
0
        public User GetUserForLogin(string username, string password)
        {
            var context = DataEntitiesProvider.Provide();
            var user    = context.Users.FirstOrDefault(x => x.Name == username);

            if (user == null)
            {
                return(null);
            }

            if (!VerifyPassword(context, user, password))
            {
                return(null);
            }

            // Log the login
            var login = new UserLogin()
            {
                LogInDate   = DateTime.UtcNow,
                User        = user,
                Application = "Website",
                Version     = Assembly.GetExecutingAssembly().GetName().Version.ToString()
            };

            user.UserLogins.Add(login);
            context.SaveChanges();
            return(user);
        }
コード例 #6
0
        public IEnumerable <NationalityVm> GetItems(int olympiadId)
        {
            var context = DataEntitiesProvider.Provide();
            var contIds = context.Entrants.Where(x => x.OlympiadId == olympiadId)
                          .Select(x => x.Mind_Sport_ID).Distinct().ToList();
            var conts = context.Contestants.Where(x => contIds.Contains(x.Mind_Sport_ID))
                        .ToList();

            var totals = conts.GroupBy(x => x.Nationality ?? "Other")
                         .ToDictionary(x => x.Key, x => x.Count());
            var males = conts.Where(x => x.Male).GroupBy(x => x.Nationality ?? "Other")
                        .ToDictionary(x => x.Key, x => x.Count());
            var females = conts.Where(x => !x.Male).GroupBy(x => x.Nationality ?? "Other")
                          .ToDictionary(x => x.Key, x => x.Count());

            foreach (var key in totals.Keys.OrderBy(x => x))
            {
                yield return new NationalityVm()
                       {
                           Nationality     = (string.IsNullOrEmpty(key) ? "Unknown" : key),
                           NumberOfMales   = males.ContainsKey(key) ? males[key] : 0,
                           NumberOfFemales = females.ContainsKey(key) ? females[key] : 0,
                           Total           = totals[key].ToString()
                       }
            }
            ;
        }
    }
コード例 #7
0
        private PentamindStandingsReportVm GetMetaStandings(int?year, string type, int pentaTotal, int pentaLong)
        {
            var context         = DataEntitiesProvider.Provide();
            var currentOlympiad = (year.HasValue)
                ? context.Olympiad_Infoes.Where(x => x.StartDate.HasValue && x.StartDate.Value.Year == year.Value).First()
                : context.Olympiad_Infoes.First(x => x.Current);

            var def = context.MetaGameDefinitions.First(x =>
                                                        x.Type == type && x.OlympiadId == currentOlympiad.Id);
            var codes = def.SubEvents.Split(',');

            var vm = new PentamindStandingsReportVm();

            vm.OlympiadTitle = currentOlympiad.FullTitle();
            vm.EventsNeeded  = pentaTotal;

            var longSessionEvents = currentOlympiad.Events.Where(x => x.No_Sessions > 1)
                                    .Select(x => x.Code)
                                    .ToList();

            var results = context.Entrants
                          .Where(x => x.OlympiadId == currentOlympiad.Id && !x.Absent && x.Rank.HasValue && x.Penta_Score.HasValue &&
                                 codes.Contains(x.Event.Code))
                          .Join(context.Contestants, e => e.Mind_Sport_ID, c => c.Mind_Sport_ID, (e, c) => new { e, c })
                          .GroupBy(x => x.c.Mind_Sport_ID)
                          .ToList();

            var calc = new EurogameMetaScoreCalculator();

            var standings = new List <PentamindStandingsReportVm.ContestantStanding>();

            foreach (var r in results)
            {
                var standing = new PentamindStandingsReportVm.ContestantStanding()
                {
                    ContestantId    = r.Key,
                    Name            = r.First().c.FullName(),
                    Nationality     = r.First().c.Nationality,
                    IsInWomensPenta = false // irrelevant for Modern Abstract
                };

                standing.Scores = r.Select(x => new PentamindStandingsReportVm.EventScore()
                {
                    Code             = x.e.Event.Code,
                    GameCode         = x.e.Event.Game.Code,
                    Score            = (double)x.e.Penta_Score,
                    IsLongSession    = true, // No long game rule in poker
                    IsEuroGame       = (x.e.Event.Game.GameCategory.Id == 3),
                    IsModernAbstract = (codes.Contains(x.e.Event.Code))
                }).ToList();

                standing.Scores     = calc.SelectBestScores(standing.Scores, pentaLong, pentaTotal, currentOlympiad.StartDate.Value.Year);
                standing.TotalScore = standing.Scores.Sum(x => x.Score);
                standing.IsValid    = (standing.Scores.Count() == pentaTotal);
                standings.Add(standing);
            }

            vm.Standings = standings.OrderByDescending(x => x.TotalScore);
            return(vm);
        }
コード例 #8
0
        private void copyEventsMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var context      = DataEntitiesProvider.Provide();
            var thisOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();

            if (thisOlympiad.Events.Any())
            {
                MessageBox.Show("You cannot do this if the current Olympiad already has events.");
                return;
            }

            var previousOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).Skip(1).First();

            this.Status.Text = "Copying from " + previousOlympiad.YearOf + " to " + thisOlympiad.YearOf;
            var dateShift = thisOlympiad.StartDate.Value.Subtract(previousOlympiad.StartDate.Value);

            foreach (var evt in previousOlympiad.Events)
            {
                var newE = evt.CopyTo(thisOlympiad);
                // This is a copy, so move the dates along by the same amount
                foreach (var es in newE.Event_Sess)
                {
                    es.Date = es.Date.Value.Add(dateShift);
                }
                thisOlympiad.Events.Add(newE);
            }

            context.SaveChanges();
            this.Status.Text = "";
        }
コード例 #9
0
        private void unpaidFee_Click(object sender, RoutedEventArgs e)
        {
            var context    = DataEntitiesProvider.Provide();
            var olympiadId = context.Olympiad_Infoes.First(x => x.Current).Id;

            var payments = context.Payments.Where(p => p.OlympiadId == olympiadId)
                           .GroupBy(x => x.MindSportsID)
                           .ToDictionary(x => x.Key, x => x.Sum(p => p.Payment1));
            var fees = context.Entrants.Where(p => p.OlympiadId == olympiadId)
                       .GroupBy(x => x.Mind_Sport_ID)
                       .ToDictionary(x => x.Key, x => x.Sum(p => p.Fee));
            var contestants = fees.Where(x => x.Value > 0 && // They have some fees - not complimentary
                                         (!payments.Keys.Contains(x.Key) || x.Value > payments[x.Key]))
                              .Select(x => x.Key);

            // Warning - can't do comparison inside SQL as Sum() can be NULL
            var names = context.Contestants.Where(x => contestants.Contains(x.Mind_Sport_ID))
                        .ToList()
                        .Select(x => x.FullName());

            if (names.Any())
            {
                MessageBox.Show("The following contestants have unpaid fees:"
                                + Environment.NewLine + string.Join(Environment.NewLine, names));
            }
            else
            {
                MessageBox.Show("There are no contestants with unpaid fees");
            }
        }
コード例 #10
0
        public IEnumerable <NationalityVm> GetItemsForLatest()
        {
            var context  = DataEntitiesProvider.Provide();
            var olympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();

            return(GetItems(olympiad.Id));
        }
コード例 #11
0
        public void PopulatePayments()
        {
            Payments.Clear();
            if (ContestantId == null)
            {
                return;
            }
            if (CurrentOlympiadId == null)
            {
                return;
            }

            var context      = DataEntitiesProvider.Provide();
            var olympiadId   = CurrentOlympiadId;
            var contestantId = int.Parse(ContestantId);
            var payments     = context.Payments.Where(x => x.OlympiadId == olympiadId && x.MindSportsID == contestantId)
                               .OrderBy(x => x.PaymentNumber).ToList();

            foreach (var p in payments)
            {
                Payments.Add(new PaymentVm()
                {
                    Amount    = p.Payment1.Value,
                    Banked    = (p.Banked.HasValue && p.Banked.Value == 1),
                    Method    = p.Payment_Method,
                    PaymentId = p.PaymentNumber
                });
            }
        }
コード例 #12
0
        public void PopulateDropdown()
        {
            Games.Clear();
            var context = DataEntitiesProvider.Provide();

            Categories.Clear();
            Categories.Add(new GameCategoryVm()
            {
                Id = 0, Name = "(No category)"
            });
            foreach (var c in context.GameCategories.Select(x => new GameCategoryVm {
                Id = x.Id, Name = x.NAME
            }))
            {
                Categories.Add(c);
            }

            Games.Add(new GameVm {
                Text = "New Game", Value = 0
            });
            foreach (var game in context.Games.OrderBy(x => x.Code))
            {
                Games.Add(new GameVm {
                    Text = game.Code + " : " + game.Mind_Sport, Value = game.Id
                });
            }
        }
コード例 #13
0
        public AddEventsToContestantWindowVm(int olympiadId, bool isConcession, IEnumerable <string> selectedEvents, IEnumerable <string> nonEditableCodes)
        {
            var context = DataEntitiesProvider.Provide();
            var allFees = context.Fees.ToList();
            var fees    = (isConcession)
                ? allFees.ToDictionary(x => x.Code, x => x.Concession)
                : allFees.ToDictionary(x => x.Code, x => x.Adult);

            Events = new ObservableCollection <EventVm>();
            foreach (var evt in context.Events
                     .Where(x => x.Code != null && x.Mind_Sport != null && x.OlympiadId == olympiadId)
                     .Select(x => new EventVm()
            {
                Id = x.EIN, Code = x.Code, Name = x.Mind_Sport, FeeCode = x.Entry_Fee,
                IsIncludedInMaxFee = (x.incMaxFee.HasValue && x.incMaxFee.Value),
                Event = x
            })
                     .ToList()
                     .Distinct(new EventVmCodeOnlyComparer())
                     .OrderBy(x => x.Code))
            {
                evt.IsSelected = (selectedEvents.Contains(evt.Code));
                evt.IsEnabled  = !(nonEditableCodes.Contains(evt.Code));
                evt.Fee        = (evt.FeeCode == null) ? 0.0m : (fees[evt.FeeCode] ?? 0.0m);
                Events.Add(evt);
            }
        }
コード例 #14
0
        public OlympiadEventsVm GetOlympiadEvents()
        {
            var context = DataEntitiesProvider.Provide();
            var vm      = new OlympiadEventsVm();

            var currentOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();
            var entryFees       = context.Fees.ToDictionary(x => x.Code, x => x);

            vm.OlympiadName          = currentOlympiad.FullTitle();
            vm.Year                  = currentOlympiad.YearOf.Value;
            vm.MaximumCost           = currentOlympiad.MaxFee.Value;
            vm.MaximumConcessionCost = currentOlympiad.MaxCon.Value;
            vm.Events                = currentOlympiad.Events
                                       .Where(x => x.No_Sessions > 0)
                                       .Select(e =>
                                               new OlympiadEventsVm.EventVm()
            {
                Code           = e.Code,
                Name           = e.Mind_Sport,
                Cost           = entryFees[e.Entry_Fee].Adult.Value,
                ConcessionCost = entryFees[e.Entry_Fee].Concession.Value
            }).ToList();

            return(vm);
        }
コード例 #15
0
        public PeopleOwingMoneyReportVm GetItemsForLatest()
        {
            var vm = new PeopleOwingMoneyReportVm();

            var context         = DataEntitiesProvider.Provide();
            var currentOlympiad = context.Olympiad_Infoes.First(x => x.Current);

            var payments = context.Payments.Where(p => p.OlympiadId == currentOlympiad.Id)
                           .GroupBy(x => x.MindSportsID)
                           .ToDictionary(x => x.Key, x => x.Sum(p => p.Payment1));
            var fees = context.Entrants.Where(p => p.OlympiadId == currentOlympiad.Id)
                       .GroupBy(x => x.Mind_Sport_ID)
                       .ToDictionary(x => x.Key, x => x.Sum(p => p.Fee));
            var contestants = fees.Where(x => !payments.Keys.Contains(x.Key) || x.Value > payments[x.Key])
                              .Select(x => x.Key);

            // Warning - can't do comparison inside SQL as Sum() can be NULL
            vm.OlympiadName = currentOlympiad.FullTitle();
            vm.Fees         = context.Contestants.Where(x => contestants.Contains(x.Mind_Sport_ID))
                              .OrderBy(x => x.Lastname)
                              .ThenBy(x => x.Firstname)
                              .ToList()
                              .Select(x => new PeopleOwingMoneyReportVm.AmountVm()
            {
                Name = x.FullName(),
                Owed = fees[x.Mind_Sport_ID],
                Paid = (payments.Keys.Contains(x.Mind_Sport_ID) ? payments[x.Mind_Sport_ID].Value : 0m)
            });

            return(vm);
        }
コード例 #16
0
        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            using (new SpinnyCursor())
            {
                // this is not good - should pass all stuff out of dialog and
                DataEntitiesProvider.IsProduction = !testData.IsChecked.Value;

                var context = DataEntitiesProvider.Provide();
                var user    = context.Users.FirstOrDefault(x => x.Name == usernameBox.Text);
                if (user != null && VerifyPassword(context, user, passwordBox.Password))
                {
                    UserId   = user.PIN;
                    UserName = user.Name;
                    var login = new UserLogin()
                    {
                        LogInDate   = DateTime.UtcNow,
                        User        = user,
                        Application = Assembly.GetExecutingAssembly().GetName().Name,
                        Version     = Assembly.GetExecutingAssembly().GetName().Version.ToString()
                    };
                    user.UserLogins.Add(login);
                    context.SaveChanges();
                    UserLoginId = login.Id;
                    UseTestData = testData.IsChecked.Value;
                }
                else
                {
                    UserId   = 0;
                    UserName = "";
                }

                this.DialogResult = true;
                this.Close();
            }
        }
コード例 #17
0
        public SwissManagerEventContestantsVm GetSwissManagerEventContestants(string eventCode)
        {
            var context = DataEntitiesProvider.Provide();
            var vm      = new SwissManagerEventContestantsVm();

            var currentOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();
            var evt             = currentOlympiad.Events.SingleOrDefault(x => x.Code == eventCode);

            if (evt == null)
            {
                throw new ArgumentOutOfRangeException("Unrecognised event");
            }

            int i = 1;

            vm.AddRange(evt.Entrants.Select(e =>
                                            new SwissManagerEventContestantsVm.ContestantVm()
            {
                NatId          = e.Name.Mind_Sport_ID,
                Firstname      = e.Name.Firstname,
                Lastname       = e.Name.Lastname,
                PlayerUniqueId = i++
            }).ToList());

            return(vm);
        }
コード例 #18
0
        public void Populate()
        {
            Events.Clear();

            var context         = DataEntitiesProvider.Provide();
            var currentOlympiad = context.Olympiad_Infoes.First(x => x.Current);
            var events          = context.Events.Include("Entrants").Include("Event_Sess")
                                  .Where(x => x.OlympiadId == currentOlympiad.Id && x.Number > 0);

            foreach (var evt in events.OrderBy(x => x.Number).ToList())
            {
                Events.Add(new EventVm()
                {
                    Name  = evt.ShortName(),
                    Code  = evt.Code,
                    Id    = evt.Number,
                    Dates = (evt.Start.HasValue) ? evt.Start.Value.ToString("ddd dd MMM HH:mm") + " - " +
                            evt.End.Value.ToString("HH:mm")
                        : "Dates unknown",
                    NumCompetitors = evt.Entrants.Count(x => !x.Absent).ToString(),
                    FractionDone   = evt.FractionDone(),
                    Status         = evt.Status(),
                    IsVisible      = ((evt.Status() != "Complete") || (DateTime.Now.Subtract(evt.End.Value).TotalHours < 1))
                });
            }

            ProgressMaximum = Events.Count();
            ProgressValue   = Events.Sum(x => x.FractionDone);
        }
コード例 #19
0
        private string GetMessageBody()
        {
            var           context         = DataEntitiesProvider.Provide();
            var           currentOlympiad = context.Olympiad_Infoes.First(x => x.Current).Id;
            var           me   = context.Contestants.First(x => x.Firstname == "Julia" && x.Lastname == "Hayward");
            StringBuilder body = new StringBuilder();

            body.Append("Your events today:\r\n");
            foreach (var e in me.Entrants.Where(x =>
                                                x.Event.Start > DateTime.Now && x.Event.Start < DateTime.Now.AddHours(24)))
            {
                body.Append(e.Event.Code + "\r\n");
            }

            body.Append("Coming up:\r\n");
            foreach (var e in me.Entrants.Where(x =>
                                                x.Event.Start >= DateTime.Now.AddHours(24)))
            {
                body.Append(e.Event.Code + "\r\n");
            }

            body.Append("Your Pentamind scores:\r\n");
            foreach (var e in me.Entrants.Where(x => x.OlympiadId.Value == currentOlympiad && x.Penta_Score != null))
            {
                body.Append(e.Event.Code + " got penta points: " + e.Penta_Score + "\r\n");
            }

            return(body.ToString());
        }
コード例 #20
0
        public ContestantPanelVm()
        {
            Contestants     = new ObservableCollection <ContestantVm>();
            Olympiads       = new ObservableCollection <OlympiadVm>();
            Events          = new ObservableCollection <EventVm>();
            Payments        = new ObservableCollection <PaymentVm>();
            ContestantId    = "0";
            FilterFirstName = "";
            FilterLastName  = "";

            Titles = new ObservableCollection <TitleVm>();
            Titles.Add(new TitleVm()
            {
                Text = "Mr", Value = "Mr"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Mrs", Value = "Mrs"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Ms", Value = "Ms"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Miss", Value = "Miss"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Master", Value = "Master"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Dr", Value = "Dr"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Prof", Value = "Prof"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Sir", Value = "Sir"
            });
            Titles.Add(new TitleVm()
            {
                Text = "Lady", Value = "Lady"
            });

            if (Nationalities == null)
            {
                Nationalities = new ObservableCollection <NationalityVm>();
                var context = DataEntitiesProvider.Provide();
                context.Nationalities.Select(x => x.Name).ToList()
                .ForEach(n => Nationalities.Add(new NationalityVm(n)));
            }

            PopulateOlympiadDropdown();
            PopulateEvents();
            PopulatePayments();
        }
コード例 #21
0
        public void Print(string EventCode)
        {
            var context         = DataEntitiesProvider.Provide();
            var currentOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();
            var juniorDate      = DateTime.Now.AddYears(-currentOlympiad.JnrAge.Value - 1);

            var evt = context.Events.First(x => x.OlympiadId == currentOlympiad.Id && x.Code == EventCode);

            var seedings = context.Seedings.Where(x => x.EventCode == evt.Code)
                           .ToDictionary(x => x.ContestantId, x => x.Rank.Value);

            var entrants = context.Entrants.Where(x => x.OlympiadId == currentOlympiad.Id && x.Game_Code == EventCode)
                           .OrderBy(x => x.Name.Lastname)
                           .ThenBy(x => x.Name.Firstname);


            PrintDialog dlg = new PrintDialog();

            if ((bool)dlg.ShowDialog().GetValueOrDefault())
            {
                FlowDocument doc = new FlowDocument();
                doc.ColumnWidth = 200; // 96ths of an inch
                doc.FontFamily  = new FontFamily("Verdana");

                AddEventToDoc(EventCode, currentOlympiad, evt, entrants, seedings, juniorDate, doc, true);

                DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;
                dlg.PrintDocument(paginator, "Event Entries " + EventCode);
            }
        }
コード例 #22
0
        public void FreezeBackgammon()
        {
            var context                     = DataEntitiesProvider.Provide();
            var currentOlympiad             = context.Olympiad_Infoes.First(x => x.Current);
            var pentamindStandingsGenerator = new PentamindStandingsGenerator();

            // Next a Modern Abstract one
            var modernAbstractStandings = pentamindStandingsGenerator.GetBackgammonStandings(null);
            int rank = 1;

            foreach (var standing in modernAbstractStandings.Standings)
            {
                if (!standing.IsValid)
                {
                    continue;
                }

                var contestant = context.Contestants.FirstOrDefault(x => x.Mind_Sport_ID == standing.ContestantId);
                var evt        = context.Events.FirstOrDefault(x => x.OlympiadId == currentOlympiad.Id && x.Code == "BACC");
                var entry      = context.Entrants.FirstOrDefault(x => x.OlympiadId == currentOlympiad.Id &&
                                                                 x.Game_Code == "BACC" && x.Mind_Sport_ID == standing.ContestantId);
                if (entry == null)
                {
                    entry = Entrant.NewEntrant(evt.EIN, "BACC", currentOlympiad.Id, contestant, 0m);
                    context.Entrants.Add(entry);
                }
                entry.Score = standing.TotalScoreStr;
                entry.Rank  = rank;
                entry.Medal = MedalForRank(rank);
                rank++;
                context.SaveChanges();
            }
        }
コード例 #23
0
        public AddSessionToEventVm(IEnumerable <string> selectedSessions)
        {
            Sessions = new ObservableCollection <SessionVm>();
            Dates    = new ObservableCollection <DateVm>();

            var context         = DataEntitiesProvider.Provide();
            var currentOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();

            for (var date = currentOlympiad.StartDate.Value; date <= currentOlympiad.FinishDate.Value; date = date.AddDays(1))
            {
                Dates.Add(new DateVm()
                {
                    Date = date
                });
            }
            SelectedDate = Dates.First().Date;

            foreach (var s in context.Sessions
                     .Where(x => x.IsActive)
                     .Select(x => new SessionVm()
            {
                Code = x.Session1, Start = x.StartTime.Value, End = x.FinishTime.Value,
                Worth = (int)x.Worth.Value
            })
                     .ToList()
                     .OrderBy(x => x.Start))
            {
                s.IsSelected = (selectedSessions.Contains(s.Code));
                Sessions.Add(s);
            }
        }
コード例 #24
0
        public EventResultsVm GetEntrantsModel(string eventCode)
        {
            var context = DataEntitiesProvider.Provide();

            var olympiad = context.Olympiad_Infoes.FirstOrDefault(x => x.Current);

            if (olympiad == null)
            {
                throw new ArgumentOutOfRangeException("No current olympiad");
            }

            var retval = new EventResultsVm {
                Year = olympiad.YearOf.Value, EventCode = eventCode, OlympiadName = olympiad.FullTitle()
            };

            var evt = context.Events.FirstOrDefault(x => x.OlympiadId == olympiad.Id && x.Code == eventCode);

            if (evt == null)
            {
                throw new ArgumentOutOfRangeException("Unknown event code " + eventCode);
            }

            retval.EventName = evt.Mind_Sport;
            retval.Entrants  = evt.Entrants
                               .Select(e => new EventResultsVm.EntrantVm()
            {
                ContestantId = e.Name.Mind_Sport_ID,
                Name         = e.Name.FullName(),
                Nationality  = e.Name.Nationality ?? "default",
            })
                               .ToList()
                               .OrderBy(x => x.Name);

            return(retval);
        }
コード例 #25
0
        public void PopulateGame()
        {
            var id = GameId;

            if (id == 0)
            {
                Name       = "";
                Code       = "";
                Contacts   = "";
                Equipment  = "";
                Rules      = "";
                CategoryId = 0;
            }
            else
            {
                var context = DataEntitiesProvider.Provide();
                var dbGame  = context.Games.FirstOrDefault(x => x.Id == id);
                Name       = dbGame.Mind_Sport;
                Code       = dbGame.Code;
                Contacts   = dbGame.Contacts;
                Equipment  = dbGame.Equipment;
                Rules      = dbGame.Rules;
                CategoryId = dbGame.CategoryId;
            }
            IsDirty = false;
        }
コード例 #26
0
        // Warning - this will go wonky in 2007 when I undo the 7002 hack
        public EventEntrantsVm GetModel(int?year, string gameCode)
        {
            var vm      = new EventEntrantsVm();
            var context = DataEntitiesProvider.Provide();

            var olympiad = (year.HasValue)
                ? context.Olympiad_Infoes.FirstOrDefault(x => x.YearOf == year.Value)
                : context.Olympiad_Infoes.First(x => x.Current);

            if (olympiad == null)
            {
                var message = (year.HasValue) ? "No Olympiad for year " + year.Value : "No current Olympiad";
                throw new ArgumentOutOfRangeException(message);
            }

            vm.EventYear = olympiad.YearOf.Value;

            var evt = context.Events.First(x => x.OlympiadId == olympiad.Id && x.Code == gameCode);

            vm.EventName = evt.Mind_Sport;
            vm.Entrants  = evt.Entrants
                           .Select(x => new EventEntrantsVm.EntrantVm()
            {
                Name = x.Name.FullName()
            })
                           .OrderBy(x => x.Name);
            return(vm);
        }
コード例 #27
0
        public EventEntriesReportPickerVm()
        {
            UseEvent = true;
            Events   = new ObservableCollection <EventVm>();
            Dates    = new ObservableCollection <DateVm>();

            var context         = DataEntitiesProvider.Provide();
            var currentOlympiad = context.Olympiad_Infoes.OrderByDescending(x => x.StartDate).First();

            foreach (var evt in context.Events
                     .Where(x => x.Code != null && x.Mind_Sport != null && x.OlympiadId == currentOlympiad.Id)
                     .Select(x => new EventVm()
            {
                Id = x.EIN, Code = x.Code, Name = x.Mind_Sport
            })
                     .ToList()
                     .OrderBy(x => x.Code))
            {
                Events.Add(evt);
            }
            for (var date = currentOlympiad.StartDate.Value; date <= currentOlympiad.FinishDate.Value; date = date.AddDays(1))
            {
                Dates.Add(new DateVm()
                {
                    Date = date
                });
            }

            SelectedEventCode = Events.First().Code;
            SelectedFromDate  = Dates.First().Date;
            SelectedToDate    = Dates.First().Date;
        }
コード例 #28
0
        public MedalTableVm GetItems(int page, int pageSize)
        {
            var medals = new[] { "Gold", "Silver", "Bronze" };

            var context = DataEntitiesProvider.Provide();
            var entries = context.Entrants.Join(context.Contestants, e => e.Mind_Sport_ID, c => c.Mind_Sport_ID, (e, c) => new { e, c })
                          .Where(x => medals.Contains(x.e.Medal))
                          .ToList()
                          .GroupBy(x => x.e.Mind_Sport_ID.Value, x => x)
                          .ToList()
                          .Select(x => new MedalTableVm.MedalTableEntryVm
            {
                ContestantId = x.Key,
                Golds        = x.Count(ec => ec.e.Medal == "Gold"),
                Silvers      = x.Count(ec => ec.e.Medal == "Silver"),
                Bronzes      = x.Count(ec => ec.e.Medal == "Bronze"),
                FirstName    = x.First().c.Firstname,
                LastName     = x.First().c.Lastname,
                Nationality  = x.First().c.Nationality ?? "default"
            })
                          .ToList()
                          .OrderByDescending(m => m.Golds).ThenByDescending(x => x.Silvers).ThenByDescending(x => x.Bronzes);

            return(new MedalTableVm()
            {
                Entries = entries.Skip((page - 1) * pageSize).Take(pageSize),
                FirstIndex = 1 + (page - 1) * pageSize,
                HasNext = (entries.Count() > page * pageSize),
                HasPrevious = (page > 1),
                Page = page
            });
        }
コード例 #29
0
        public IEnumerable <MedalTableVm> GetItemsForLatest()
        {
            var context  = DataEntitiesProvider.Provide();
            var olympiad = context.Olympiad_Infoes.Single(x => x.Current);

            return(GetItems(olympiad.Id));
        }
コード例 #30
0
        public GameMedalsVm GetModel(string gameCode)
        {
            var context = DataEntitiesProvider.Provide();

            var game = context.Games.FirstOrDefault(x => x.Code == gameCode);

            if (game == null)
            {
                throw new ArgumentException("Game code " + (gameCode ?? "(null)") + " not recognised");
            }

            var retval = new GameMedalsVm {
                GameName = game.Mind_Sport
            };

            retval.Medals = context.Entrants
                            .Where(x => x.Event.Game.Code == gameCode && (x.Medal != null || x.JuniorMedal != null))
                            .Join(context.Contestants, e => e.Mind_Sport_ID, c => c.Mind_Sport_ID, (e, c) => new { e, c })
                            .Select(ecv => new GameMedalsVm.MedalVm()
            {
                Year         = ecv.e.Event.Olympiad_Info.YearOf.Value,
                EventCode    = ecv.e.Event.Code,
                EventName    = ecv.e.Event.Mind_Sport,
                Medal        = ecv.e.Medal ?? ecv.e.JuniorMedal,
                ContestantId = ecv.c.Mind_Sport_ID,
                FirstName    = ecv.c.Firstname,
                LastName     = ecv.c.Lastname,
                Nationality  = ecv.c.Nationality ?? "default"
            })
                            .ToList()
                            .Where(x => x.Year < 7002)
                            .OrderByDescending(x => x.Year).ThenBy(x => x.EventCode).ThenBy(x => x.Rank).ThenBy(x => x.Medal.MedalRank());

            var titleLookup = retval.Medals.GroupBy(x => new { x.EventCode, x.ContestantId, x.Name });

            foreach (var possibleTitle in titleLookup)
            {
                var golds   = possibleTitle.Count(x => x.Medal == "Gold");
                var silvers = possibleTitle.Count(x => x.Medal == "Silver");
                var bronzes = possibleTitle.Count(x => x.Medal == "Bronze");
                if (golds >= 2 || (golds == 1 && silvers >= 2))
                {
                    retval.Titles.Grandmasters.Add(possibleTitle.Key.Name);
                }
                else if ((golds == 1 && silvers + bronzes > 0) ||
                         silvers >= 2 ||
                         (silvers == 1 && bronzes >= 2))
                {
                    retval.Titles.Masters.Add(possibleTitle.Key.Name);
                }
                else if ((silvers == 1 && bronzes > 0) ||
                         bronzes >= 2)
                {
                    retval.Titles.CandidateMasters.Add(possibleTitle.Key.Name);
                }
            }

            return(retval);
        }