public async Task <IActionResult> GetLifeCyclePhase( [FromServices] BackofficeContext context, [FromRoute] string id, [FromRoute] int faseId, CancellationToken cancellationToken = default) { var projectionPosition = await context.GetProjectionPositionAsync(typeof(PublicServiceLifeCycleListProjections), cancellationToken); Response.Headers.Add(PublicServiceHeaderNames.LastObservedPosition, projectionPosition.ToString()); await context.CheckPublicServiceAsync(id, cancellationToken); var publicServiceLifeCycleItem = await context .PublicServiceLifeCycleList .AsNoTracking() .SingleOrDefaultAsync(item => item.PublicServiceId == id && item.LifeCycleStageId == faseId, cancellationToken); if (publicServiceLifeCycleItem == null) { throw new ApiException("Onbestaande levensloopfase.", StatusCodes.Status404NotFound); } // TODO: Introduce soft delete for lifecycle //if (publicServiceLifeCycleItem.Removed) // throw new ApiException("Levensloopfase werd verwijderd.", StatusCodes.Status410Gone); return(Ok( new LifeCycleStageResponse( publicServiceLifeCycleItem.LifeCycleStageType, PublicServiceRegistry.LifeCycleStageType.Parse(publicServiceLifeCycleItem.LifeCycleStageType).Translation.Name, publicServiceLifeCycleItem.From, publicServiceLifeCycleItem.To))); }
public DvrCodeGenerator( BackofficeContext context, IStreamStore streamStore) { _context = context; _streamStore = streamStore; }
public async Task <IActionResult> Get( [FromServices] BackofficeContext context, [FromRoute] string id, CancellationToken cancellationToken = default) { var projectionPosition = await context.GetProjectionPositionAsync(cancellationToken); Response.Headers.Add(PublicServiceHeaderNames.LastObservedPosition, projectionPosition.ToString()); var publicService = await context .PublicServiceList .AsNoTracking() .SingleOrDefaultAsync(item => item.PublicServiceId == id, cancellationToken); if (publicService == null) { return(NotFound()); } return(Ok( new PublicServiceResponse( publicService.PublicServiceId, publicService.Name, publicService.CompetentAuthorityCode, publicService.CompetentAuthorityName, publicService.ExportToOrafin, publicService.CurrentLifeCycleStageType, !string.IsNullOrEmpty(publicService.CurrentLifeCycleStageType) ? PublicServiceRegistry.LifeCycleStageType.Parse(publicService.CurrentLifeCycleStageType).Translation.Name : string.Empty, publicService.IpdcCode, publicService.LegislativeDocumentId))); }
public static async Task Assert(this ConnectedProjectionTestSpecification <BackofficeContext> specification) { if (specification == null) { throw new ArgumentNullException(nameof(specification)); } var options = new DbContextOptionsBuilder <BackofficeContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; using (var context = new BackofficeContext(options)) { context.Database.EnsureCreated(); foreach (var message in specification.Messages) { await new ConnectedProjector <BackofficeContext>(specification.Resolver) .ProjectAsync(context, message); await context.SaveChangesAsync(); } var result = await specification.Verification(context, CancellationToken.None); if (result.Failed) { throw new AssertionFailedException(result.Message); } } }
public async Task <IActionResult> GetLifeCyclePhase( [FromServices] BackofficeContext context, [FromRoute] string id, [FromRoute] int faseId, CancellationToken cancellationToken = default) { var projectionPosition = await context.GetProjectionPositionAsync(nameof(PublicServiceLifeCycleListProjections), cancellationToken); Response.Headers.Add(PublicServiceHeaderNames.LastObservedPosition, projectionPosition.ToString()); var publicService = await context .PublicServiceLifeCycleList .AsNoTracking() .SingleOrDefaultAsync(item => item.PublicServiceId == id && item.LifeCycleStageId == faseId, cancellationToken); if (publicService == null) { return(NotFound()); } return(Ok( new LifeCycleStageResponse( publicService.LifeCycleStageType, PublicServiceRegistry.LifeCycleStageType.Parse(publicService.LifeCycleStageType).Translation.Name, publicService.From, publicService.To))); }
private static async Task <object[]> AllRecords(this BackofficeContext context) { var records = new List <object>(); records.AddRange(await context.PublicServiceList.ToArrayAsync()); records.AddRange(await context.PublicServiceLabelList.ToArrayAsync()); return(records.ToArray()); }
public async Task <IActionResult> List( [FromServices] BackofficeContext context, [FromRoute] string id, CancellationToken cancellationToken = default) { return(Ok(await context .PublicServiceLabelList .Where(item => item.PublicServiceId == id) .ToListAsync(cancellationToken))); }
public static async Task <long> GetProjectionPositionAsync(this BackofficeContext context, string projectionName, CancellationToken cancellationToken) { var projectionState = await context .ProjectionStates .AsNoTracking() .SingleOrDefaultAsync(item => item.Name == projectionName, cancellationToken); return(projectionState?.Position ?? -1L); }
public static async Task CheckPublicServiceAsync( this BackofficeContext context, string id, CancellationToken cancellationToken) { var publicService = await context .PublicServiceList .AsNoTracking() .SingleOrDefaultAsync(item => item.PublicServiceId == id, cancellationToken); publicService.CheckPublicService(); }
public async Task <IActionResult> RemoveStageFromLifeCycle( [FromServices] BackofficeContext context, [FromCommandId] Guid commandId, [FromRoute] string id, [FromRoute] int faseId, CancellationToken cancellationToken = default) { await context.CheckPublicServiceAsync(id, cancellationToken); return(Accepted( await Bus.Dispatch( commandId, new RemoveStageFromLifeCycle(new PublicServiceId(id), LifeCycleStageId.FromNumber(faseId)), GetMetadata(), cancellationToken))); }
void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); // testar conexão DB using (var db = new BackofficeContext()) { DbConnection conn = db.Database.Connection; try { conn.Open(); // check the database connection Console.WriteLine("\n\nNICE CONNECTION DB\n\n"); } catch { Console.WriteLine("\n\nFAILLLLLx2 DB\n\n"); } } // StaticBackoffice.bo = new FacadeBackoffice(); //StaticBackoffice.bo.adicionaPetisco("inicio"); //using (var db = new BackofficeContext()) //{ // DbConnection conn = db.Database.Connection; // try // { // conn.Open(); // check the database connection // Console.WriteLine("\n\nNICE CONNECTION DB\n\n"); // } // catch // { // Console.WriteLine("\n\nFAILLLLL DB\n\n"); // } //} // BackofficeContext db = new BackofficeContext(); //String p = (new Random()).Next(100).ToString(); //db.Petiscos.Add(new Petisco { Nome = p }); //db.SaveChanges(); }
public PublicServiceControllerTests() { var dbContextOptions = CreateDbContext(); _existingPublicServiceId = "DVR000000001"; var publicServiceListItem = new PublicServiceListItem { PublicServiceId = _existingPublicServiceId, Name = "Dienstverlening" }; _backofficeContext = new BackofficeContext(dbContextOptions); _backofficeContext.PublicServiceList.Add(publicServiceListItem); _backofficeContext.SaveChanges(); _eventMapping = new EventMapping(EventMapping.DiscoverEventNamesInAssembly(typeof(DomainAssemblyMarker).Assembly)); _eventDeserializer = new EventDeserializer(JsonConvert.DeserializeObject); }
public async Task <IActionResult> List( [FromServices] BackofficeContext context, CancellationToken cancellationToken = default) { var filtering = Request.ExtractFilteringRequest <PublicServiceListItemFilter>(); var sorting = Request.ExtractSortingRequest(); var pagination = Request.ExtractPaginationRequest(); var pagedOrganisations = new PublicServiceListQuery(context) .Fetch(filtering, sorting, pagination); Response.AddPagedQueryResultHeaders(pagedOrganisations); var projectionPosition = await context.GetProjectionPositionAsync(cancellationToken); Response.Headers.Add(PublicServiceHeaderNames.LastObservedPosition, projectionPosition.ToString()); return(Ok(await pagedOrganisations.Items.ToListAsync(cancellationToken))); }
public async Task <IActionResult> Put( [FromServices] BackofficeContext context, [FromCommandId] Guid commandId, [FromRoute] string id, [FromBody] UpdateLabelsRequest updateLabelsRequest, CancellationToken cancellationToken = default) { if (!TryValidateModel(updateLabelsRequest)) { return(BadRequest(ModelState)); } await context.CheckPublicServiceAsync(id, cancellationToken); return(Accepted( await Bus.Dispatch( commandId, UpdateLabelsRequestMapping.Map(id, updateLabelsRequest), GetMetadata(), cancellationToken))); }
public async Task <IActionResult> ChangePeriodOfLifeCycleStage( [FromServices] BackofficeContext context, [FromCommandId] Guid commandId, [FromRoute] string id, [FromRoute] int faseId, [FromBody] ChangePeriodOfLifeCycleStageRequest request, CancellationToken cancellationToken = default) { if (!TryValidateModel(request)) { return(BadRequest(ModelState)); } await context.CheckPublicServiceAsync(id, cancellationToken); return(Accepted( await Bus.Dispatch( commandId, ChangePeriodOfLifeCycleStageRequestMapping.Map(id, faseId, request), GetMetadata(), cancellationToken))); }
public async Task <IActionResult> Post( [FromServices] BackofficeContext context, [FromServices] DvrCodeGenerator dvrCodeGenerator, [FromCommandId] Guid commandId, [FromBody] RegisterPublicServiceRequest registerPublicService, CancellationToken cancellationToken = default) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publicServiceId = await dvrCodeGenerator.GenerateDvrCode(); return(Accepted( $"/v1/dienstverleningen/{publicServiceId}", await Bus.Dispatch( commandId, RegisterPublicServiceRequestMapping.Map(registerPublicService, publicServiceId), GetMetadata(), cancellationToken))); }
public async Task <IActionResult> ListLifeCycleStages( [FromServices] BackofficeContext context, [FromRoute] string id, CancellationToken cancellationToken = default) { var projectionPosition = await context.GetProjectionPositionAsync(nameof(PublicServiceLifeCycleListProjections), cancellationToken); Response.Headers.Add(PublicServiceHeaderNames.LastObservedPosition, projectionPosition.ToString()); // idea: if dienstverleningid does not exist => 404 + documentatie aanpassen swagger var filter = Request.ExtractFilteringRequest <LifeCycleFilter>(); var sorting = Request.ExtractSortingRequest(); var pagination = Request.ExtractPaginationRequest(); var pagedLifeCycle = new LifeCycleQuery(context, id) .Fetch(filter, sorting, pagination); Response.AddPagedQueryResultHeaders(pagedLifeCycle); return(Ok(await pagedLifeCycle.Items.ToListAsync(cancellationToken))); }
public static Task <long> GetProjectionPositionAsync(this BackofficeContext context, CancellationToken cancellationToken) => context.GetProjectionPositionAsync(PublicServiceBackofficeRunner.Name, cancellationToken);
public LifeCycleQuery(BackofficeContext context, string publicServiceId) { _context = context; _publicServiceId = publicServiceId; }
public PublicServiceListQuery(BackofficeContext context) => _context = context;
public PublicServiceRepository(BackofficeContext context) => _context = context;
public MsSqlBackofficeCourseRepository(BackofficeContext context) { _context = context; }
public IActionResult List( [FromServices] BackofficeContext context) => Ok(LabelType.All.Select(x => new LabelTypeListResponse(x)));