PageRenderTime 82ms CodeModel.GetById 41ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/TimeSheetReporting/TimeSheetReporting/Views/Home.xaml.cs

#
C# | 83 lines | 72 code | 10 blank | 1 comment | 3 complexity | dab820c2814be89a70a867d9fb69525f MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Net;
 5using System.Windows;
 6using System.Windows.Controls;
 7using System.Windows.Documents;
 8using System.Windows.Input;
 9using System.Windows.Media;
10using System.Windows.Media.Animation;
11using System.Windows.Navigation;
12using System.Windows.Shapes;
13using TimeSheetReporting.Web.Service;
14using TimeSheetReporting.Helper;
15using TimeSheetReporting.Web.Model;
16
17namespace TimeSheetReporting
18{
19    public partial class Home : Page
20    {
21        TimeSheetContext _dc;
22        public Home()
23        {
24            InitializeComponent();
25            gridEfforts.Loaded += new RoutedEventHandler(gridEfforts_Loaded);
26        }
27
28        void gridEfforts_Loaded(object sender, RoutedEventArgs e)
29        {
30            _dc = new TimeSheetContext();
31            gridEfforts.ItemsSource = _dc.Efforts;
32
33            MemberListProvider memberListProvider = LayoutRoot.Resources["memberListProvider"] as MemberListProvider;
34            ProjectListProvider projectListProvider = LayoutRoot.Resources["projectListProvider"] as ProjectListProvider;
35
36            memberListProvider.DomainContext = _dc;
37            projectListProvider.DomainContext = _dc;
38
39            _dc.Load<Effort>(_dc.GetEffortQuery());
40        }
41
42        // Executes when the user navigates to this page.
43        protected override void OnNavigatedTo(NavigationEventArgs e)
44        {
45        }
46
47        private void BtnAdd_Click(object sender, RoutedEventArgs e)
48        {
49            Effort lastAddedEffort;
50            if (_dc.Efforts.Count > 0)
51            {
52                lastAddedEffort = _dc.Efforts.ElementAt(_dc.Efforts.Count - 1);
53            }
54            else
55            {
56                lastAddedEffort = new Effort()
57                    {
58                        Date = DateTime.Today.Date
59                    };
60            }
61
62            _dc.Efforts.Add(new Effort()
63                {
64                    Date = lastAddedEffort.Date,
65                    Member = lastAddedEffort.Member,
66                    Project = lastAddedEffort.Project,
67                });
68        }
69
70        private void BtnDelete_Click(object sender, RoutedEventArgs e)
71        {
72            if (gridEfforts.SelectedItem != null)
73            {
74                _dc.Efforts.Remove(gridEfforts.SelectedItem as Effort);
75            }
76        }
77
78        private void BtnSave_Click(object sender, RoutedEventArgs e)
79        {
80            _dc.SubmitChanges();
81        }
82    }
83}