aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/JobsViewVM.cs
blob: 0eb59eeebdd45a79d5656d91db47ea46839d6562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.PPC.Common;
using Tango.PPC.Common.Application;
using Tango.PPC.Common.Authentication;
using Tango.PPC.Common.Navigation;
using Tango.PPC.Common.Notifications;
using Tango.Settings;
using Tango.SharedUI;

namespace Tango.PPC.UI.ViewModels
{
    public class JobsViewVM : PPCViewModel
    {
        private ObservablesContext _jobsContext;

        private ObservableCollection<Job> _jobs;

        public ObservableCollection<Job> Jobs
        {
            get { return _jobs; }
            set { _jobs = value; RaisePropertyChangedAuto(); }
        }

        public JobsViewVM(IPPCApplicationManager application, IAuthenticationProvider authentication, INavigationManager navigation, INotificationProvider notification) : base(application, authentication, navigation, notification)
        {
            Jobs = new ObservableCollection<Job>();
        }

        public override void OnApplicationStarted()
        {
            LoadJobs();
        }

        private void LoadJobs()
        {
            Task.Factory.StartNew(() =>
            {
                if (_jobsContext != null)
                {
                    _jobsContext.Dispose();
                }

                _jobsContext = ObservablesContext.CreateDefault();
                Jobs = _jobsContext.Jobs.Where(x => x.Machine.SerialNumber == Settings.MachineSerialNumber).ToObservableCollection();
            });
        }
    }
}