예제 #1
0
        /// <summary>
        /// Delete the specified goal and descendents from the db.
        /// If the goal is not already in the repository, an
        /// exception is thrown.
        /// </summary>
        public void DeleteGoal(Goal goal, ProjectData projectData, TaskData taskData)
        {
            if (goal == null)
            {
                throw new ArgumentNullException("goal");
            }

            if (goal.GoalId == 0)
            {
                throw new InvalidOperationException("delete goal");
            }

            var query = (from g in _appInfo.GcContext.Goals
                         where g.GoalID == goal.GoalId
                         select g).First();

            Goal requestedGoal = Goal.CreateGoal(query);

            // delete child projects first
            List <Project> childProjects = this.GetChildProjects(requestedGoal.GoalId);

            foreach (Project childProject in childProjects)
            {
                projectData.DeleteProject(childProject, taskData);
            }

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

            if (this.GoalDeleted != null)
            {
                this.GoalDeleted(this, new GoalDeletedEventArgs(goal));
            }
        }
예제 #2
0
        public void PurgeCompletedGoals(ProjectData projectData, TaskData taskData)
        {
            List <Data.Goal> completedDbGoals = (from g in _appInfo.GcContext.Goals
                                                 where g.StatusID == Statuses.Completed
                                                 select g).ToList();

            foreach (Data.Goal completedDbGoal in completedDbGoals)
            {
                Goal completedGoal = Goal.CreateGoal(completedDbGoal);

                this.DeleteGoal(completedGoal, projectData, taskData);
            }
        }
예제 #3
0
        /// <summary>
        /// Returns a shallow-copied list of all goals in the repository.
        /// </summary>
        public List <Goal> GetGoals(string filterTerm = "", SortableProperty sortColumn = null, int?pageNumber = null)
        {
            QueryCacheItem   allGoalsCacheItem = _appInfo.GlobalQueryCache.GetCacheItem(Constants.AllGoalsCacheItem);
            List <Data.Goal> dbGoalsList;

            // retrieve the query from cache if available
            // this will avoid retrieving all records when only a page is needed
            if (allGoalsCacheItem == null)
            {
                // get the unordered, unfiltered list for caching
                IQueryable <Data.Goal> allGoals = GetAllGoalsQuery();
                dbGoalsList = GetOrderedList(allGoals);
                _appInfo.GlobalQueryCache.AddCacheItem(Constants.AllGoalsCacheItem, dbGoalsList);
            }
            else
            {
                dbGoalsList = (List <Data.Goal>)allGoalsCacheItem.Value;
            }

            // now do the ordering and filtering
            if (!string.IsNullOrEmpty(filterTerm))
            {
                dbGoalsList = (from g in dbGoalsList
                               where g.Title.ToLower().Contains(filterTerm.ToLower())
                               select g).ToList();
            }

            if (sortColumn != null)
            {
                dbGoalsList = SortList(dbGoalsList, sortColumn);
            }

            // do the paging
            if (pageNumber.HasValue)
            {
                dbGoalsList = dbGoalsList.Skip(Constants.RecordsPerPage * (pageNumber.Value - 1))
                              .Take(Constants.RecordsPerPage).ToList();
            }

            // create system goal objects from db goal objects
            List <Goal> goals = new List <Goal>();

            foreach (Data.Goal dbGoal in dbGoalsList)
            {
                goals.Add(Goal.CreateGoal(dbGoal));
            }

            return(goals);
        }
예제 #4
0
        /// <summary>
        /// Returns a shallow-copied list of a single goal by goal id.
        /// </summary>
        public Goal GetGoalByGoalId(int goalId)
        {
            Goal requestedGoal = null;

            Data.Goal requestedDbGoal = (from g in _appInfo.GcContext.Goals
                                         where g.GoalID == goalId
                                         select g).FirstOrDefault();

            if (requestedDbGoal != null)
            {
                requestedGoal = Goal.CreateGoal(requestedDbGoal);
            }

            return(requestedGoal);
        }
예제 #5
0
        /// <summary>
        /// Returns a shallow-copied list of all goals that contain tasks.
        /// </summary>
        public List <Goal> GetGoalsContainingInactiveTasks()
        {
            List <Data.Goal> dbGoals = (from p in _appInfo.GcContext.Projects
                                        where p.Tasks.Any(t => t.IsActive == false && t.StatusID != Statuses.Completed && t.StatusID != Statuses.Abandoned) && p.Goals.Count > 0
                                        orderby p.Goals.FirstOrDefault().Title
                                        select p.Goals.FirstOrDefault()).Distinct().ToList();

            List <Goal> goals = new List <Goal>();

            foreach (Data.Goal dbGoal in dbGoals)
            {
                goals.Add(Goal.CreateGoal(dbGoal));
            }

            return(goals);
        }
예제 #6
0
        public static Project CreateProject(Data.Project dbProject)
        {
            Data.Goal parentGoal = (from pt in dbProject.Goals
                                          select pt).FirstOrDefault();

            return new Project
            {
                ProjectId = dbProject.ProjectID,
                Title = dbProject.Title,
                CreatedDate = dbProject.CreatedDate,
                CompletedDate = dbProject.CompletedDate,
                EstimatedCost = dbProject.EstimatedCost,
                StatusId = dbProject.StatusID,
                ParentGoal = parentGoal == null ? null : Goal.CreateGoal(parentGoal)
            };
        }
예제 #7
0
        /// <summary>
        /// Returns a shallow-copied list of all completed goals within the given date range.
        /// </summary>
        public List <Goal> GetCompletedGoalsByDate(DateTime startDate, DateTime endDate)
        {
            List <Data.Goal> dbGoals = (from g in _appInfo.GcContext.Goals
                                        where g.StatusID == Statuses.Completed &&
                                        g.CompletedDate >= startDate &&
                                        g.CompletedDate <= endDate
                                        orderby g.Title
                                        select g).ToList();

            List <Goal> goals = new List <Goal>();

            foreach (Data.Goal dbGoal in dbGoals)
            {
                goals.Add(Goal.CreateGoal(dbGoal));
            }

            return(goals);
        }