/// <summary>
            /// Business or validation rule implementation.
            /// </summary>
            /// <param name="context">Rule context object.</param>
            protected override void Execute(Csla.Rules.RuleContext context)
            {
                base.Execute(context);

                var element = context.Target as SystemOptionsEdit;
                if (element == null) return;

                var list = context.InputPropertyValues[this.InputProperties[0]] as SystemParametersList;

                if (list == null) return;
                
                var duplicates = list.GroupBy(x => x.Name.Trim()).Where(x => x.Count() > 1).Select(k=>k.Key);
            
                if (!duplicates.Any())
                {
                    return;
                }

                context.AddErrorResult("This name already exists: " + duplicates.First());
                _required.Execute(context);
            }
示例#2
0
            protected override void Execute(Csla.Rules.RuleContext context)
            {
                
                var target = (VoucherEdit)context.Target;
                string firstName = (string)ReadProperty(target, FirstProperty);
                string lastName = (string)ReadProperty(target, LastProperty);
                string companyName = (string)ReadProperty(target, CompanyProperty);
                string address1 = (string)ReadProperty(target, AddressLine1Property);
                string municipality = (string)ReadProperty(target, MunicipalityProperty);
                string postalCode = (string)ReadProperty(target, PostalCodeProperty);

                
                if (!string.IsNullOrEmpty(firstName + lastName + companyName) && !string.IsNullOrEmpty(address1) && !string.IsNullOrEmpty(municipality) && !string.IsNullOrEmpty(postalCode) && target.IsDirty )
                
                {
                        //if a complete address then verify against web service
                        var config = ConfigurationManager.AppSettings;
                    var dataCleanEventFactory =
                        new DataCleanEventFactory(
                            new DataCleaner(config),
                            new DataCleanRespository(), 
                            new DataCleanCriteria()
                            {
                                AutoFixAddressLine1 = false,
                                AutoFixCity = false,
                                AutoFixPostalCode = false,
                                AutoFixState = false,
                                ForceValidation = false
                            });

                    var inputAddress = new InputStreetAddress()
                        {
                            AddressLine1 = target.AddressLine1,
                            AddressLine2 = target.AddressLine2,
                            City = target.Municipality,
                            CompanyName = target.Company,
                            Country = target.Country,
                            FirstName = target.First,
                            FullName = target.FullName,
                            LastName = target.Last,
                            PostalCode = target.PostalCode,
                            State = target.Region
                        };

                    var dataCleanEvent = dataCleanEventFactory.ValidateAddress(inputAddress);

                        if (!dataCleanEvent.Output.OkMailingAddress)
                    {
                            var errStr = string.Empty;
                            foreach (var err in dataCleanEvent.Output.Errors)
                            {
                                context.AddErrorResult(err.LongDescription);
                            }
                            
                        }
                        
                }

            }
示例#3
0
            protected override void Execute(Csla.Rules.RuleContext context)
            {
                var target = (VoucherEdit)context.Target;
                string firstName = (string)ReadProperty(target, FirstProperty);
                string lastName = (string)ReadProperty(target, LastProperty);
                string companyName = (string)ReadProperty(target, CompanyProperty);


                if ((string.IsNullOrEmpty(firstName) && string.IsNullOrEmpty(lastName)) && string.IsNullOrEmpty(companyName))
                {
                    context.AddErrorResult("First Name and Last Name Or Company Name Required");
                }
             
            }