Ejemplo n.º 1
0
        public GetTaskOutput GetTask(GetTaskInput input)
        {
            var currentUser = _userRepository.Load(AbpUser.CurrentUserId.Value);
            var task        = _taskRepository.FirstOrDefault(input.Id);

            if (task == null)
            {
                throw new UserFriendlyException("Can not found the task!");
            }

            if (!_taskPolicy.CanSeeTasksOfUser(currentUser, task.AssignedUser))
            {
                throw new UserFriendlyException("Can not see tasks of " + task.AssignedUser.Name);
            }

            if (task.AssignedUser.Id != currentUser.Id && task.Privacy == TaskPrivacy.Private)
            {
                throw new UserFriendlyException("Can not see this task since it's private!");
            }

            return(new GetTaskOutput
            {
                Task = task.MapTo <TaskWithAssignedUserDto>(),
                IsEditableByCurrentUser = _taskPolicy.CanUpdateTask(currentUser, task)
            });
        }