Ejemplo n.º 1
0
        private void UpdateWrongValues(System.Data.Common.DbConnection connection, SqlServerValidationToolkitContext ctx)
        {
            string q = CompiledQuery;
            var    c = connection.CreateCommand();

            c.CommandText = q;
            var reader = c.ExecuteReader();

            List <WrongValue> correctedWrongValues = Validation_WrongValue.ToList();

            while (reader.Read())
            {
                //the query returns the id of the invalid value and the errortype-id
                int invalidValueId = reader.GetInt32(0);

                string errorTypeCode = reader.GetString(1);


                WrongValue existingWrongValue = Validation_WrongValue
                                                .SingleOrDefault(wv =>
                                                                 wv.Errortype.CodeForValidationQueries == errorTypeCode
                                                                 &&
                                                                 wv.Id == invalidValueId
                                                                 );

                string value = GetValue(invalidValueId, connection);

                if (existingWrongValue == null)
                {
                    ErrorType errorType = ctx.Errortypes.Where(et => et.CodeForValidationQueries == errorTypeCode).SingleOrDefault();

                    if (errorType == null) //errorType should exist
                    {
                        throw new Exception("ErrorType not found for code '" + errorTypeCode + "'");
                    }

                    WrongValue wrongValue = new WrongValue()
                    {
                        Errortype = errorType,
                        Id        = invalidValueId,
                        Value     = value
                    };
                    Validation_WrongValue.Add(wrongValue);
                }
                else
                {
                    existingWrongValue.Value = value;
                    correctedWrongValues.Remove(existingWrongValue);
                }
            }

            _log.Info(string.Format("{0} wrong values are corrected", correctedWrongValues.Count));
            foreach (var wvCorrected in correctedWrongValues)
            {
                wvCorrected.Is_Corrected = true;
            }
        }
 public WrongValueViewModel(WrongValue wrongValue)
 {
     _wrongValue = wrongValue;
 }