private async Task ActOnSubmitCallback(DetectionUpdate request)
        {
            await Service.UpdateRequestAsync(request);

            await JSRuntime.InvokeVoidAsync("PlaySubmitSound");

            await LoadDetection();
        }
Example #2
0
        public async Task UpdateRequestAsync(DetectionUpdate request)
        {
            var url           = $"{api}/{request.Id}";
            var dataJson      = JsonSerializer.Serialize(request);
            var stringContent = new StringContent(dataJson, Encoding.UTF8, "application/json");

            var httpResponseMessage = await httpClient.PutAsync(url, stringContent);
        }
        private async Task ActOnSubmitCallback(DetectionUpdate request)
        {
            await Service.UpdateRequestAsync(request);

            ToastService.ShowSuccess("Detection successfully updated.");

            await LoadDetection();
        }
        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));
            }
        }