Ejemplo n.º 1
0
        public async Task <IActionResult> GetAsync(int?id)
        {
            try
            {
                if (id == null)
                {
                    throw new ArgumentException($"Parameter {nameof(id)} cannot be null", nameof(id));
                }

                var value = await _valueService.GetValueAsync(id.Value);

                if (value == null)
                {
                    return(StatusCode((int)HttpStatusCode.NotFound));
                }

                var valueModel = new ValueModel(value);
                return(Ok(valueModel));
            }
            catch (ArgumentException argumentException)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, argumentException.Message));
            }
            catch (Exception exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, exception.Message));
            }
        }