public async Task <IActionResult> AddUserSkill(int id, [FromBody] AddUserSkillDTO skill)
        {
            try
            {
                //if (User.Identity.IsAuthenticated)
                {
                    //var login = User.FindFirst(c => c.Type == "urn:github:login")?.Value;
                    //var credentials = new Credentials(await HttpContext.GetTokenAsync("access_token"));

                    //var user = _usersServices.GetUserAsync(login);

                    //if (user.Id != id)
                    //    throw new Exception("Authentication Exception: User not authorize to change other user Id");

                    await _usersServices.AddUserSkillAsync(skill, id);

                    return(NoContent());
                }
                //else
                //{
                //    return BadRequest("Authentication Exception");
                //}
            }
            catch (Exception ex)
            {
                return(BadRequest($"{ex.Message} {ex.InnerException?.Message}"));
            }
        }
示例#2
0
        public async Task AddSkillForUser(AddUserSkillDTO userSkillDto, int userId)
        {
            var skill = _context.Skills
                        .FirstOrDefault(s => s.SkillName
                                        .Equals(userSkillDto.SkillName, StringComparison.OrdinalIgnoreCase));

            if (skill != null)
            {
                var userSkill = await _context.UserSkills
                                .Include(us => us.Skill)
                                .FirstOrDefaultAsync(us => us.UserId == userId && us.Skill.SkillName.Equals(userSkillDto.SkillName));

                if (userSkill == null)
                {
                    _context.UserSkills.Add(new UserSkills
                    {
                        UserId  = userId,
                        SkillId = skill.Id,
                        Rating  = userSkillDto.Rating
                    });
                }
            }
            else
            {
                _context.UserSkills.Add(new UserSkills
                {
                    UserId = userId,
                    Skill  = new Skill
                    {
                        SkillName = userSkillDto.SkillName
                    },
                    Rating = userSkillDto.Rating
                });
            }
            await _context.SaveChangesAsync();
        }
 public async Task AddUserSkillAsync(AddUserSkillDTO userSkill, int userId)
 {
     await _skillsServices.AddSkillForUser(userSkill, userId);
 }