コード例 #1
0
        public IEnumerable<ValidationResult> PersistValidationErrors(TakeRateFilter filter, FluentValidation.Results.ValidationResult validationResult, bool global = false)
        {
            var results = new List<ValidationResult>();
            
            _takeRateDataStore.FdpValidationClear(filter);

            foreach (var validationError in validationResult.Errors)
            {
                var state = (ValidationState)validationError.CustomState;
                var validationData = new ValidationResult
                {
                    TakeRateId = state.TakeRateId,

                    ValidationRule = state.ValidationRule,

                    FdpVolumeDataItemId = state.FdpVolumeDataItemId,
                    FdpTakeRateSummaryId = state.FdpTakeRateSummaryId,
                    FdpTakeRateFeatureMixId = state.FdpTakeRateFeatureMixId,
                    FdpChangesetDataItemId = state.FdpChangesetDataItemId,

                    MarketId = state.MarketId,
                    ModelId = state.ModelId,
                    FdpModelId = state.FdpModelId,
                    FeatureId = state.FeatureId,
                    FdpFeatureId = state.FdpFeatureId,
                    FeaturePackId = state.FeaturePackId,
                    ExclusiveFeatureGroup = state.ExclusiveFeatureGroup,

                    Message = validationError.ErrorMessage
                };

                validationData = _takeRateDataStore.FdpValidationPersist(validationData, global);
                results.Add(validationData);

                foreach (var childState in state.ChildStates)
                {
                    validationData = new ValidationResult
                    {
                        TakeRateId = childState.TakeRateId,

                        FdpVolumeDataItemId = childState.FdpVolumeDataItemId,
                        FdpTakeRateSummaryId = childState.FdpTakeRateSummaryId,
                        FdpTakeRateFeatureMixId = childState.FdpTakeRateFeatureMixId,
                        FdpChangesetDataItemId = childState.FdpChangesetDataItemId,

                        ValidationRule = state.ValidationRule,

                        MarketId = childState.MarketId,
                        ModelId = childState.ModelId,
                        FdpModelId = childState.FdpModelId,
                        FeatureId = childState.FdpFeatureId,
                        FdpFeatureId = childState.FdpFeatureId,
                        FeaturePackId = childState.FeaturePackId,

                        Message = validationError.ErrorMessage
                    };
                    validationData = _takeRateDataStore.FdpValidationPersist(validationData, global);
                    results.Add(validationData);
                }
            }
            
            return results;
        }
コード例 #2
0
        public ValidationResult FdpValidationPersist(ValidationResult validationData, bool global = false)
        {
            ValidationResult retVal = null;

            using (var conn = DbHelper.GetDBConnection())
            {
                try
                {
                    // Most validation is performed on a per user basis, except when perfomed on initial data process
                    // If this is the case, we want all users to see the validation
                    DynamicParameters para;
                    if (!global)
                    {
                        para = DynamicParameters.FromCDSId(CurrentCDSID);
                    }
                    else
                    {
                        para = new DynamicParameters();
                        para.Add("@CDSId", "", DbType.String);
                    }
                    para.Add("@FdpVolumeHeaderId", validationData.TakeRateId, DbType.Int32);

                    para.Add("@FdpValidationRuleId", (int)validationData.ValidationRule, DbType.Int32);

                    para.Add("@MarketId", validationData.MarketId, DbType.Int32);
                    para.Add("@ModelId", validationData.ModelId, DbType.Int32);
                    para.Add("@FdpModelId", validationData.FdpModelId, DbType.Int32);
                    para.Add("@FeatureId", validationData.FeatureId, DbType.Int32);
                    para.Add("@FdpFeatureId", validationData.FdpFeatureId, DbType.Int32);
                    para.Add("@FeaturePackId", validationData.FeaturePackId, DbType.Int32);
                    para.Add("@ExclusiveFeatureGroup", validationData.ExclusiveFeatureGroup, DbType.String);

                    para.Add("@FdpVolumeDataItemId", validationData.FdpVolumeDataItemId, DbType.Int32);
                    para.Add("@FdpTakeRateSummaryId", validationData.FdpTakeRateSummaryId, DbType.Int32);
                    para.Add("@FdpTakeRateFeatureMixId", validationData.FdpTakeRateFeatureMixId, DbType.Int32);
                    para.Add("@FdpPowertrainDataItemId", validationData.FdpPowertrainDataItemId, DbType.Int32);
                    para.Add("@FdpChangesetDataItemId", validationData.FdpChangesetDataItemId, DbType.Int32);

                    para.Add("@Message", validationData.Message, DbType.String);

                    var results = conn.Query<ValidationResult>("dbo.Fdp_Validation_Persist", para, commandType: CommandType.StoredProcedure);
                    var validationResults = results as IList<ValidationResult> ?? results.ToList();
                    if (results != null && validationResults.Any())
                    {
                        retVal = validationResults.First();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    throw;
                }
            }
            return retVal;
        }