using System; using System.Collections.Generic; using System.Linq; using Quadarax.Foundation.Core.Exceptions; namespace Quadarax.Foundation.Core.Data.Interface.Entity.Dto { public abstract class ResultDto : IDto, IResult { /// /// /// public bool IsSuccess => !Errors.Any(); /// /// /// public IEnumerable Errors { get; set; } //public IEnumerable Errors { get; set; } IEnumerable IResult.Errors => Errors; /// /// /// /// public abstract object GetValue(); protected ResultDto(IEnumerable errors) { Errors = new List(errors.Select(x=>(ErrorMessageDto) x)); //Errors = new List(errors); } protected ResultDto() { Errors = new List(); } public void AppendException(Exception e) { if (e == null) throw new ArgumentNullException(nameof(e)); if (e is CodeException) { Errors = Errors.Append(new ErrorMessageDto(e)); } } public AggregateException ToAggregateException() { if (IsSuccess) return null; var errors = new List(); foreach (var e in Errors) { var addExc = new Exception(e.Message); addExc.SetCode(e.Code); errors.Add(addExc); } return new AggregateException(errors); } } }