public async Task <IActionResult> GetEcole(long id) { Ecole ecole = await _ecoleRepository.GetById(id); if (ecole == null) { return(NotFound()); } var res = _mapper.Map <EcoleResponseDto>(ecole); return(Ok(res)); }
public async Task <IActionResult> CreateEleve([FromBody] long ecoleId, EleveCreateDto eleveCreateDto) { if (eleveCreateDto.name == null) { return(BadRequest()); } Ecole ecole = await _ecoleRepository.GetById(ecoleId); if (ecole == null) { return(NotFound()); } Eleve eleve = eleve.From(eleveCreateDto); eleve.Ecole = ecole; await _eleveRepository.CreateEntity(eleve); var res = await _ecoleRepository.SaveAsync(); if (!res) { return(BadRequest()); } return(Created("professeur/me", eleve)); }
public async Task <IActionResult> CreateProfesseur([FromBody] long ecoleId, ProfesseurCreateDto professeurCreateDto) { if (professeurCreateDto.name == null) { return(BadRequest()); } Ecole ecole = await _ecoleRepository.GetById(ecoleId); if (ecole == null) { return(NotFound()); } Professeur professeur = Professeur.From(professeurCreateDto); professeur.Ecole = ecole; await _professeurRepository.CreateEntity(professeur); var res = await _ecoleRepository.SaveAsync(); if (!res) { return(BadRequest()); } return(Created("professeur/me", professeur)); }