コード例 #1
0
ファイル: UserController.cs プロジェクト: lillo42/book-store
        public async Task <IActionResult> UpdateUser([FromRoute] Guid id, [FromBody] UserResponse user, [FromServices] UserUpdateOperation operation)
        {
            var result = await operation.ExecuteAsync(new UserUpdate
            {
                Id        = id,
                FirstName = user.FirstName,
                LastNames = user.LastNames,
                BirthDate = user.BirthDay
            });

            if (result is OkResult <UserResponse> ok)
            {
                return(Ok(ok.Value));
            }

            if (result is ErrorResult error && error.ErrorCode.StartsWith("USR"))
            {
                if (error.ErrorCode == DomainError.UserError.UserNotFound.ErrorCode)
                {
                    return(NotFound(error));
                }

                return(UnprocessableEntity(error));
            }

            return(BadRequest(result));
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: lillo42/book-store
        public async Task <IActionResult> Create([FromBody] UserResponse user, [FromServices] UserCreateOperation operation)
        {
            var result = await operation.ExecuteAsync(new UserAdd
            {
                FirstName = user.FirstName,
                LastNames = user.LastNames,
                BirthDate = user.BirthDay,
                Email     = user.Email
            });

            if (result is OkResult <UserResponse> ok)
            {
                return(Created("", ok.Value));
            }

            if (result is ErrorResult error && error.ErrorCode.StartsWith("USR"))
            {
                return(UnprocessableEntity(error));
            }

            return(BadRequest(result));
        }