public async Task <IActionResult> Put([FromBody] TagUpdate tagUpdate) { try { if (tagUpdate == null) { throw new ArgumentNullException("tagUpdate"); } var detectionsToUpdate = _repository.GetAllWithTag(tagUpdate.OldTag).ToList(); if (detectionsToUpdate.Count() == 0) { return(NoContent()); } foreach (var detection in detectionsToUpdate) { detection.tags = detection.tags.Replace(tagUpdate.OldTag, tagUpdate.NewTag); } await _repository.CommitAsync(); return(Ok(detectionsToUpdate.Count())); } catch (ArgumentNullException ex) { var details = new ProblemDetails() { Detail = ex.Message }; return(BadRequest(details)); } catch (Exception ex) { var details = new ProblemDetails() { Title = ex.GetType().ToString(), Detail = ex.Message }; return(StatusCode(StatusCodes.Status500InternalServerError, details)); } }