public MainGroups()
        {
            InitializeComponent();
            var  vm          = new MainAppViewModel();
            User currentUser = AuthenticationManager.GetCurrentUser();

            using (var context = new ExpansesManagerContext())
            {
                var groups = context.Groups.Where(c => c.UserId == currentUser.Id);
                var list   = new List <StatisticsViewModel>();

                foreach (var gr in groups)
                {
                    foreach (var item in gr.SubGroups)
                    {
                        list.Add(new StatisticsViewModel()
                        {
                            GroupName          = gr.Name,
                            SubGroupName       = item.Name,
                            TotalSubGroupPrice = item.Elements.Sum(e => e.Price),
                            DayPrice           = item.Elements.Where(e => e.DateBought.Date == DateTime.Today.Date).Sum(e => e.Price),
                            WeekPrice          = item.Elements.Where(e => e.DateBought <= DateTime.Today.AddDays(-7) && e.DateBought <= DateTime.Today).Sum(e => e.Price),
                            MonthPrice         = item.Elements.Where(e => e.DateBought <= DateTime.Today.AddMonths(-1) && e.DateBought <= DateTime.Today).Sum(e => e.Price),
                            YearPrice          = item.Elements.Where(e => e.DateBought.Year <= DateTime.Today.AddYears(-1).Year&& e.DateBought.Date <= DateTime.Today.Date).Sum(e => e.Price),
                        });
                    }
                }
                this.lvUsers.ItemsSource = list;
            }
        }
        public EditModeMainApp()
        {
            InitializeComponent();

            var  vm          = new MainAppViewModel();
            User currentUser = AuthenticationManager.GetCurrentUser();

            using (var contex = new ExpansesManagerContext())
            {
                textBox.Text = "Welcome " + " " + currentUser.Username;
                var user = contex.Users.Find(currentUser.Id);
                vm.Groups = new ObservableCollection <GroupViewModel>(Mapper.Instance.Map <IEnumerable <Group>, ObservableCollection <GroupViewModel> >(user.Groups));
                this.GroupsGrid.DataContext = vm;
                this.GroupsGrid.ItemsSource = vm.Groups;
            }
        }
Пример #3
0
        public MainApp()
        {
            InitializeComponent();
            var  vm          = new MainAppViewModel();
            User currentUser = AuthenticationManager.GetCurrentUser();

            using (var contex = new ExpansesManagerContext())
            {
                var user = contex.Users.Find(currentUser.Id);
                vm.Groups = new ObservableCollection <GroupViewModel>(Mapper.Instance.Map <IEnumerable <Group>, ObservableCollection <GroupViewModel> >(user.Groups));

                foreach (var group in contex.Groups.Where(g => g.IsActive == true))
                {
                    TreeViewGroups.Items.Add(group.Name);
                }
            }
        }