示例#1
0
        public async Task <IActionResult> CreateBehavioralSkill(int createdById, BehavioralSkillForCreationDto behavioralSkillForCreationDto)
        {
            try
            {
                var user = await _repo.User.GetUser(createdById, false);

                if (user.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
                {
                    return(Unauthorized());
                }

                behavioralSkillForCreationDto.CreatedById = createdById;

                var behavioralSkill = _mapper.Map <BehavioralSkill>(behavioralSkillForCreationDto);

                _repo.BehavioralSkill.AddBehavioralSkill(behavioralSkill);
                await _repo.BehavioralSkill.SaveAllAsync();

                var behavioralSkillToReturn = _mapper.Map <BehavioralSkillToReturnDto>(behavioralSkill);
                return(CreatedAtRoute("GetBehavioralSkill", new { id = behavioralSkill.Id }, behavioralSkillToReturn));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside CreateBehavioralSkill endpoint: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
示例#2
0
        public async Task <IActionResult> CloneBehavioralSkill(int ownerId, int BehavioralSkillId)
        {
            try
            {
                var owner = await _repo.User.GetUser(ownerId, false);

                if (owner.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
                {
                    return(Unauthorized());
                }

                var behavioralSkillFromRepo = await _repo.BehavioralSkill.GetBehavioralSkill(BehavioralSkillId);

                var newBehavioralSkill = new BehavioralSkillForCreationDto()
                {
                    Skill                 = behavioralSkillFromRepo.Skill + " - clone",
                    CreatedById           = ownerId,
                    Definition            = behavioralSkillFromRepo.Definition,
                    LevelOne              = behavioralSkillFromRepo.LevelOne,
                    LevelOneGrade         = behavioralSkillFromRepo.LevelOneGrade,
                    LevelOneDescription   = behavioralSkillFromRepo.LevelOneDescription,
                    LevelTwo              = behavioralSkillFromRepo.LevelTwo,
                    LevelTwoGrade         = behavioralSkillFromRepo.LevelTwoGrade,
                    LevelTwoDescription   = behavioralSkillFromRepo.LevelTwoDescription,
                    LevelThree            = behavioralSkillFromRepo.LevelThree,
                    LevelThreeGrade       = behavioralSkillFromRepo.LevelThreeGrade,
                    LevelThreeDescription = behavioralSkillFromRepo.LevelThreeDescription,
                    LevelFour             = behavioralSkillFromRepo.LevelFour,
                    LevelFourGrade        = behavioralSkillFromRepo.LevelFourGrade,
                    LevelFourDescription  = behavioralSkillFromRepo.LevelFourDescription,
                };

                var behavioralSkill = _mapper.Map <BehavioralSkill>(newBehavioralSkill);

                _repo.BehavioralSkill.AddBehavioralSkill(behavioralSkill);

                await _repo.BehavioralSkill.SaveAllAsync();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside CloneBehavioralSkill endpoint: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }