Beispiel #1
0
            public async Task <CommandResponse <Schedule> > Handle(ScheduleDeleteCommand request, CancellationToken cancellationToken)
            {
                var result = new CommandResponse <Schedule>()
                {
                    Errors = GetRequestErrors(request)
                };

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

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

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

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