Ejemplo n.º 1
0
        //[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);

            Logger.Debug("Creaded " + taskEntity);

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

            return(new CreateTaskOutput
            {
                Task = taskEntity.MapTo <TaskDto>()
            });
        }
        public GetUserProfileOutput GetUserProfile(GetUserProfileInput input)
        {
            var currentUser = _userRepository.Load(AbpUser.CurrentUserId.Value);

            var profileUser = _userRepository.Get(input.UserId);

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

            if (profileUser.Id != currentUser.Id)
            {
                var friendship = _friendshipRepository.GetOrNull(currentUser.Id, input.UserId);
                if (friendship == null)
                {
                    return(new GetUserProfileOutput {
                        CanNotSeeTheProfile = true, User = profileUser.MapTo <UserDto>()
                    });                                                                                                  //TODO: Is it true to send user informations?
                }

                if (friendship.Status != FriendshipStatus.Accepted)
                {
                    return(new GetUserProfileOutput {
                        CanNotSeeTheProfile = true, SentFriendshipRequest = true, User = profileUser.MapTo <UserDto>()
                    });
                }
            }

            return(new GetUserProfileOutput {
                User = profileUser.MapTo <UserDto>()
            });
        }
Ejemplo n.º 3
0
 public void HandleEvent(TaskCompletedEventData eventData)
 {
     if (eventData.Entity.CreatorUserId.HasValue)
     {
         _notificationService.Notify(new CompletedTaskNotification(eventData.Entity, _userRepository.Get(eventData.Entity.CreatorUserId.Value)));
     }
 }