コード例 #1
0
        [ProducesResponseType(409)] // User with same ID or email already exists
        public async Task <IActionResult> PostAsync(string userId, [FromBody] UserArgs args)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_userIndex.TryGetInternalId(userId, out var _))
            {
                return(StatusCode(409, new { Message = $"A user with ID '{userId}' already exists" }));
            }

            if (_userIndex.IsEmailInUse(args.Email))
            {
                return(StatusCode(409, new { Message = $"A user with email address '{args.Email}' already exists" }));
            }

            var user = new UserEventArgs
            {
                UserId    = userId,
                Email     = args.Email,
                FirstName = args.FirstName,
                LastName  = args.LastName,
            };
            var id = _entityIndex.NextId(ResourceTypes.User);

            await EntityManager.CreateEntityAsync(_eventStore, user, ResourceTypes.User, id, User.Identity.GetUserIdentity());

            return(Created($"{Request.Scheme}://{Request.Host}/api/Users/{userId}", userId));
        }
コード例 #2
0
        public async Task <IActionResult> PostAsync([FromBody] TagArgs args)
        {
            ValidateTagArgs(args);

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

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

            if (_tagIndex.IsTitleExist(args.Title))
            {
                return(StatusCode(409));
            }

            int id = _entityIndex.NextId(ResourceType.Tag);

            var ev = new TagCreated
            {
                Id         = id,
                UserId     = User.Identity.GetUserIdentity(),
                Properties = args,
                Timestamp  = DateTimeOffset.Now
            };

            await _eventStore.AppendEventAsync(ev);

            return(Created($"{Request.Scheme}://{Request.Host}/api/Tags/{id}", id));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        public async Task <IActionResult> PostAsync([FromBody] FooArgs args)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = _entityIndex.NextId(ResourceTypes.Foo);
            await EntityManager.CreateEntityAsync(_eventStore, args, ResourceTypes.Foo, id, User.Identity.GetUserIdentity());

            return(Created($"{Request.Scheme}://{Request.Host}/api/Foo/{id}", id));
        }
コード例 #5
0
        public async Task <IActionResult> Post([FromBody] TArgs args)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (User.Identity.GetUserIdentity() == null)
            {
                return(Forbid());
            }

            var validationResult = await ValidateActionArgs(args);

            if (!validationResult.Success)
            {
                return(validationResult.ActionResult);
            }

            var id = _entityIndex.NextId(ResourceTypes.Action);
            await EntityManager.CreateEntityAsync(_eventStore, args, ResourceType, id, User.Identity.GetUserIdentity());

            return(Created($"{Request.Scheme}://{Request.Host}/api/Action/{id}", id));
        }
コード例 #6
0
        public async Task <IActionResult> PostAsync([FromBody] ExhibitPageArgs2 args)
        {
            // if font family is not specified, fallback to the configured default font family
            if (args != null && args.FontFamily == null)
            {
                args.FontFamily = _exhibitPagesConfig.Value.DefaultFontFamily;
            }

            ValidateExhibitPageArgs(args);

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

            // ReSharper disable once PossibleNullReferenceException (args == null is handled through ModelState.IsValid)
            if (!UserPermissions.IsAllowedToCreate(User.Identity, args.Status))
            {
                return(Forbid());
            }

            // validation passed, emit event
            var newPageId = _entityIndex.NextId(ResourceType.ExhibitPage);

            var ev = new ExhibitPageCreated3
            {
                Id         = newPageId,
                UserId     = User.Identity.GetUserIdentity(),
                Properties = args,
                Timestamp  = DateTimeOffset.Now
            };

            await _eventStore.AppendEventAsync(ev);

            return(Created($"{Request.Scheme}://{Request.Host}/api/Exhibits/Pages/{newPageId}", newPageId));
        }