public async Task <IActionResult> PostAsync([FromBody] RouteArgs args)
        {
            ValidateRouteArgs(args);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!UserPermissions.IsAllowedToCreate(User.Identity, args.Status))
            {
                return(Forbid());
            }

            // validation passed, emit event
            var ev = new RouteCreated
            {
                Id         = _entityIndex.NextId(ResourceType.Route),
                UserId     = User.Identity.GetUserIdentity(),
                Properties = args,
                Timestamp  = DateTimeOffset.Now
            };

            await _eventStore.AppendEventAsync(ev);

            return(Created($"{Request.Scheme}://{Request.Host}/api/Routes/{ev.Id}", ev.Id));
        }
Example #2
0
        private void RouteCreated(IDocumentSession session, RouteCreated @event)
        {
            var routeDetails = GetRouteDetails(session, @event.RouteId);

            routeDetails.Status = "Created";
        }