Example #1
0
        public void Update(UpdateProjectTaskInput input)
        {
            var projectId = _ganttRepository.Get().Where(u => u.Tasks.Any(v => v.Id == input.Id)).Select(u => u.ProjectId).FirstOrDefault();

            if (!_projectHelper.HasPermission("项目进度负责人", projectId))
            {
                throw new AppCoreException("项目进度没有权限");
            }
            var task     = input.MapTo <ProjectTask>();
            var existing = _projectTaskRepository.Get().Where(u => u.Id == task.Id).FirstOrDefault();
            int adjacentTaskId;
            var nextSibling = false;
            var targetId    = input.Target;

            _projectTaskRepository.Update(task, new System.Linq.Expressions.Expression <Func <ProjectTask, object> >[] { u => u.GanttId, u => u.SortNo }, false);
            if (!string.IsNullOrEmpty(targetId))
            {
                if (targetId.StartsWith("next:"))
                {
                    targetId    = targetId.Replace("next:", "");
                    nextSibling = true;
                }
                if (!int.TryParse(targetId, out adjacentTaskId))
                {
                    return;
                }
                var adjacentTask = _projectTaskRepository.Get().Where(u => u.Id == adjacentTaskId).Select(u => new ProjectTask {
                    Id = u.Id, SortNo = u.SortNo
                }).FirstOrDefault();
                var sortedOrder = adjacentTask.SortNo;
                if (nextSibling)
                {
                    sortedOrder++;
                }
                List <ProjectTask> updatedList = new List <ProjectTask>();
                updatedList.Add(new ProjectTask {
                    Id = task.Id, SortNo = sortedOrder
                });
                var otherUpdatedList = _projectTaskRepository.Get().Where(u => u.SortNo >= sortedOrder && u.Id != task.Id).Select(u => new ProjectTask {
                    Id = u.Id, SortNo = u.SortNo
                }).ToList();
                otherUpdatedList.ForEach(u => u.SortNo++);
                updatedList.AddRange(otherUpdatedList);
                _projectTaskRepository.BatchUpdate(updatedList, new System.Linq.Expressions.Expression <Func <ProjectTask, object> >[] { u => u.SortNo }, true);
            }
        }