//[AbpAuthorize(TaskeverPermissions.CreateTask)]
        public virtual CreateTaskOutput CreateTask(CreateTaskInput input)
        {
            //Get entities from database
            var creatorUser = _userRepository.Get(AbpUser.CurrentUserId.Value);
            var assignedUser = _userRepository.Get(input.Task.AssignedUserId);

            if (!_taskPolicy.CanAssignTask(creatorUser, assignedUser))
            {
                throw new UserFriendlyException("You can not assign task to this user!");
            }

            //Create the task
            var taskEntity = input.Task.MapTo<Task>();

            taskEntity.CreatorUserId = creatorUser.Id;
            taskEntity.AssignedUser = _userRepository.Load(input.Task.AssignedUserId);
            taskEntity.State = TaskState.New;

            if (taskEntity.AssignedUser.Id != creatorUser.Id && taskEntity.Privacy == TaskPrivacy.Private)
            {
                throw new ApplicationException("A user can not assign a private task to another user!");
            }

            _taskRepository.Insert(taskEntity);

            _eventBus.Trigger(this, new EntityCreatedEventData<Task>(taskEntity));

            return new CreateTaskOutput
                       {
                           Task = taskEntity.MapTo<TaskDto>()
                       };
        }
        public async System.Threading.Tasks.Task<CreateTaskOutput> CreateTaskAsync(CreateTaskInput input)
        {
            //Get entities from database
            var creatorUser = await _userRepository.GetAsync(AbpSession.UserId.Value); // was TaskeverUser.CurrentUserId.Value
            var assignedUser = await _userRepository.GetAsync(input.Task.AssignedUserId);

            if (!_taskPolicy.CanAssignTask(creatorUser, assignedUser))
            {
                throw new UserFriendlyException("You can not assign task to this user!");
            }

            //Create the task
            var taskEntity = input.Task.MapTo<Task>();

            taskEntity.CreatorUserId = creatorUser.Id;
            taskEntity.AssignedUser = assignedUser;// _userRepository.Load(input.Task.AssignedUserId);
            taskEntity.State = TaskState.New;

            if (taskEntity.AssignedUser.Id != creatorUser.Id && taskEntity.Privacy == TaskPrivacy.Private)
            {
                throw new ApplicationException("A user can not assign a private task to another user!");
            }

            //TODO: Check, this may have an id issue, load seperately to resolve
            await _taskRepository.InsertAsync(taskEntity);

            Logger.Debug("Created " + taskEntity);

            //TODO: Reimplement
            _eventBus.Trigger(this, new EntityCreatedEventData<Task>(taskEntity));

            return new CreateTaskOutput
            {
                Task = taskEntity.MapTo<TaskDto>()
            };
        }
        public virtual CreateTaskOutput CreateTask(CreateTaskInput input)
        {
            if (System.Diagnostics.Debugger.IsAttached)
                System.Diagnostics.Debugger.Break();

            //Get entities from database
            var creatorUser = _userRepository.Load(AbpSession.UserId.Value); // was TaskeverUser.CurrentUserId.Value
            var assignedUser = _userRepository.Load(input.Task.AssignedUserId);

            if (!_taskPolicy.CanAssignTask(creatorUser, assignedUser))
            {
                throw new UserFriendlyException("You can not assign task to this user!");
            }

            //Create the task
            var taskEntity = input.Task.MapTo<Task>();

            taskEntity.CreatorUserId = creatorUser.Id;
            taskEntity.AssignedUserId = assignedUser.Id;// _userRepository.Load(input.Task.AssignedUserId);
            taskEntity.State = TaskState.New;

            if (taskEntity.AssignedUserId != creatorUser.Id && taskEntity.Privacy == TaskPrivacy.Private)
            {
                throw new ApplicationException("A user can not assign a private task to another user!");
            }

            int id = _taskRepository.InsertAndGetId(taskEntity);
            Task result = _taskRepository.Get(id);

            Logger.Debug("Created " + taskEntity);
            Logger.Debug("Result " + result);

            // TODO: check
            _eventBus.Trigger(this, new EntityCreatedEventData<Task>(result));
                
            return new CreateTaskOutput
                       {
                           Task = result.MapTo<TaskDto>()
                       };
        }