示例#1
0
        public async Task <CommandResponse <Location> > Handle(LocationSaveCommand request, CancellationToken cancellationToken)
        {
            var result = new CommandResponse <Location>()
            {
                Errors = GetRequestErrors(request)
            };

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

                    result.Result = (Location)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(LocationSaveCommand request)
        {
            var issues = _validator.Validate((Location)request.Item).Errors;

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