コード例 #1
0
        public Task <CharacterUpdateResponse> Handle(CharacterUpdateCommand request, CancellationToken cancellationToken)
        {
            var response = new CharacterUpdateResponse {
                Id = request.CharacterId
            };
            var updatedCharacter = _facade.QueryById(request.CharacterId);

            if (updatedCharacter is null)
            {
                response.WithError("Not found", $"Character with id {request.CharacterId} was not found.");
            }
            if (request.CharacterUpdateForm.Episodes.Any(x => Episode.List.All(y => y.Value != x)))
            {
                response.WithError(nameof(request.CharacterUpdateForm.Episodes), $"Some invalid episodes provided.");
            }

            if (response.IsSuccessful)
            {
                Dictionary <string, string> facadeErrors = _facade.TryUpdate(request.CharacterId, request.CharacterUpdateForm);
                foreach (var error in facadeErrors)
                {
                    response.WithError(error.Key, error.Value);
                }
            }
            return(Task.FromResult(response));
        }
コード例 #2
0
        public Task <CharacterQueryResponse> Handle(CharacterQuery request, CancellationToken cancellationToken)
        {
            var character = _facade.QueryById(request.Id);

            if (character is null)
            {
                return(Task.FromResult(new CharacterQueryResponse {
                    Id = request.Id, Errors = new Dictionary <string, string> {
                        { nameof(Character), $"Character with id {request.Id} was not found." }
                    }
                }));
            }
            return(Task.FromResult(new CharacterQueryResponse {
                Id = request.Id, Data = character
            }));
        }