コード例 #1
0
        public async Task <IActionResult> ExecuteAsync(string toggleId, string serviceId, CancellationToken cancellationToken)
        {
            ServiceToggle toggle = await _serviceToggleRepository.GetById(toggleId, serviceId, cancellationToken);

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

            HttpContext httpContext = _actionContextAccessor.ActionContext.HttpContext;

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

            ServiceToggleVM toggleViewModel = _mapper.Map <ServiceToggle, ServiceToggleVM>(toggle);

            httpContext.Response.Headers.Add(HeaderNames.LastModified, toggle.Modified.ToString("R", CultureInfo.InvariantCulture));
            return(new OkObjectResult(toggleViewModel));
        }
コード例 #2
0
        public async Task <IActionResult> ExecuteAsync(string toggleId, string serviceId, CancellationToken cancellationToken)
        {
            ServiceToggle toggle = await _serviceToggleRepository.GetById(toggleId, serviceId, cancellationToken);

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

            await _serviceToggleRepository.Delete(toggle, cancellationToken);

            return(new NoContentResult());
        }
コード例 #3
0
        public async Task <IActionResult> ExecuteAsync(string toggleId, string serviceId, SaveServiceToggleVM saveToggle, CancellationToken cancellationToken)
        {
            ServiceToggle toggle = await _serviceToggleRepository.GetById(toggleId, serviceId, cancellationToken);

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

            _mapper.Map(saveToggle, toggle);
            toggle = await _serviceToggleRepository.Update(toggle, cancellationToken);

            ServiceToggleVM toggleViewModel = _mapper.Map <ServiceToggle, ServiceToggleVM>(toggle);

            return(new OkObjectResult(toggleViewModel));
        }