/// <summary>
 /// Initializes commands.
 /// </summary>
 private void InitializeCommands()
 {
     EditEventCommand            = new RelayCommand(EditEvent);
     CompleteEventCommand        = new RelayCommand(CompleteEvent);
     CheckTaskCommand            = new RelayParamCommand <Task>(CheckTaskEvent);
     IncreaseSelectedTaskCommand = new RelayCommand(IncreaseSelectedTaskEvent);
     DecreaseSelectedTaskCommand = new RelayCommand(DecreaseSelectedTaskEvent);
     UpdateEventCommand          = new RelayCommand(UpdateEvent);
 }
Exemple #2
0
        public HistoryViewModel()
        {
            using (var context = new EventDatabaseEntities())
            {
                int CurrentIndex = 0;
                // Get every date when was an event.
                var dates = context.Events.Where(x => DbFunctions.TruncateTime(x.Date) < DateTime.Today)
                            .GroupBy(r => DbFunctions.TruncateTime(r.Date)).OrderByDescending(x => x.Key).ToList();

                // Set the date indicators.
                ToDate   = dates.ElementAt(0).Key.ToString();
                FromDate = dates.ElementAt(dates.Count() - 1).Key.ToString();

                foreach (var events in dates)
                {
                    // Every event that happend at this day.
                    var Events = context.Events.Where(x => DbFunctions.TruncateTime(x.Date) == events.Key).ToList();

                    // Add the date to the list.
                    HistoryList.Add(new HistoryModel()
                    {
                        EventDate = (DateTime)events.Key
                    });

                    // Get the tasks for the events if there any.
                    foreach (var task in Events)
                    {
                        var tasks = context.Tasks.Where(x => x.EventID == task.ID).ToList();
                        HistoryList.ElementAt(CurrentIndex).EventList.Add(new HistoryListModel(task, tasks));
                    }

                    CurrentIndex++;
                }
            }

            DateFilterCommand  = new RelayCommand(DateFilterEvent);
            DeleteEventCommand = new RelayParamCommand <Event>(DeleteEvent);
            CloseEventCommand  = new RelayCommand(CloseEvent);
        }