Exemplo n.º 1
0
        // POST users/current/skill-sets/add/{skillSetId}
        // Adds the skill set to the users list.
        public async Task <ActionResult> AddSkillSet(int skillSetId)
        {
            var currentUser = await _userService.GetUserAsync(User);

            // Validation.
            var skillSet = await _skillService.GetSkillSetAsync(skillSetId);

            if (skillSet == null)
            {
                _logger.LogInformation($"AddSkillSet called with invalid SkillSetId of {skillSetId}");
                return(new BadRequestResult());
            }

            var userSkillSets = await _skillService.GetSkillSetsAsync(currentUser.Id);

            if (userSkillSets.Any(set => set.Id == skillSetId))
            {
                // User already has this skillset.
                return(new OkResult());
            }

            // Add the user skillset.
            await _skillService.AddUserSkillSetAsync(currentUser.Id, skillSetId);

            return(new OkResult());
        }