public async Task <ActionResult> PostFreelancer(FreelancerViewModel vm) { string res = User.Claims.First(x => x.Type == "UserId").Value; int id = int.Parse(res); vm.UserId = id; var freelancer = new Domain.Entities.Freelancer() { UserForeignKey = id, PayHourly = vm.PayHourly }; await freelancerService.AddAsync(freelancer); await clientService.AddAsync(vm.CompanyName, id); var user = await userService.GetAsync(id); var token = await tokenService.GenerateToken(user, appSettings.JWT_Secret, vm.Password); //Update freelancerId and skillId of Skills var skillsUsers = vm.SkillUsers.Select(c => new SkillUser { FreelancerId = user.Freelancer.Id, SkillId = c.Skill.Id }).ToList(); await skillService.AddRangeAsync(skillsUsers); if (token == "") { return(BadRequest()); } return(Ok(new { token })); }