public async Task <IActionResult> Get() { var skillsMetadata = await _skillsMetadataRepository.Get(); if (skillsMetadata == null) { return(NotFound()); } return(new ObjectResult(skillsMetadata)); }
public async Task <IActionResult> AddSkill(int git, [FromBody] PersonSkillViewModel personSkillViewModel) { if (personSkillViewModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var person = await _personRepository.GetPersonWithSkills(personSkillViewModel.PersonId); if (person == null) { return(NotFound()); } var skillToAdd = await _skillRepository.GetSingleAsync(personSkillViewModel.SkillId); var skillsMetadata = await _metadataRepository.Get(); var personSkill = new PersonSkill { Skill = skillToAdd, SkillLevel = skillsMetadata.SkillLevels.Where(x => x.Code == personSkillViewModel.SkillLevelCode).FirstOrDefault(), TimeUsed = skillsMetadata.TimePeriods.Where(x => x.Code == personSkillViewModel.TimeUsedCode).FirstOrDefault(), TimeSinceUsed = skillsMetadata.TimePeriods.Where(x => x.Code == personSkillViewModel.TimeLastUsedCode).FirstOrDefault() }; if (person.Skills == null) { person.Skills = new Collection <PersonSkill>(); } person.Skills.Add(personSkill); await _personRepository.SaveChangesAsync(); var personViewModel = PersonViewModelFactory.Build(person); return(CreatedAtAction(nameof(Get), new { id = personViewModel.LastName }, personViewModel)); }