예제 #1
0
        public MainPage()
        {
            this.InitializeComponent();

            var entriesView = entries.CreateView(
                x => new
            {
                Source      = x,
                Description = x.Description,
                Points      = x.Points,
                Date        = x.Date.ToString("dd MMM"),
            },
                x => x.Source
                );

            HistoryItems.ItemsSource  = entriesView;
            TemplateItems.ItemsSource = templates;
            BountyItems.ItemsSource   = bounties;

            TotalScore.DataContext      = entries.DeriveObservableProperty(es => es.Sum(e => e.Points));
            TotalScoreToday.DataContext = entries.DeriveObservableProperty(es =>
                                                                           es.Where(e => e.Date.Date.Equals(DateTime.Now.Date))
                                                                           .Sum(e => e.Points));

            AddTemplateStream.Subscribe(x =>
            {
                templates.Add(x);
                NewTemplateDescription.Text = String.Empty;
                NewTemplatePoints.Text      = "0";
            });
            DeleteTemplateStream.Subscribe(template => templates.Remove(template));
            AddEntryStream.Subscribe(x =>
            {
                entries.Add(x);
                NewEntryDescription.Text = String.Empty;
                NewEntryPoints.Text      = "0";
            });

            DeleteEntryStream.Subscribe(x => entries.Remove(x));

            AddBountyStream.Subscribe(bounty =>
            {
                bounties.Add(bounty);
                NewBountyDescription.Text = String.Empty;
                NewBountyPoints.Text      = "0";
            });
            CompleteBountyStream.Subscribe(bounty =>
            {
                entries.Add(new Entry
                {
                    Points      = bounty.Points,
                    Description = bounty.Description,
                });
                bounties.Remove(bounty);
            });
            DeleteBountyStream.Subscribe(bounty => bounties.Remove(bounty));
        }