Ejemplo n.º 1
0
        public async Task <UserDto> UpdateUserAsync(UserDto user)
        {
            UserEntity userEntity = await _userStorage.FindAsync(u => u.Id == user.Id);

            List <TechnologyEntity> storedTechnologies = new List <TechnologyEntity>(userEntity.UserTechnologies);
            bool storedLookingForProject = userEntity.LookingForProject;

            userEntity.UserTechnologies.RemoveAll(t => t.UserId == user.Id);

            userEntity.Bio               = user.Bio;
            userEntity.Username          = user.Username;
            userEntity.LookingForProject = user.LookingForProject;
            // TODO: Refactor
            //userEntity.Email = user.Email;
            //userEntity.GitHubUsername = user.GitHubUsername;
            //userEntity.ProfilePictureUrl = user.ProfilePictureUrl;
            userEntity.UserTechnologies.AddRange(MapTechnologies(user.Technologies));
            await _userStorage.UpdateAsync(userEntity);

            await _techStorage.DeleteAsync(storedTechnologies);

            await RecomputeProjectCollaboratorSuggestions(user, storedTechnologies, storedLookingForProject);

            UserDto userDto = _mapper.Map <UserDto>(userEntity);

            return(userDto);
        }
Ejemplo n.º 2
0
        private async Task ProcessReactionRemovedEvent(SlackEventFullDto <ReactionEventDto> slackEventDto)
        {
            if (InvalidTechnologyReaction(slackEventDto))
            {
                return;
            }

            string          reactionName = slackEventDto.Event.Reaction;
            SlackMessageDto messageDto   = await _slackService.ChatRetrieveMessage(slackEventDto.Event.Item.Channel, slackEventDto.Event.Item.Ts);

            MessageDetailsDto initialMessage = messageDto.Messages.First();
            Reaction          reaction       = initialMessage.Reactions?.Find(r => r.Name == reactionName);

            // Only delete technology if it's the last
            // instance of the particular reaction and
            // if the remaining reactions do not belong
            // to privileged members.
            if (reaction != null)
            {
                bool reactedByPrivilegedUsers = reaction.Users.Intersect(_privilegedMembers.Members).Count() > 0;
                bool reactedByOwner           = reaction.Users.Contains(initialMessage.User);

                if (reactedByPrivilegedUsers || reactedByOwner)
                {
                    return;
                }
            }

            string technologyName = reactionName.Remove(reactionName.LastIndexOf("-"));

            // if technology name uses keywords - replace them with appropriate
            // value
            foreach (var word in _keywords)
            {
                technologyName = technologyName.Replace(word.Key, word.Value);
            }

            string     workspaceId       = slackEventDto.TeamId;
            string     workspaceMemberId = slackEventDto.Event.ItemUser;
            UserEntity user = await GetUserEntity(workspaceId, workspaceMemberId);

            TechnologyEntity technology = user.UserTechnologies.Find(tech => tech.Name == technologyName);

            // if technology has been deleted that for
            // some reason doesn't exist in db return
            if (technology == null)
            {
                return;
            }
            await _technologiesStorage.DeleteAsync(technology.Id);
        }