예제 #1
0
        public async Task <CommandResponse <Event> > Handle(EventSaveCommand request, CancellationToken cancellationToken)
        {
            var result = new CommandResponse <Event>()
            {
                Errors = GetRequestErrors(request)
            };

            if (result.Errors.Count == 0)
            {
                try
                {
                    var aggregate = new EventAggregate(_dbContext);
                    await aggregate.EventSaveAsync(request.Item);

                    result.Result = (Event)request.Item;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);

                    result.ErrorInfo = new ErrorInfo()
                    {
                        UserErrorMessage = "An internal error has occured",
                        HasException     = true
                    };
                }
            }
            return(result);
        }
예제 #2
0
        private List <KeyValuePair <string, string> > GetRequestErrors(EventSaveCommand request)
        {
            var issues = _validator.Validate((Event)request.Item).Errors;

            foreach (var issue in issues)
            {
                _errors.Add(new KeyValuePair <string, string>(issue.PropertyName, issue.ErrorMessage));
            }
            return(_errors);
        }