コード例 #1
0
        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)));
        }
コード例 #2
0
 public DvrCodeGenerator(
     BackofficeContext context,
     IStreamStore streamStore)
 {
     _context     = context;
     _streamStore = streamStore;
 }
コード例 #3
0
        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);
                }
            }
        }
コード例 #5
0
        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());
        }
コード例 #7
0
 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)));
 }
コード例 #8
0
        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();
        }
コード例 #10
0
        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)));
        }
コード例 #11
0
        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);
        }
コード例 #13
0
        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)));
        }
コード例 #14
0
        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)));
        }
コード例 #15
0
        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)));
        }
コード例 #16
0
        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)));
        }
コード例 #17
0
        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)));
        }
コード例 #18
0
 public static Task <long> GetProjectionPositionAsync(this BackofficeContext context, CancellationToken cancellationToken)
 => context.GetProjectionPositionAsync(PublicServiceBackofficeRunner.Name, cancellationToken);
コード例 #19
0
 public LifeCycleQuery(BackofficeContext context, string publicServiceId)
 {
     _context         = context;
     _publicServiceId = publicServiceId;
 }
コード例 #20
0
 public PublicServiceListQuery(BackofficeContext context) => _context = context;
コード例 #21
0
 public PublicServiceRepository(BackofficeContext context) => _context = context;
コード例 #22
0
 public MsSqlBackofficeCourseRepository(BackofficeContext context)
 {
     _context = context;
 }
コード例 #23
0
 public IActionResult List(
     [FromServices] BackofficeContext context) =>
 Ok(LabelType.All.Select(x => new LabelTypeListResponse(x)));