Exemplo n.º 1
0
        /// <summary>
        /// Completing the selected event and add it to the completed table.
        /// </summary>
        private void CompleteEvent()
        {
            if (SelectedEvent == null || SelectedEvent.IsCompleted)
            {
                return;
            }

            using (var context = new EventDatabaseEntities())
            {
                Completed completed = new Completed()
                {
                    EventID = SelectedEvent.CurrentEvent.ID
                };
                context.Completeds.Add(completed);

                // Mark every task as completed.
                (from item in context.Tasks
                 where item.EventID == SelectedEvent.CurrentEvent.ID select item).ToList().ForEach(x => x.Completed = true);

                TodayTasksList.ToList().ForEach(x => x.Completed = true);
                SelectedEvent.IsCompleted = true;
                ProgressbarValue          = ProgressbarSize;
                context.SaveChanges();
                MessageBox.Show("Event completed successfully!");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decreases the number of the tasks of the selected event.
        /// </summary>
        private void DecreaseSelectedTaskEvent()
        {
            int current = int.Parse(TaskNumberSelected);

            if (current == 0)
            {
                return;
            }


            current--;
            TaskNumberSelected = current.ToString();
            TodayTasksList.RemoveAt(current);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Increases the number of the tasks of the selected event.
        /// </summary>
        private void IncreaseSelectedTaskEvent()
        {
            int current = int.Parse(TaskNumberSelected);

            if (current == 99)
            {
                return;
            }

            current++;
            TaskNumberSelected = current.ToString();
            TodayTasksList.Add(new Task {
                Description = ""
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the selected event.
        /// </summary>
        private void UpdateEvent()
        {
            if (SelectedEvent.IsCompleted)
            {
                return;
            }

            if (SelectedEvent.CurrentEvent.Date == null || string.IsNullOrWhiteSpace(SelectedEvent.CurrentEvent.Title))
            {
                MessageBox.Show("Wrong title or date!");
                return;
            }

            using (var context = new EventDatabaseEntities())
            {
                // Update the event.
                var update = context.Events.Where(x => x.ID == SelectedEvent.CurrentEvent.ID).Single();
                context.Entry(update).CurrentValues.SetValues(SelectedEvent);

                context.Tasks.RemoveRange(context.Tasks.Where(x => x.EventID == SelectedEvent.CurrentEvent.ID));
                context.SaveChanges();

                foreach (var item in TodayTasksList)
                {
                    if (!string.IsNullOrWhiteSpace(item.Description))
                    {
                        context.Tasks.Add(new Task {
                            EventID = SelectedEvent.CurrentEvent.ID, Description = item.Description
                        });
                    }
                }

                context.SaveChanges();

                //Remove every empty task item from the list if there any.
                TodayTasksList.Where(x => string.IsNullOrWhiteSpace(x.Description)).ToList().All(i => TodayTasksList.Remove(i));

                TaskNumberSelected = TodayTasksList.Count().ToString();
                ProgressbarSize    = TodayTasksList.Count();
                ProgressbarValue   = TodayTasksList.Where(r => r.Completed == true).Count();
                IsEditable         = false;
            }
        }