Esempio n. 1
0
        /// <summary>
        /// Delete the specified project from the db.
        /// If the project is not already in the repository, an
        /// exception is thrown.
        /// </summary>
        public void DeleteProject(Project project, TaskData taskData)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            if (project.ProjectId == 0)
            {
                throw new InvalidOperationException("delete project");
            }

            var query = (from p in _appInfo.GcContext.Projects
                         where p.ProjectID == project.ProjectId
                         select p).First();

            Project requestedProject = Project.CreateProject(query);

            // delete child tasks first
            List <Task> childTasks = this.GetChildTasks(requestedProject.ProjectId);

            foreach (Task childTask in childTasks)
            {
                taskData.DeleteTask(childTask);
            }

            _appInfo.GcContext.DeleteObject(query);
            _appInfo.GcContext.SaveChanges();

            if (this.ProjectDeleted != null)
            {
                this.ProjectDeleted(this, new ProjectDeletedEventArgs(project));
            }
        }
        /// <summary>
        /// Launches the delete task window.
        /// </summary>
        public void DeleteTask()
        {
            TaskViewModel selectedTaskVM = ChildTasks.FirstOrDefault(t => t.IsSelected == true);

            if (selectedTaskVM != null && WPFMessageBox.Show(Properties.Resources.Delete_Confirm, Properties.Resources.Tasks_Delete_Confirm, WPFMessageBoxButtons.YesNo, WPFMessageBoxImage.Question) == WPFMessageBoxResult.Yes)
            {
                _taskData.DeleteTask(_taskData.GetTaskByTaskId(selectedTaskVM.TaskId));
                selectedTaskVM.Dispose();
            }
        }