public async Task <int> UpdateColleagueAsync(ColleguePatchDto collegueDto) { if (collegueDto == null) { throw new CollegueInvalideException(); } var collegue = await FindColleagueByMatriculeAsync(collegueDto.Matricule) .ConfigureAwait(false); if (collegue == null) { throw new CollegueNonTrouveException(); } if (collegueDto.Email != null) { collegue.Email = collegueDto.Email; } if (collegueDto.PhotoUrl != null) { collegue.PhotoUrl = collegueDto.PhotoUrl; } _colleguesContext.Entry(collegue).State = EntityState.Modified; return(await _colleguesContext .SaveChangesAsync() .ConfigureAwait(false)); }
public async Task <Collegue> ModifierCollegue(ColleguePatchDto collegueDto) { if (collegueDto == null) { throw new CollegueInvalideException(); } await _collegueRepository.UpdateColleagueAsync(collegueDto).ConfigureAwait(false); return(await RechercherParMatricule(collegueDto.Matricule).ConfigureAwait(false)); }
public IActionResult PatchColleagueAsync(string matricule, [FromBody] ColleguePatchDto collegueDto) { if (collegueDto != null) { collegueDto.Matricule = matricule; try { var response = Ok(_collegueService.ModifierCollegue(collegueDto).Result); return(response); } catch (CollegueNonTrouveException) { return(NotFound()); } catch (CollegueInvalideException) { return(BadRequest()); } catch (ProblemeTechniqueException) { return(BadRequest()); } catch (AggregateException e) { if (e.InnerException.GetType() == typeof(CollegueNonTrouveException)) { return(NotFound()); } else { return(BadRequest()); } } } else { throw new CollegueInvalideException(); } }