public List <TaskDetail> ViewTasks(SearchRequest searchReq)
        {
            List <TaskDetail> tasks = null;

            using (var taskManagerContext = new TASKMANAGEREntities())
            {
                var taskList = (from task in taskManagerContext.Tasks
                                join parent in taskManagerContext.Tasks on task.Parent_ID equals parent.Task_ID into gj
                                from parenttask in gj.DefaultIfEmpty()
                                select new
                {
                    task.Task_ID,
                    task.Task_Name,
                    task.Priority,
                    task.Parent_ID,
                    task.Start_Date,
                    task.End_Date,
                    Parent_Task = (parenttask != null ? parenttask.Task_Name : string.Empty)
                }).ToList();

                var list = taskList;

                if (searchReq != null)
                {
                    list = taskList.Where(x => x.Task_Name.Contains(searchReq.TaskName) ||
                                          (x.Priority >= searchReq.PriorityFrom && x.Priority <= searchReq.PriorityTo) ||
                                          x.Start_Date >= searchReq.StartDate ||
                                          x.End_Date <= searchReq.EndDate).ToList();
                }

                if (list != null)
                {
                    tasks = new List <TaskDetail>();
                    foreach (var item in list)
                    {
                        var tsk = new TaskDetail
                        {
                            Task_ID     = item.Task_ID,
                            Task_Name   = item.Task_Name,
                            Parent_ID   = item.Parent_ID,
                            Parent_Task = item.Parent_Task,
                            Priority    = item.Priority,
                            Start_Date  = item.Start_Date,
                            End_Date    = item.End_Date
                        };
                        tasks.Add(tsk);
                    }
                }
            }
            return(tasks);
        }
        public List <TaskDetail> ViewAllTasks()
        {
            List <TaskDetail> tasklist = null;

            using (var taskManagerContext = new TASKMANAGEREntities())
            {
                var data = taskManagerContext.Tasks.ToList();
                var list = (from task in taskManagerContext.Tasks
                            join parent in taskManagerContext.Tasks on task.Parent_ID equals parent.Task_ID into gj
                            from parenttask in gj.DefaultIfEmpty()
                            select new
                {
                    task.Task_ID,
                    task.Task_Name,
                    task.Priority,
                    task.Parent_ID,
                    task.Start_Date,
                    task.End_Date,
                    Parent_Task = (parenttask != null ? parenttask.Task_Name : string.Empty)
                }).ToList();

                if (list != null)
                {
                    tasklist = new List <TaskDetail>();
                    foreach (var item in list)
                    {
                        var tsk = new TaskDetail
                        {
                            Task_ID     = item.Task_ID,
                            Task_Name   = item.Task_Name,
                            Parent_ID   = item.Parent_ID,
                            Parent_Task = item.Parent_Task,
                            Priority    = item.Priority,
                            Start_Date  = item.Start_Date,
                            End_Date    = item.End_Date
                        };
                        tasklist.Add(tsk);
                    }
                }
            }
            return(tasklist);
        }