Ejemplo n.º 1
0
        public override IDataValidationResult <TKey> Deleting(TKey id, object arg, IDataValidationResults <TKey> validationResults)
        {
            IDataValidationResult <TKey> result = null;
            TXPORole role = arg as TXPORole;

            if (role != null)
            {
                int userCount = (int)role.Session.Evaluate(typeof(XpoDxUser),
                                                           CriteriaOperator.Parse("Count"),
                                                           CriteriaOperator.Parse("Roles[Id == ?]", role.ID));
                if (userCount > 0)
                {
                    result = new DataValidationResult <TKey>
                    {
                        ResultType = DataValidationResultType.Error,
                        ID         = role.ID,
                        Message    = String.Format("Role '{0}' cannot be deleted because there are users in this Role", role.Name)
                    }
                }
                ;
            }

            if (result == null)
            {
                result = base.Deleting(id, arg, validationResults);
            }
            validationResults.Add(result);
            return(result);
        }
    }
Ejemplo n.º 2
0
        private static IDataValidationResults Validate(IDataValidationResults result, DataSet dataSet, int maxErrorRows, bool recursive)
        {
            foreach (var dataRow in dataSet)
            {
                if (maxErrorRows > 0 && result.Count >= maxErrorRows)
                {
                    return(result);
                }

                var errors = dataRow.Validate();
                if (errors != null && errors.Count > 0)
                {
                    result = result.Add(new DataValidationResult(dataRow, errors));
                }

                if (recursive)
                {
                    var childModels = dataSet.Model.ChildModels;
                    foreach (var childModel in childModels)
                    {
                        var childDataSet = dataRow[childModel];
                        result = Validate(result, childDataSet, maxErrorRows, recursive);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public override IDataValidationResult <TKey> Deleting(TKey id, IDataValidationResults <TKey> validationResults, params object[] args)
        {
            if (args == null || args.Length == 0)
            {
                throw new ArgumentNullException("args[0] should contain reference to XPO entity");
            }
            IDataValidationResult <TKey> result = null;
            TXPORole role = args[0] as TXPORole;

            if (role != null)
            {
                int userCount = (int)role.Session.Evaluate(typeof(XpoDxUser),
                                                           CriteriaOperator.Parse("Count"),
                                                           CriteriaOperator.Parse("Roles[Id == ?]", role.ID));
                if (userCount > 0)
                {
                    result = new DataValidationResult <TKey>
                    {
                        ResultType = DataValidationResultType.Error,
                        ID         = role.ID,
                        Message    = String.Format("Role '{0}' cannot be deleted because there are users in this Role", role.Name)
                    }
                }
                ;
            }

            if (result == null)
            {
                result = base.Deleting(id, validationResults, args);
            }
            validationResults.Add(result);
            return(result);
        }
    }
Ejemplo n.º 4
0
        public override IDataValidationResult <TKey> Updating(TModel model, IDataValidationResults <TKey> validationResults)
        {
            var result = new DataValidationResult <TKey>
            {
                ResultType = DataValidationResultType.Success,
                ID         = model.ID
            };

            validationResults.Add(result);
            return(result);
        }
Ejemplo n.º 5
0
        public override IDataValidationResult <TKey> Inserted(TModel model, TXPOClass dbModel, IDataValidationResults <TKey> validationResults)
        {
            var result = new DataValidationResult <TKey>
            {
                ResultType = DataValidationResultType.Success,
                ID         = dbModel.ID
            };

            validationResults.Add(result);
            return(result);
        }
Ejemplo n.º 6
0
        public override IDataValidationResult <TKey> Deleting(TKey id, object arg, IDataValidationResults <TKey> validationResults)
        {
            var result = new DataValidationResult <TKey>
            {
                ResultType = DataValidationResultType.Success,
                ID         = id
            };

            validationResults.Add(result);
            return(result);
        }
Ejemplo n.º 7
0
        public override IDataValidationResult <TKey> Deleted(TKey id, TXPOClass dbModel, IDataValidationResults <TKey> validationResults)
        {
            var result = new DataValidationResult <TKey>
            {
                ResultType = DataValidationResultType.Success,
                ID         = id
            };

            validationResults.Add(result);
            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Parses JSON into <see cref="IDataValidationResults"/> object.
        /// </summary>
        /// <param name="jsonReader">The <see cref="JsonReader"/>.</param>
        /// <param name="dataSet">The DataSet of validation.</param>
        /// <returns>The <see cref="IDataValidationResults"/> object.</returns>
        public static IDataValidationResults ParseDataValidationResults(this JsonReader jsonReader, DataSet dataSet)
        {
            IDataValidationResults results = DataValidationResults.Empty;

            jsonReader.ExpectToken(JsonTokenKind.SquaredOpen);

            if (jsonReader.PeekToken().Kind == JsonTokenKind.CurlyOpen)
            {
                results = results.Add(jsonReader.ParseDataValidationResult(dataSet));

                while (jsonReader.PeekToken().Kind == JsonTokenKind.Comma)
                {
                    jsonReader.ConsumeToken();
                    results = results.Add(jsonReader.ParseDataValidationResult(dataSet));
                }
            }

            jsonReader.ExpectToken(JsonTokenKind.SquaredClose);

            return(results);
        }