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>() }); }
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) }); }
public void HandleEvent(EntityCreatedEventData <Task> eventData) { _activityService.AddActivity( new CreateTaskActivity { CreatorUser = eventData.Entity.CreatorUserId.HasValue ? _userRepository.Load(eventData.Entity.CreatorUserId.Value) : null, AssignedUser = eventData.Entity.AssignedUser, Task = eventData.Entity }); }
public GetFollowedActivitiesOutput GetFollowedActivities(GetFollowedActivitiesInput input) { var currentUser = _userRepository.Load(AbpUser.CurrentUserId.Value); var user = _userRepository.Load(input.UserId); //Can see activities of this user? if (currentUser.Id != user.Id && !_friendshipDomainService.HasFriendship(user, currentUser)) { throw new UserFriendlyException("Can not see activities of this user!"); } //TODO: Think on private activities? When a private task is created or completed? var activities = _followedActivityRepository.Getactivities(input.UserId, input.IsActor, input.BeforeId, input.MaxResultCount); return(new GetFollowedActivitiesOutput { Activities = activities.MapIList <UserFollowedActivity, UserFollowedActivityDto>() }); }
public virtual void ChangeFriendshipProperties(ChangeFriendshipPropertiesInput input) { var currentUser = _taskeverUserRepository.Load(AbpUser.CurrentUserId.Value); var friendShip = _friendshipRepository.Get(input.Id); //TODO: Call FirstOrDefault and throw a specific exception? if (!_friendshipPolicy.CanChangeFriendshipProperties(currentUser, friendShip)) { throw new ApplicationException("Can not change properties of this friendship!"); } //TODO: Implement mappings using Auto mapper! if (input.CanAssignTask.HasValue) { friendShip.CanAssignTask = input.CanAssignTask.Value; } if (input.FollowActivities.HasValue) { friendShip.FollowActivities = input.FollowActivities.Value; } }
protected virtual void CreateUserFollowedActivities(Activity activity) { //TODO: Run this method in a new thread (check connection creation) //TODO: Maybe optimized by creating a stored procedure? //Get user id's of all actors of this activity var actorUserIds = activity.GetActors().Cast <long>().ToList(); if (actorUserIds.IsNullOrEmpty()) { //No actor of this activity, so, no one will follow it. return; } //Get all followers of these actors var followerUserIds = GetFollowersOfUserIds(actorUserIds); //Add also actors (if not includes) followerUserIds = followerUserIds.Union(actorUserIds).ToList(); //Get id's of all related users of this activity var relatedUserIds = activity.GetRelatedUsers().Cast <long>().ToList(); //Add also related users (if not includes) followerUserIds = followerUserIds.Union(relatedUserIds).ToList(); //Add one entity for each follower and actor foreach (var followerUserId in followerUserIds) { _userFollowedActivityRepository.Insert( new UserFollowedActivity { User = _userRepository.Load(followerUserId), Activity = activity, IsActor = actorUserIds.Contains(followerUserId), IsRelated = relatedUserIds.Contains(followerUserId) }); } }