コード例 #1
0
        public async Task <IActionResult> ExecuteAsync(int id, CancellationToken cancellationToken)
        {
            var item = await _repository.AsyncGetById(id, cancellationToken);

            if (item == null)
            {
                return(new NotFoundResult());
            }

            await _repository.DeleteAsync(item);

            return(new NoContentResult());
        }
コード例 #2
0
        public async Task <IActionResult> ExecuteAsync(int id, CancellationToken cancellationToken)
        {
            var item = await _repository.AsyncGetById(id, cancellationToken);

            if (item == null)
            {
                return(new NotFoundResult());
            }

            var httpContext = _actionContextAccessor.ActionContext.HttpContext;

            if (httpContext.Request.Headers.TryGetValue(HeaderNames.IfModifiedSince, out var stringValues))
            {
                if (DateTimeOffset.TryParse(stringValues, out var modifiedSince) &&
                    (modifiedSince >= item.Modified))
                {
                    return(new StatusCodeResult(StatusCodes.Status304NotModified));
                }
            }

            httpContext.Response.Headers.Add(HeaderNames.LastModified, item.Modified.ToString("R"));
            return(new OkObjectResult(item));
        }