public async Task <IActionResult> AddCert([FromBody] CertificationForCreationDto input) { var certification = _mapper.Map <Certification>(input); if (User.IsInRole("Admin")) { if (!input.TrainerId.HasValue) { return(BadRequest("Please specify the trainer id to add certificate to")); } if (!await IsTrainer(input.TrainerId.Value)) { return(NotFound("No such a trainer with specified ID")); } certification.trainerId = input.TrainerId.Value; } certification.trainerId = CurrentUserId; await _certificationRepo.Add(certification); return(Ok()); }
public async Task <IActionResult> AddCert(CertificationForCreationDto certificationForCreationDto) { var userId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var user = await _genUserRepo.GetByIdAsync(userId); if (user == null) { return(Unauthorized()); } var Cert = _mapper.Map <Certification>(certificationForCreationDto); Cert.UserId = userId; _genCertificationRepo.Add(Cert); if (await _genCertificationRepo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to add certification")); }