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)); }
public void Apply(Schema model, SchemaFilterContext context) { var toggle = new ServiceToggleVM() { Id = "isButtonBlue", Value = true, Created = DateTime.UtcNow, Modified = DateTime.UtcNow }; model.Default = toggle; model.Example = toggle; }
public async Task <IActionResult> ExecuteAsync(SaveServiceToggleVM createToggle, CancellationToken cancellationToken) { ServiceToggle toggle = _mapper.Map <SaveServiceToggleVM, ServiceToggle>(createToggle); toggle = await _serviceToggleRepository.Add(toggle, cancellationToken); ServiceToggleVM toggleViewModel = _mapper.Map <ServiceToggle, ServiceToggleVM>(toggle); return(new CreatedAtRouteResult( ServiceControllerRoute.GetServiceToggle, new { toggleId = toggleViewModel.Id }, toggleViewModel)); }
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)); }
public void ServiceToggleVM_should_mapped_to_ServiceToggle_model() { ServiceToggleVM toggle = new ServiceToggleVM { Id = "isButtonBlue", Value = true, ServiceId = "ABC", VersionRange = "*", Created = DateTime.UtcNow, Modified = DateTime.UtcNow }; ServiceToggle result = _fixture.Mapper.Map <ServiceToggle>(toggle); result.Id.Should().Be(toggle.Id); result.Value.Should().Be(toggle.Value); result.ServiceId.Should().Be(toggle.ServiceId); result.VersionRange.Should().Be(toggle.VersionRange); result.Created.Should().Be(toggle.Created); result.Modified.Should().Be(toggle.Modified); }