コード例 #1
0
        public async Task <IActionResult> AddAdvisor([FromBody] AdvisorForCreateDto advisorForCreateDto)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (!await _repo.GetUserLevelAdmin(currentUserId))
            {
                return(Unauthorized());
            }

            if (await _advisorRepo.AdvisorExists(advisorForCreateDto.FullName))
            {
                ModelState.AddModelError("Advisor Name", "Advisor Name already exists");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var advisorToCreate = new Advisors {
                FullName  = advisorForCreateDto.FullName,
                FirstName = advisorForCreateDto.FirstName,
                LastName  = advisorForCreateDto.LastName,
                Title     = advisorForCreateDto.Title
            };

            var createAdvisor = await _advisorRepo.AddAdvisor(advisorToCreate);

            return(StatusCode(201));
        }
コード例 #2
0
 public async Task AddAdvisor(AdvisorDTO advisor)
 {
     await _advisorRepository.AddAdvisor(advisor);
 }