Exemplo n.º 1
0
        public SettingValidation()
        {
            Define(s => s.Key)
            .NotNullableAndNotEmpty()
            .WithRequired(SettingConstants.Fields.Key.Label)
            .And
            .MaxLength(SettingConstants.Fields.Key.Length)
            .WithInvalidLength(SettingConstants.Fields.Key.Label,
                               SettingConstants.Fields.Key.Length);

            Define(s => s.Value)
            .MaxLength();

            ValidateInstance.SafeBy((setting, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <Setting, SettingQuery> >();

                if (service.GetByKey(setting.Key).IsDuplicate(setting))
                {
                    context.AddDuplicate <Setting, string>(SettingConstants.Fields.Key.Label,
                                                           s => s.Key);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 2
0
        public RoleValidation()
        {
            Define(r => r.Name).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.RoleEntity_Name));

            Define(r => r.InternalKey);

            Define(r => r.Permissions);

            Define(r => r.Groups);

            Define(r => r.Users);

            ValidateInstance.By((role, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IRoleService>();

                if (service.Get(role.Name, true, false).IsDuplicate(role))
                {
                    context.AddInvalid <RoleEntity, string>(ValidationHelpers.DuplicateValue(Members.RoleEntity_Name, role.Name), r => r.Name);

                    isValid = false;
                }

                if (service.Get(role.InternalKey, true, false).IsDuplicate(role))
                {
                    context.AddInvalid <RoleEntity, Constant>(ValidationHelpers.DuplicateValue(Members.RoleEntity_InternalKey, role.InternalKey), r => r.InternalKey);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 3
0
        public BannedIpValidation()
        {
            Define(bi => bi.IpAdrress).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.BannedIpEntity_IpAdrress)).And.IsIp().WithMessage(ValidationHelpers.InvalidIpAddress(Members.BannedIpEntity_IpAdrress));

            Define(bi => bi.Reason).MaxLength();

            Define(bi => bi.StartDateUtc);

            Define(bi => bi.ExpireDateUtc);

            ValidateInstance.By((bannedIp, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IBannedIpService>();

                if (service.Get(bannedIp.IpAdrress, true, false).IsDuplicate(bannedIp))
                {
                    context.AddInvalid <BannedIpEntity, string>(ValidationHelpers.DuplicateValue(Members.BannedIpEntity_IpAdrress, bannedIp.IpAdrress), bi => bi.IpAdrress);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 4
0
        public PermissionGroupValidation()
        {
            Define(pg => pg.Name).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.PermissionGroupEntity_Name));

            Define(pg => pg.InternalKey);

            Define(pg => pg.Permissions);

            Define(pg => pg.Roles);

            ValidateInstance.By((group, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IPermissionGroupService>();

                if (service.Get(group.Name, true, false).IsDuplicate(group))
                {
                    context.AddInvalid <PermissionGroupEntity, string>(ValidationHelpers.DuplicateValue(Members.PermissionGroupEntity_Name, group.Name), pg => pg.Name);

                    isValid = false;
                }

                if (service.Get(group.InternalKey, true, false).IsDuplicate(group))
                {
                    context.AddInvalid <PermissionGroupEntity, Constant>(ValidationHelpers.DuplicateValue(Members.PermissionGroupEntity_InternalKey, group.InternalKey), pg => pg.InternalKey);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 5
0
        public SuricatoDef()
        {
            var attribute = new AssertAnimalAttribute();

            attribute.Message = "is not an animal";
            ValidateInstance.Using(attribute);
        }
        public MeetingDef()
        {
            Define(x => x.Name).NotNullableAndNotEmpty();
            Define(x => x.Description).NotNullableAndNotEmpty();

            ValidateInstance.Using(new ValidRangeAttribute());
        }
        public ResourceValueValidation()
        {
            Define(rv => rv.Language)
            .NotNullable()
            .WithRequired(ResourceValueConstants.Fields.Language.Label);

            Define(rv => rv.Key)
            .NotNullable()
            .WithRequired(ResourceValueConstants.Fields.Key.Label);

            Define(rv => rv.Value)
            .MaxLength();

            ValidateInstance.SafeBy((resourceValue, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <ResourceValue, ResourceValueQuery> >();

                if (service.GetByLanguageIdAndKey(resourceValue.LanguageId, resourceValue.Key.Key).IsDuplicate(resourceValue))
                {
                    context.AddDuplicate <ResourceValue, long>(ResourceValueConstants.Fields.Key.Label,
                                                               rv => rv.KeyId);

                    context.AddDuplicate <ResourceValue, long>(ResourceValueConstants.Fields.Language.Label,
                                                               rv => rv.LanguageId);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 8
0
        public SubscriptionValidation()
        {
            Define(s => s.Email).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.SubscriptionEntity_Email)).And.IsEmail().WithMessage(ValidationHelpers.InvalidEmail(Members.SubscriptionEntity_Email));

            Define(s => s.Status);

            Define(s => s.SubscribDateUtc);

            Define(s => s.ConfirmDateUtc);

            Define(s => s.CancelDateUtc);

            ValidateInstance.By((subscription, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <ISubscriptionService>();

                if (service.Get(subscription.Email, true, false).IsDuplicate(subscription))
                {
                    context.AddInvalid <SubscriptionEntity, string>(ValidationHelpers.DuplicateValue(Members.SubscriptionEntity_Email, subscription.Email), s => s.Email);

                    isValid = false;
                }

                return(isValid);
            });
        }
        public ActivityTypeValidation()
        {
            Define(at => at.SystemName)
            .NotNullableAndNotEmpty()
            .WithRequired(ActivityTypeConstants.Fields.SystemName.Label)
            .And
            .MaxLength(ActivityTypeConstants.Fields.SystemName.Length)
            .WithInvalidLength(ActivityTypeConstants.Fields.SystemName.Label, ActivityTypeConstants.Fields.SystemName.Length);

            Define(at => at.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(ActivityTypeConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(ActivityTypeConstants.Fields.DisplayName.Length)
            .WithInvalidLength(ActivityTypeConstants.Fields.DisplayName.Label, ActivityTypeConstants.Fields.DisplayName.Length);

            Define(at => at.Description)
            .MaxLength();

            ValidateInstance.SafeBy((activityType, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <ActivityType, ActivityTypeQuery> >();

                if (service.GetBySystemName(activityType.SystemName).IsDuplicate(activityType))
                {
                    context.AddDuplicate <ActivityType, string>(ActivityTypeConstants.Fields.SystemName.Label,
                                                                at => at.SystemName);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 10
0
        public ScheduleTaskValidation()
        {
            Define(st => st.SystemName)
            .NotNullableAndNotEmpty()
            .WithRequired(ScheduleTaskConstants.Fields.SystemName.Label)
            .And
            .MaxLength(ScheduleTaskConstants.Fields.SystemName.Length)
            .WithInvalidLength(ScheduleTaskConstants.Fields.SystemName.Label,
                               ScheduleTaskConstants.Fields.SystemName.Length);

            Define(st => st.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(ScheduleTaskConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(ScheduleTaskConstants.Fields.DisplayName.Length)
            .WithInvalidLength(ScheduleTaskConstants.Fields.DisplayName.Label,
                               ScheduleTaskConstants.Fields.DisplayName.Length);

            Define(st => st.TypeName)
            .NotNullableAndNotEmpty()
            .WithRequired(ScheduleTaskConstants.Fields.TypeName.Label)
            .And
            .MaxLength(ScheduleTaskConstants.Fields.TypeName.Length)
            .WithInvalidLength(ScheduleTaskConstants.Fields.TypeName.Label,
                               ScheduleTaskConstants.Fields.TypeName.Length);

            Define(st => st.Description)
            .MaxLength();

            Define(st => st.ExecutionPriority);

            Define(st => st.IsActive);

            Define(st => st.StopOnError);

            Define(st => st.MaximumRunningSeconds)
            .GreaterThanOrEqualTo(ScheduleTaskConstants.Fields.MaximumRunningSeconds.MinValue)
            .WithInvalidMinValue(ScheduleTaskConstants.Fields.MaximumRunningSeconds.Label,
                                 ScheduleTaskConstants.Fields.MaximumRunningSeconds.MinValue);

            ValidateInstance.SafeBy((scheduleTask, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <ScheduleTask, ScheduleTaskQuery> >();

                if (service.GetBySystemName(scheduleTask.SystemName).IsDuplicate(scheduleTask))
                {
                    context.AddDuplicate <ScheduleTask, string>(ScheduleTaskConstants.Fields.SystemName.Label,
                                                                st => st.SystemName);

                    isValid = false;
                }

                return(isValid);
            });
        }
        public MessageTemplateValidation()
        {
            Define(mt => mt.SystemName)
            .NotNullableAndNotEmpty()
            .WithRequired(MessageTemplateConstants.Fields.SystemName.Label)
            .And
            .MaxLength(MessageTemplateConstants.Fields.SystemName.Length)
            .WithInvalidLength(MessageTemplateConstants.Fields.SystemName.Label,
                               MessageTemplateConstants.Fields.SystemName.Length);

            Define(mt => mt.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(MessageTemplateConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(MessageTemplateConstants.Fields.DisplayName.Length)
            .WithInvalidLength(MessageTemplateConstants.Fields.DisplayName.Label,
                               MessageTemplateConstants.Fields.DisplayName.Length);

            Define(mt => mt.Description)
            .MaxLength();

            Define(mt => mt.BccEmailAddresses)
            .MaxLength();

            Define(mt => mt.Subject)
            .MaxLength(MessageTemplateConstants.Fields.Subject.Length)
            .WithInvalidLength(MessageTemplateConstants.Fields.Subject.Label,
                               MessageTemplateConstants.Fields.Subject.Length);

            Define(mt => mt.Body)
            .MaxLength();

            Define(mt => mt.EmailAccount)
            .NotNullable()
            .WithRequired(MessageTemplateConstants.Fields.EmailAccount.Label);

            ValidateInstance.SafeBy((messageTemplate, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <MessageTemplate, MessageTemplateQuery> >();

                if (service.GetBySystemName(messageTemplate.SystemName).IsDuplicate(messageTemplate))
                {
                    context.AddDuplicate <MessageTemplate, string>(MessageTemplateConstants.Fields.SystemName.Label,
                                                                   mt => mt.SystemName);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 12
0
 public EmployeeValidator()
 {
     ValidateInstance.By((employee, context) => {
         bool isValid = true;
         if (string.IsNullOrEmpty(employee.FullName.FirstName))
         {
             isValid = false;
             context.AddInvalid <Employee, string>(
                 "Please enter a first name.", c => c.FullName.FirstName);
         }             // Similar for last name
         return(isValid);
     });
 }
Exemplo n.º 13
0
        public BillingSettingsValidation()
        {
            Define(bs => bs.PricePerTrack)
            .GreaterThanOrEqualTo(BillingSettingsConstants.Fields.PricePerTrack.MinValue)
            .WithInvalidMinValue(BillingSettingsConstants.Fields.PricePerTrack.Label,
                                 BillingSettingsConstants.Fields.PricePerTrack.MinValue);

            Define(bs => bs.PublisherPercentagePerTrack)
            .IncludedBetween(BillingSettingsConstants.Fields.PublisherPercentagePerTrack.MinValue,
                             BillingSettingsConstants.Fields.PublisherPercentagePerTrack.MaxValue)
            .WithInvalidRange(BillingSettingsConstants.Fields.PublisherPercentagePerTrack.Label,
                              BillingSettingsConstants.Fields.PublisherPercentagePerTrack.MinValue,
                              BillingSettingsConstants.Fields.PublisherPercentagePerTrack.MaxValue);

            Define(bs => bs.PricePerAlbum)
            .GreaterThanOrEqualTo(BillingSettingsConstants.Fields.PricePerAlbum.MinValue)
            .WithInvalidMinValue(BillingSettingsConstants.Fields.PricePerAlbum.Label,
                                 BillingSettingsConstants.Fields.PricePerAlbum.MinValue);

            Define(bs => bs.PublisherPercentagePerAlbum)
            .IncludedBetween(BillingSettingsConstants.Fields.PublisherPercentagePerAlbum.MinValue,
                             BillingSettingsConstants.Fields.PublisherPercentagePerAlbum.MaxValue)
            .WithInvalidRange(BillingSettingsConstants.Fields.PublisherPercentagePerAlbum.Label,
                              BillingSettingsConstants.Fields.PublisherPercentagePerAlbum.MinValue,
                              BillingSettingsConstants.Fields.PublisherPercentagePerAlbum.MaxValue);

            Define(bs => bs.MaximumAccessTries);

            Define(bs => bs.Payer);

            Define(bs => bs.MerchantId)
            .MaxLength();

            Define(bs => bs.TransactionKey)
            .MaxLength();

            ValidateInstance.SafeBy((billingSettings, context) => {
                var isValid = true;

                if (billingSettings.PricePerTrack > billingSettings.PricePerAlbum)
                {
                    context.AddLocalizedInvalid <BillingSettings, decimal>(BillingSettingsConstants.Messages.PricePerTrackShouldNotBeGreaterThanPricePerAlbum,
                                                                           bs => bs.PricePerTrack);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 14
0
        public MembershipValidation()
        {
            Define(m => m.User).NotNullable().WithMessage(ValidationHelpers.Required(Members.MembershipEntity_User));

            Define(m => m.ConfirmationToken);

            Define(m => m.Password).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.MembershipEntity_Password));

            Define(m => m.CreateDateUtc);

            Define(m => m.LastActivityDateUtc);

            Define(m => m.LastLoginDateUtc);

            Define(m => m.LastPasswordChangeDateUtc);

            Define(m => m.LastPasswordFailureDateUtc);

            Define(m => m.PasswordFailuresSinceLastSuccess);

            Define(m => m.PasswordVerificationToken);

            Define(m => m.PasswordVerificationTokenExpirationDateUtc);

            Define(m => m.PasswordResetRequested);

            Define(m => m.LastLockoutDateUtc);

            Define(m => m.IsLocked);

            Define(m => m.LastIpAddress);

            Define(m => m.AdminComment).MaxLength();

            ValidateInstance.By((membership, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IMembershipService>();

                if (service.Get(membership.User, true, false).IsDuplicate(membership))
                {
                    context.AddInvalid <MembershipEntity, UserEntity>(ValidationHelpers.DuplicateValue(Members.MembershipEntity_User, membership.User), m => m.User);

                    isValid = false;
                }

                return(isValid);
            });
        }
        public EntityAttributeValidation()
        {
            Define(ea => ea.Key)
            .NotNullableAndNotEmpty()
            .WithRequired(EntityAttributeConstants.Fields.Key.Label)
            .And
            .MaxLength(EntityAttributeConstants.Fields.Key.Length)
            .WithInvalidLength(EntityAttributeConstants.Fields.Key.Label,
                               EntityAttributeConstants.Fields.Key.Length);

            Define(ea => ea.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(EntityAttributeConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(EntityAttributeConstants.Fields.DisplayName.Length)
            .WithInvalidLength(EntityAttributeConstants.Fields.DisplayName.Label,
                               EntityAttributeConstants.Fields.DisplayName.Length);

            Define(ea => ea.Value)
            .NotNullableAndNotEmpty()
            .WithRequired(EntityAttributeConstants.Fields.Value.Label)
            .And
            .MaxLength(EntityAttributeConstants.Fields.Value.Length)
            .WithInvalidLength(EntityAttributeConstants.Fields.Value.Label,
                               EntityAttributeConstants.Fields.Value.Length);

            Define(ea => ea.Description)
            .MaxLength();

            ValidateInstance.SafeBy((entityAttribute, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <EntityAttribute, EntityAttributeQuery> >();

                if (service.GetByOwnerIdAndKey(entityAttribute.OwnerId, entityAttribute.Key).IsDuplicate(entityAttribute))
                {
                    context.AddDuplicate <EntityAttribute, long>(OwnableConstantsBase <EntityAttribute> .Fields.OwnerId.Label,
                                                                 ea => ea.OwnerId);

                    context.AddDuplicate <EntityAttribute, string>(EntityAttributeConstants.Fields.Key.Label,
                                                                   ea => ea.Key);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 16
0
        public OrderValidation()
        {
            Define(o => o.Guid)
            .NotEmpty()
            .WithInvalidValue(OrderConstants.Fields.Guid.Label);

            Define(o => o.PlaceDateUtc);

            Define(o => o.Buyer)
            .NotNullable()
            .WithRequired(OrderConstants.Fields.Buyer.Label);

            Define(o => o.BuyerIp)
            .NotNullable()
            .WithRequired(OrderConstants.Fields.BuyerIp.Label)
            .And
            .MaxLength(OrderConstants.Fields.BuyerIp.Length)
            .WithInvalidLength(OrderConstants.Fields.BuyerIp.Label,
                               OrderConstants.Fields.BuyerIp.Length)
            .And
            .IsIp()
            .WithInvalidFormat(OrderConstants.Fields.BuyerIp.Label);

            Define(o => o.Status)
            .NotNullable()
            .WithRequired(OrderConstants.Fields.Status.Label);

            Define(o => o.Lines);

            Define(o => o.Notes);

            Define(o => o.Requests);

            ValidateInstance.SafeBy((order, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <Order, OrderQuery> >();

                if (service.GetByGuid(order.Guid).IsDuplicate(order))
                {
                    context.AddDuplicate <Order, Guid>(OrderConstants.Fields.Guid.Label, o => o.Guid);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 17
0
        public ArtistValidation()
        {
            Define(a => a.FullName)
            .NotNullableAndNotEmpty()
            .WithRequired(ArtistConstants.Fields.FullName.Label)
            .And
            .MaxLength(ArtistConstants.Fields.FullName.Length)
            .WithInvalidLength(ArtistConstants.Fields.FullName.Label,
                               ArtistConstants.Fields.FullName.Length);

            Define(a => a.AlternativeName)
            .MaxLength(ArtistConstants.Fields.AlternativeName.Length)
            .WithInvalidLength(ArtistConstants.Fields.AlternativeName.Label,
                               ArtistConstants.Fields.AlternativeName.Length);

            Define(a => a.HomeTown)
            .MaxLength(ArtistConstants.Fields.HomeTown.Length)
            .WithInvalidLength(ArtistConstants.Fields.HomeTown.Label,
                               ArtistConstants.Fields.HomeTown.Length);

            Define(a => a.Biography)
            .MaxLength();

            ValidateInstance.SafeBy((artist, context) => {
                var isValid = true;

                if (artist.Facebook != null && !string.IsNullOrEmpty(artist.Facebook.TargetUrl))
                {
                    if (artist.Facebook.TargetUrl.Length > ArtistConstants.Fields.Facebook.Length)
                    {
                        context.AddInvalidLength <Artist, Redirector>(ArtistConstants.Fields.Facebook.Label,
                                                                      ArtistConstants.Fields.Facebook.Length,
                                                                      a => a.Facebook);

                        isValid = false;
                    }
                    else if (!CommonHelper.IsValidUrl(artist.Facebook.TargetUrl))
                    {
                        context.AddInvalidFormat <Artist, Redirector>(ArtistConstants.Fields.Facebook.Label,
                                                                      a => a.Facebook);

                        isValid = false;
                    }
                }

                return(isValid);
            });
        }
        public TransactionRequestValidation()
        {
            Define(tr => tr.Order)
            .NotNullable()
            .WithRequired(TransactionRequestConstants.Fields.Order.Label);

            Define(tr => tr.RequestDateUtc);

            Define(tr => tr.MerchantId)
            .NotNullableAndNotEmpty()
            .WithRequired(TransactionRequestConstants.Fields.MerchantId.Label)
            .And
            .MaxLength();

            Define(tr => tr.TransactionKey)
            .NotNullableAndNotEmpty()
            .WithRequired(TransactionRequestConstants.Fields.TransactionKey.Label)
            .And
            .MaxLength();

            Define(tr => tr.ComputedHash)
            .NotNullableAndNotEmpty()
            .WithRequired(TransactionRequestConstants.Fields.ComputedHash.Label)
            .And
            .MaxLength();

            Define(tr => tr.IsPending);
            Define(tr => tr.IsVerified);

            Define(tr => tr.Responses);

            ValidateInstance.SafeBy((transactionRequest, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <TransactionRequest, TransactionRequestQuery> >();

                if (service.GetByComputedHash(transactionRequest.ComputedHash).IsDuplicate(transactionRequest))
                {
                    context.AddDuplicate <TransactionRequest, string>(TransactionRequestConstants.Fields.ComputedHash.Label,
                                                                      tr => tr.ComputedHash);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 19
0
        public PermissionRecordValidation()
        {
            Define(pr => pr.SystemName)
            .NotNullableAndNotEmpty()
            .WithRequired(PermissionRecordConstants.Fields.SystemName.Label)
            .And
            .MaxLength(PermissionRecordConstants.Fields.SystemName.Length)
            .WithInvalidLength(PermissionRecordConstants.Fields.SystemName.Label,
                               PermissionRecordConstants.Fields.SystemName.Length);

            Define(pr => pr.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(PermissionRecordConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(PermissionRecordConstants.Fields.DisplayName.Length)
            .WithInvalidLength(PermissionRecordConstants.Fields.DisplayName.Label,
                               PermissionRecordConstants.Fields.DisplayName.Length);

            Define(pr => pr.Category)
            .MaxLength(PermissionRecordConstants.Fields.Category.Length)
            .WithInvalidLength(PermissionRecordConstants.Fields.Category.Label,
                               PermissionRecordConstants.Fields.Category.Length);

            Define(pr => pr.Description)
            .MaxLength();

            Define(pr => pr.Roles);

            ValidateInstance.SafeBy((permissionRecord, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <PermissionRecord, PermissionRecordQuery> >();

                if (service.GetBySystemName(permissionRecord.SystemName).IsDuplicate(permissionRecord))
                {
                    context.AddDuplicate <PermissionRecord, string>(PermissionRecordConstants.Fields.SystemName.Label,
                                                                    pr => pr.SystemName);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 20
0
        public UserAttributeValidation()
        {
            Define(ua => ua.User).NotNullable().WithMessage(ValidationHelpers.Required(Members.UserAttributeEntity_User));

            ValidateInstance.By((userAttribute, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IUserAttributeService>();

                if (DuplicationExtentions.IsDuplicate(service.Get(userAttribute.User, userAttribute.Key, true, false), userAttribute))
                {
                    context.AddInvalid(ValidationHelpers.DuplicateValues(Tuple.Create(Members.UserAttributeEntity_User, (object)userAttribute.User), Tuple.Create(Members.AttributeEntityBase_Key, (object)userAttribute.Key)));

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 21
0
        public RoleValidation()
        {
            Define(r => r.SystemName)
            .NotNullableAndNotEmpty()
            .WithRequired(RoleConstants.Fields.SystemName.Label)
            .And
            .MaxLength(RoleConstants.Fields.SystemName.Length)
            .WithInvalidLength(RoleConstants.Fields.SystemName.Label,
                               RoleConstants.Fields.SystemName.Length);

            Define(r => r.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(RoleConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(RoleConstants.Fields.DisplayName.Length)
            .WithInvalidLength(RoleConstants.Fields.DisplayName.Label,
                               RoleConstants.Fields.DisplayName.Length);

            Define(r => r.Description);

            Define(r => r.IsActive);

            Define(r => r.Records);

            Define(r => r.Users);

            ValidateInstance.SafeBy((role, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <Role, RoleQuery> >();

                if (service.GetBySystemName(role.SystemName).IsDuplicate(role))
                {
                    context.AddDuplicate <Role, string>(RoleConstants.Fields.SystemName.Label,
                                                        r => r.SystemName);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 22
0
        public NewsletterSubscriptionValidation()
        {
            Define(ns => ns.Email)
            .NotNullableAndNotEmpty()
            .WithRequired(NewsletterSubscriptionConstants.Fields.Email.Label)
            .And
            .MaxLength(NewsletterSubscriptionConstants.Fields.Email.Length)
            .WithInvalidLength(NewsletterSubscriptionConstants.Fields.Email.Label,
                               NewsletterSubscriptionConstants.Fields.Email.Length)
            .And
            .IsEmail()
            .WithInvalidFormat(NewsletterSubscriptionConstants.Fields.Email.Label);

            Define(ns => ns.Guid)
            .NotEmpty()
            .WithInvalidValue(NewsletterSubscriptionConstants.Fields.Guid.Label);

            ValidateInstance.SafeBy((newsletterSubscription, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <NewsletterSubscription, NewsletterSubscriptionQuery> >();

                if (service.GetByEmail(newsletterSubscription.Email).IsDuplicate(newsletterSubscription))
                {
                    context.AddDuplicate <NewsletterSubscription, string>(NewsletterSubscriptionConstants.Fields.Email.Label,
                                                                          ns => ns.Email);

                    isValid = false;
                }

                if (service.GetByGuid(newsletterSubscription.Guid).IsDuplicate(newsletterSubscription))
                {
                    context.AddDuplicate <NewsletterSubscription, Guid>(NewsletterSubscriptionConstants.Fields.Guid.Label,
                                                                        ns => ns.Guid);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 23
0
        public OAuthTokenValidation()
        {
            Define(oat => oat.Token).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.OAuthTokenEntity_Token));

            Define(oat => oat.Token).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.OAuthTokenEntity_Secret));

            ValidateInstance.By((oauthToken, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IOAuthTokenService>();

                if (service.Get(oauthToken.Token, true, false).IsDuplicate(oauthToken))
                {
                    context.AddInvalid <OAuthTokenEntity, Constant>(ValidationHelpers.DuplicateValue(Members.OAuthTokenEntity_Token, oauthToken.Token), oat => oat.Token);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 24
0
        public SettingValidation()
        {
            Define(s => s.Key).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.SettingEntity_Key));

            Define(s => s.Value).MaxLength();

            ValidateInstance.By((setting, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <ISettingService>();

                if (service.Get(setting.Key, true, false).IsDuplicate(setting))
                {
                    context.AddInvalid <SettingEntity, string>(ValidationHelpers.DuplicateValue(Members.SettingEntity_Key, setting.Key), s => s.Key);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 25
0
        public PollVotingRecordValidation()
        {
            Define(pvr => pvr.SelectedItem)
            .NotNullable()
            .WithRequired(PollVotingRecordConstants.Fields.SelectedItem.Label);

            ValidateInstance.SafeBy((pollVotingRecord, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <PollVotingRecord, PollVotingRecordQuery> >();

                if (pollVotingRecord.IsTransient() || service.AlreadyVoted(pollVotingRecord.SelectedItem.Choice.PollId, pollVotingRecord.VoterId))
                {
                    context.AddLocalizedInvalid <PollVotingRecord, PollVotingRecord>(PollVotingRecordConstants.Messages.AlreadyVoted,
                                                                                     pvr => pvr);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 26
0
        public TicketDepartmentValidation()
        {
            Define(td => td.SystemName)
            .NotNullableAndNotEmpty()
            .WithRequired(TicketDepartmentConstants.Fields.SystemName.Label)
            .And
            .MaxLength(TicketDepartmentConstants.Fields.SystemName.Length)
            .WithInvalidLength(TicketDepartmentConstants.Fields.SystemName.Label,
                               TicketDepartmentConstants.Fields.SystemName.Length);

            Define(td => td.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(TicketDepartmentConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(TicketDepartmentConstants.Fields.DisplayName.Length)
            .WithInvalidLength(TicketDepartmentConstants.Fields.DisplayName.Label,
                               TicketDepartmentConstants.Fields.DisplayName.Length);

            Define(td => td.Description)
            .MaxLength();

            Define(td => td.Tickets);

            ValidateInstance.SafeBy((redirector, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <TicketDepartment, TicketDepartmentQuery> >();

                if (service.GetBySystemName(redirector.SystemName).IsDuplicate(redirector))
                {
                    context.AddDuplicate <TicketDepartment, string>(TicketDepartmentConstants.Fields.SystemName.Label,
                                                                    td => td.SystemName);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 27
0
        public OrderStatusValidation()
        {
            Define(os => os.SystemName)
            .NotNullableAndNotEmpty()
            .WithRequired(OrderStatusConstants.Fields.SystemName.Label)
            .And
            .MaxLength(OrderStatusConstants.Fields.SystemName.Length)
            .WithInvalidLength(OrderStatusConstants.Fields.SystemName.Label,
                               OrderStatusConstants.Fields.SystemName.Length);

            Define(os => os.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(OrderStatusConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(OrderStatusConstants.Fields.DisplayName.Length)
            .WithInvalidLength(OrderStatusConstants.Fields.DisplayName.Label,
                               OrderStatusConstants.Fields.DisplayName.Length);

            Define(os => os.Description)
            .MaxLength();

            Define(os => os.Orders);

            ValidateInstance.SafeBy((orderStatus, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <OrderStatus, OrderStatusQuery> >();

                if (service.GetBySystemName(orderStatus.SystemName).IsDuplicate(orderStatus))
                {
                    context.AddDuplicate <OrderStatus, string>(OrderStatusConstants.Fields.SystemName.Label,
                                                               os => os.SystemName);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 28
0
        public ResourceKeyValidation()
        {
            Define(rk => rk.Key)
            .NotNullableAndNotEmpty()
            .WithRequired(ResourceKeyConstants.Fields.Key.Label)
            .And
            .MaxLength(ResourceKeyConstants.Fields.Key.Length)
            .WithInvalidLength(ResourceKeyConstants.Fields.Key.Label,
                               ResourceKeyConstants.Fields.Key.Length);

            Define(rk => rk.DisplayName)
            .NotNullableAndNotEmpty()
            .WithRequired(ResourceKeyConstants.Fields.DisplayName.Label)
            .And
            .MaxLength(ResourceKeyConstants.Fields.DisplayName.Length)
            .WithInvalidLength(ResourceKeyConstants.Fields.DisplayName.Label,
                               ResourceKeyConstants.Fields.DisplayName.Length);

            Define(rk => rk.Description)
            .MaxLength();

            Define(rk => rk.Values);

            ValidateInstance.SafeBy((resourceKey, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IDbService <ResourceKey, ResourceKeyQuery> >();

                if (service.GetByKey(resourceKey.Key).IsDuplicate(resourceKey))
                {
                    context.AddDuplicate <ResourceKey, string>(ResourceKeyConstants.Fields.Key.Label,
                                                               rk => rk.Key);

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 29
0
        public OAuthValidation()
        {
            Define(oa => oa.ProviderKey).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.OAuthEntity_ProviderKey));

            Define(oa => oa.UserKey).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.OAuthEntity_UserKey));

            Define(oa => oa.User);

            ValidateInstance.By((oauth, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IOAuthService>();

                if (service.Get(oauth.ProviderKey, oauth.UserKey, true, false).IsDuplicate(oauth))
                {
                    context.AddInvalid(ValidationHelpers.DuplicateValues(Tuple.Create(Members.OAuthEntity_ProviderKey, (object)oauth.ProviderKey), Tuple.Create(Members.OAuthEntity_UserKey, (object)oauth.UserKey)));

                    isValid = false;
                }

                return(isValid);
            });
        }
Exemplo n.º 30
0
        public UserValidation()
        {
            Define(u => u.Email).NotNullableAndNotEmpty().WithMessage(ValidationHelpers.Required(Members.UserEntity_Email)).And.IsEmail().WithMessage(ValidationHelpers.InvalidEmail(Members.UserEntity_Email));

            Define(u => u.OAuths);

            Define(u => u.Roles);

            ValidateInstance.By((user, context) => {
                var isValid = true;

                var service = EngineContext.Current.Resolve <IUserService>();

                if (service.Get(user.Email, true, false).IsDuplicate(user))
                {
                    context.AddInvalid <UserEntity, string>(ValidationHelpers.DuplicateValue(Members.UserEntity_Email, user.Email), u => u.Email);

                    isValid = false;
                }

                return(isValid);
            });
        }