コード例 #1
0
        public void UpdateRating(int winnerId, int loserId)
        {
            var ids = new[] { winnerId, loserId };

            var winner = _repository.Images.Untracked
                         .Where(x => x.Id == winnerId)
                         .Select(x => new { Image = x, Wins = x.Wins.Count, Losses = x.Losses.Count })
                         .Single();

            var loser = _repository.Images.Untracked
                        .Where(x => x.Id == loserId)
                        .Select(x => new { Image = x, Wins = x.Wins.Count, Losses = x.Losses.Count })
                        .Single();

            winner.Image.Rating = _rating.GetRating(winner.Wins + 1, winner.Losses);
            winner.Image.Sort   = _sort.GetSortValue(winner.Wins + 1, winner.Losses);

            loser.Image.Rating = _rating.GetRating(winner.Wins, winner.Losses + 1);
            loser.Image.Sort   = _sort.GetSortValue(winner.Wins, winner.Losses + 1);

            _repository.Ratings.Insert(new Rating
            {
                Added    = DateTime.Now,
                WinnerId = winner.Image.Id,
                LoserId  = loser.Image.Id
            });

            _repository.Images.Update(new[] { winner.Image, loser.Image });
        }
コード例 #2
0
        public AddEditStudentWindow(Student student, IRatingCalculator calculator)
        {
            InitializeComponent();
            _calculator = calculator;

            if (student != null)
            {
                Title                      = "Edit student";
                textBoxName.Text           = student.Name;
                dataGridGrades.ItemsSource = student.Grades;
                textBlockRating.Text       = $"Rating: {_calculator.GetRating(student)}";
            }
            else
            {
                Title = "Add course";
            }
            textBoxName.Focus();
            Student = student;
        }