protected override void Execute(Csla.Rules.RuleContext context) { var ce = (CustomerEdit)context.Target; bool result = string.IsNullOrEmpty(ce.Name) || !(from c in ce.Name.ToCharArray() where char.IsDigit(c) select c) .Any(); if (!result) { context.AddErrorResult("Name must consist of only letters."); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (ResourceEdit)context.Target; foreach (var item in target.Assignments) { var count = target.Assignments.Count(r => r.ProjectId == item.ProjectId); if (count > 1) { context.AddErrorResult("Duplicate projects not allowed"); return; } } }
protected override void Execute(Csla.Rules.RuleContext context) { var value = context.InputPropertyValues[PrimaryProperty]; if (value == null || string.IsNullOrWhiteSpace(value.ToString()) || value.ToString() == this.EmptyValue.ToString()) { var message = string.Format(Csla.Properties.Resources.StringRequiredRule, PrimaryProperty.FriendlyName); context.Results.Add(new Csla.Rules.RuleResult(RuleName, PrimaryProperty, message) { Severity = Severity }); } }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (PaymentDetail)context.Target; if (target.AmountPaid == null) { context.AddErrorResult("Amount paid is required"); } else { if (target.AmountPaid > target.AmountDue) { context.AddErrorResult("Amount paid should not exceed amount due."); } } }
private static void HandleResult(Csla.Rules.RuleContext context, MyExpensiveCommand result) { if (result == null) { context.AddErrorResult("Command failed to run"); } else if (result.Result) { context.AddInformationResult(result.ResultText); } else { context.AddErrorResult(result.ResultText); } context.Complete(); }
protected override void Execute(Csla.Rules.RuleContext context) { var target = (RoleEdit)context.Target; RoleEditList parent = (RoleEditList)target.Parent; if (parent != null) { foreach (RoleEdit item in parent) { if (item.Id == target.ReadProperty(IdProperty) && !(ReferenceEquals(item, target))) { context.AddErrorResult("Role Id must be unique"); break; } } } }
protected override void Execute(Csla.Rules.RuleContext context) { MyExpensiveCommand result = null; if (IsAsync) { MyExpensiveCommand.BeginCommand((r) => { result = r; HandleResult(context, result); }); } else { result = MyExpensiveCommand.DoCommand(); HandleResult(context, result); } }
protected async override void Execute(Csla.Rules.RuleContext context) { var tcs = new TaskCompletionSource <bool>(); new Task(() => { var name = (string)context.InputPropertyValues[PrimaryProperty]; tcs.SetResult(string.IsNullOrEmpty(name) || !(from c in name.ToCharArray() where char.IsDigit(c) select c) .Any()); }).Start(); var result = await tcs.Task; if (!result) { context.AddErrorResult("Name must consist of only letters."); } context.Complete(); }
protected override void Execute(Csla.Rules.RuleContext context) { var birthDateProperty = context.InputPropertyValues.Single(p => p.Key.Name == "BirthDateProperty"); var status = "Unknown Date of Birth"; if (birthDateProperty.Value != null) { var birthDate = (DateTime)birthDateProperty.Value; if (birthDate.CompareTo(DateTime.Today) == 0) { status = "Happy Birthday"; } else { status = "It's not your birthday"; } } context.AddOutValue(PrimaryProperty, status); }
protected override void Execute(Csla.Rules.RuleContext context) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, e) => Thread.Sleep(3000); worker.RunWorkerCompleted += (o, e) => { string val = (string)context.InputPropertyValues[PrimaryProperty]; if (val == "Error") { context.AddErrorResult("Invalid data!"); } else if (val == "Warning") { context.AddWarningResult("This might not be a great idea!"); } else if (val == "Information") { context.AddInformationResult("Just an FYI!"); } context.Complete(); }; worker.RunWorkerAsync(); }