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));
            }
        }
        public async Task <IActionResult> Put(string id, [FromBody] DetectionUpdate detectionUpdate)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    throw new ArgumentNullException("id");
                }

                if (detectionUpdate == null)
                {
                    throw new ArgumentNullException("postedDetection");
                }

                var metadata = await _repository.GetByIdAsync(id);

                if (metadata == null)
                {
                    return(NotFound());
                }

                metadata.comments      = detectionUpdate.Comments;
                metadata.moderator     = detectionUpdate.Moderator;
                metadata.dateModerated = detectionUpdate.Moderated.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
                metadata.reviewed      = detectionUpdate.Reviewed;
                metadata.SRKWFound     = (string.IsNullOrWhiteSpace(detectionUpdate.Found)) ? "no" : detectionUpdate.Found.ToLower();

                // Normalize the tags
                if (!string.IsNullOrWhiteSpace(detectionUpdate.Tags))
                {
                    var working = detectionUpdate.Tags.Replace(",", ";");

                    var tagList = new List <string>();
                    tagList.AddRange(working.Split(';').ToList().Select(x => x.Trim()));
                    metadata.tags = string.Join(";", tagList);
                }
                else
                {
                    metadata.tags = string.Empty;
                }

                await _repository.CommitAsync();

                return(Ok(MetadataProcessors.ToDetection(metadata)));
            }
            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));
            }
        }