예제 #1
0
        public void AddAction(Guid actionId)
        {
            using (var itemModel = new DailyListContext())
            {
                var actionToAdd =
                    itemModel.DailyListItemActions
                    .Include(i => i.DailyListItem)
                    .SingleOrDefault(i => i.DailyListItemActionId == actionId);

                if (actionToAdd != null)
                {
                    Actions.Add(new ActionViewModel(actionToAdd, Context));
                }
            }
        }
예제 #2
0
        private void StopThisItem()
        {
            var actionToRaise = RaiseNewAction(DailyListItemActionType.Stop);

            using (var itemModel = new DailyListContext())
            {
                _ItemToDisplay.Actions.Add(actionToRaise);
                _ItemToDisplay.IsRunning = false;
                itemModel.Entry(_ItemToDisplay).State = EntityState.Modified;
                itemModel.SaveChanges();
            }

            OnActionAdded(actionToRaise);

            OnPropertyChanged(() => IsRunning);
            OnPropertyChanged(() => RunningTime);
        }
예제 #3
0
        private void StartThisItem()
        {
            // Mark this item as IsRunning.
            // Create a new Action Item Action for the start event.
            // Raise event to get the action added to the daily timeline
            var actionToRaise = RaiseNewAction(DailyListItemActionType.Start);

            using (var itemModel = new DailyListContext())
            {
                _ItemToDisplay.Actions.Add(actionToRaise);
                _ItemToDisplay.IsRunning = true;

                itemModel.Entry(_ItemToDisplay).State = EntityState.Modified;
                itemModel.SaveChanges();
            }

            OnActionAdded(actionToRaise);

            OnPropertyChanged(() => IsRunning);
            OnPropertyChanged(() => RunningTime);
        }
예제 #4
0
        private DailyListItemAction RaiseNewAction(DailyListItemActionType type, string noteText = null)
        {
            DailyListItemAction actionToRaise = null;

            using (var itemModel = new DailyListContext())
            {
                actionToRaise = itemModel.DailyListItemActions.Create();

                actionToRaise.DailyListItemActionId = Guid.NewGuid();
                actionToRaise.DailyListItemId = _ItemToDisplay.DailyListItemId;
                actionToRaise.Type = type;
                actionToRaise.Time = SystemClock.Instance.Now;
                actionToRaise.Text = noteText;

                itemModel.DailyListItemActions.Add(actionToRaise);
                itemModel.SaveChanges();
            }

            actionToRaise.DailyListItem = _ItemToDisplay;

            return actionToRaise;
        }
예제 #5
0
        private void CompleteThisItem()
        {
            var actionToRaise = RaiseNewAction(DailyListItemActionType.Complete);

            using (var itemModel = new DailyListContext())
            {
                _ItemToDisplay.Actions.Add(actionToRaise);
                _ItemToDisplay.IsRunning = false;
                _ItemToDisplay.IsComplete = true;
                _ItemToDisplay.CompletedTime = SystemClock.Instance.Now;
                itemModel.Entry(_ItemToDisplay).State = EntityState.Modified;
                itemModel.SaveChanges();
            }

            OnActionAdded(actionToRaise);

            OnPropertyChanged(() => IsRunning);
            OnPropertyChanged(() => IsComplete);
            OnPropertyChanged(() => RunningTime);
            OnPropertyChanged(() => TotalTime);
            OnPropertyChanged(() => CompletedTime);
        }
        public void AddNewItem(string itemText, bool startItemToo)
        {
            DailyListItem newListItem = null;

            using (var itemModel = new DailyListContext())
            {
                newListItem = itemModel.DailyListItems.Create();

                newListItem.DailyListItemId = Guid.NewGuid();
                newListItem.CreatedTime = SystemClock.Instance.Now;
                newListItem.ItemText = itemText;

                itemModel.DailyListItems.Add(newListItem);

                itemModel.SaveChanges();
            }

            var newItemVm = new DailyListItemViewModel(newListItem, Context);

            newItemVm.ActionAdded += ActionItemActionAdded;

            ItemsToDisplay.Add(newItemVm);

            if (startItemToo)
            {
                newItemVm.StartItem.Execute(null);
            }
        }
        // TODO Get Items by Date
        // TODO Get Items by ID
        // TODO Get Items by QUERY?
        public void ShowItemsForPeriod(DailyListTimePeriod periodToRetrieve)
        {
            ItemsToDisplay = new ObservableCollection<DailyListItemViewModel>();

            using (var itemModel = new DailyListContext())
            {
                //var now = SystemClock.Instance.Now;
                //var dayNumber = now.InUtc().Day;

                //// Get all items for today
                //var currentItems = itemModel.DailyListItems
                //    .Where(i => i.CreatedDateTimeUtc.Day == dayNumber)
                //    .OrderByDescending(i => i.CreatedDateTimeUtc)
                //    .Include(i => i.Actions)
                //    .ToList();

                // TODO Stop ignoring the time period...
                // Get all items...
                var currentItems = itemModel.DailyListItems
                    .OrderByDescending(i => i.CreatedDateTimeUtc)
                    .Include(i => i.Actions)
                    .ToList();

                // TODO Actually we want to list the items in order of last run
                // I think. At the top of the list is not necessarily the last created
                // but the last run

                currentItems.ForEach(AddExistingItem);
            }
        }
예제 #8
0
        public void ShowActionsForPeriod(DailyListTimePeriod periodToRetrieve)
        {
            Actions = new ObservableCollection<ActionViewModel>();

            using (var itemModel = new DailyListContext())
            {
                var nowDate = SystemClock.Instance.Now.InUtc().Date;

                var periodStart = nowDate.AtMidnight().ToDateTimeUnspecified();
                var periodEnd = nowDate.AtMidnight().PlusDays(1).ToDateTimeUnspecified();

                //var actionEntities = itemModel.DailyListItemActions
                //    .Where(i => (i.ActionDateTimeUtc >= periodStart) &&
                //        (i.ActionDateTimeUtc < periodEnd))
                //    .Include(i => i.DailyListItem)
                //    .ToList();

                // TODO Implement the period properly
                var actionEntities = itemModel.DailyListItemActions
                    .Include(i => i.DailyListItem)
                    .ToList();

                actionEntities.ForEach(i => Actions.Add(new ActionViewModel(i, Context)));
            }
        }
예제 #9
0
        public void ShowActionsForItem(Guid dailyListItemId)
        {
            Actions = new ObservableCollection<ActionViewModel>();

            using (var itemModel = new DailyListContext())
            {
                var actionEntities = itemModel.DailyListItemActions
                    .Where(i => i.DailyListItemId == dailyListItemId)
                    .Include(i => i.DailyListItem)
                    .ToList();

                actionEntities.ForEach(i => Actions.Add(new ActionViewModel(i, Context)));
            }
        }