private Either <StateChangeError, UpdateRequest> validate (ExchangeData data) { var errors = ExchangeDataValidator.Validate( new ExchangeDataValidationRequest( exchanges: exchanges.All , data: data , checkCodeIsUnique: false // it should exist ) ); return(errors.Count() == 0 ? Either <StateChangeError, UpdateRequest> .Right(new UpdateRequest( data, exchange )) : Either <StateChangeError, UpdateRequest> .Left(new UpdateExchangeError( errors )) ); }
private Either <StateChangeError, ExchangeModel> validate (ExchangeData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } // todo: validator should not have a checkCode is Unique flag need to think about validation and the implications var errors = ExchangeDataValidator.Validate( new ExchangeDataValidationRequest( exchanges: exchanges.All , data: data , checkCodeIsUnique: true ) ); return(errors.Count() == 0 ? Either <StateChangeError, ExchangeModel> .Right(new ExchangeModel { Code = data.Code, Name = data.Name }) : Either <StateChangeError, ExchangeModel> .Left(new AddExchangeError( data.Code, errors )) ); }