Esempio n. 1
0
        private async System.Threading.Tasks.Task <Tasks_Issue809> manageParentTask(Tasks_Issue809 task)
        {
            if ((task.ParentTask != null) && (task.ParentTask.Parent_Task > 0))
            {
                ParentTask_Issue809 parentTask = taskContext.ParentTasks.FirstOrDefault(parTsk =>
                                                                                        parTsk.Parent_Task == task.ParentTaskId);
                if (parentTask == default)
                {
                    var parTaskFromTaskEntity = taskContext.Tasks
                                                .FirstOrDefault(tsk => tsk.TaskId == task.ParentTaskId);
                    parentTask = new ParentTask_Issue809
                    {
                        Parent_Task           = parTaskFromTaskEntity.TaskId,
                        ParentTaskDescription = parTaskFromTaskEntity.TaskDeatails
                    };
                    taskContext.ParentTasks.Add(parentTask);
                    await taskContext.SaveChangesAsync();
                }
                else
                {
                    taskContext.Update(parentTask);
                    await taskContext.SaveChangesAsync();
                }

                task.ParentTaskId = parentTask.Parent_ID;
                task.ParentTask   = parentTask;
            }
            else
            {
                task.ParentTask = null;
            }

            return(task);
        }
Esempio n. 2
0
        public async System.Threading.Tasks.Task <bool> EditTask(Tasks_Issue809 tasks, int val)
        {
            if (val == 10)
            {
                return(true);
            }
            else
            {
                if ((tasks.ParentTask != default) && (tasks.ParentTask.Parent_Task == 0))
                {
                    tasks.ParentTask = null;
                }

                var oldTaskQuery = from taskEntity in taskContext.Tasks.Where(tsk => tsk.TaskId == tasks.TaskId)
                                   from parTaskEntity in taskContext.ParentTasks.Where(partask =>
                                                                                       partask.Parent_ID == taskEntity.ParentTaskId).DefaultIfEmpty()
                                   select new { taskEntity, parTaskEntity };
                var oldTaskValueObj = oldTaskQuery.FirstOrDefault();
                var oldTask         = oldTaskValueObj.taskEntity;
                if (oldTaskValueObj.parTaskEntity != default)
                {
                    oldTask.ParentTask = new ParentTask_Issue809
                    {
                        Parent_ID             = oldTaskValueObj.parTaskEntity.Parent_ID,
                        ParentTaskDescription = oldTaskValueObj.parTaskEntity.ParentTaskDescription,
                        Parent_Task           = oldTaskValueObj.parTaskEntity.Parent_Task
                    };
                }


                if (oldTask == default)
                {
                    throw new System.ApplicationException("Task not found");
                }
                if (((oldTask.ParentTask != null) && (oldTask.ParentTask.Parent_ID != tasks.ParentTaskId)) ||
                    ((oldTask.ParentTask == default) && (tasks.ParentTask != default) && (tasks.ParentTask.Parent_Task > 0)))
                {
                    _ = await manageParentTask(tasks);
                }


                taskContext.Update <Tasks_Issue809>(tasks);
                var rowsAffected = await taskContext.SaveChangesAsync();

                bool combinedResult     = (rowsAffected > 0) ? true : false;
                bool parentUpdateResult = await UpdateParentTakDetails(tasks);

                if ((combinedResult) && (parentUpdateResult))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 3
0
        public async System.Threading.Tasks.Task <bool> AddTask(Tasks_Issue809 tasks)
        {
            _ = await manageParentTask(tasks);

            taskContext.Tasks.Add(tasks);
            var rowsAffected = await taskContext.SaveChangesAsync();

            return((rowsAffected > 0) ? true : false);
        }
Esempio n. 4
0
        private async System.Threading.Tasks.Task <bool> UpdateParentTakDetails(Tasks_Issue809 task)
        {
            var parentTask = taskContext.ParentTasks.FirstOrDefault(parTsk =>
                                                                    parTsk.Parent_Task == task.ParentTaskId);

            if ((parentTask != default) &&
                (parentTask.ParentTaskDescription.CompareTo(task.TaskDeatails) != 0))
            {
                parentTask.ParentTaskDescription = task.TaskDeatails;
                taskContext.Update(parentTask);
                var recordsAffected = await taskContext.SaveChangesAsync();

                return((recordsAffected > 0) ? true : false);
            }
            return(true);
        }