public void Validate(RegisterViewModel model, ValidatorAction action = ValidatorAction.Register)
        {
            if (model == null)
            {
                AddError("You provided no data");
                return;
            }

            if (entityService.IsNameTaken(model.Name))
            {
                AddError("Name is taken", () => model.Name);
            }

            if (entityService.IsSpecialName(model.Name))
            {
                AddError("This is special name. You cannot use it", () => model.Name);
            }

            if (citizenRepository.IsEmailAddressAllowed(model.Email) == false)
            {
                AddError("Email address not registered for beta!");
            }
            else if (citizenRepository.IsEmailAddressUsed(model.Email))
            {
                AddError("Email address is already used!");
            }
        }
Example #2
0
        public void Validate(CreateCompanyViewModel model, Entity entity, ValidatorAction action = ValidatorAction.Undefined)
        {
            var wallet       = entity.Wallet;
            var countryMoney = wallet.GetMoney(model.CountryFee.CurrencyID, currencyRepository.GetAll());
            var adminMoney   = wallet.GetMoney(model.AdminFee.CurrencyID, currencyRepository.GetAll());

            if (countryMoney.Amount < model.CountryFee.Quantity)
            {
                AddError("Not enough money", () => model.CountryFee);
            }
            if (adminMoney.Amount < model.AdminFee.Quantity)
            {
                AddError("Not enough gold", () => model.AdminFee);
            }


            if (entityService.IsNameTaken(model.CompanyName))
            {
                AddError("Name is already used!", () => model.CompanyName);
            }

            if (entityService.IsSpecialName(model.CompanyName))
            {
                AddError("This is special name. You cannot use it", () => model.CompanyName);
            }

            if (model.ProducedProductID == (int)ProductTypeEnum.Development)
            {
                AddError("You cannot produce company which produce this kind of product!");
            }
        }
        public override void Validate(LoginViewModel model, ValidatorAction action = ValidatorAction.Login)
        {
            var citizen = citizenRepository.FirstOrDefault(c => c.Entity.Name == model.Name);

            if (citizen == null)
            {
                AddError("Citizen does not exist!", () => model.Name);
            }
            else
            {
                var hash = SHA256.Encode(model.Password);
                if (hash != citizen.Password)
                {
                    AddError("Password does not match!", () => model.Password);
                }
            }
        }
        public override void Validate(SendMessageViewModel model, ValidatorAction action = ValidatorAction.Undefined)
        {
            if (model.RecipientID.HasValue)
            {
                bool exists = entityRepository.Any(e => e.EntityID == model.RecipientID);

                if (!exists)
                {
                    AddError("Recipient does not exists", () => model.RecipientName);
                }
            }
            else
            {
                bool exists = entityRepository.Any(e => e.Name.ToLower() == model.RecipientName.ToLower());

                if (!exists)
                {
                    AddError("Recipient does not exists", () => model.RecipientName);
                }
            }
        }
Example #5
0
        public override void Validate(CreatePartyViewModel model, ValidatorAction action = ValidatorAction.Undefined)
        {
            var currentEntity = SessionHelper.CurrentEntity;

            if (currentEntity.Is(EntityTypeEnum.Citizen) == false)
            {
                AddError("You must be a citizen to create a party!");
            }

            if (currentEntity.Citizen.PartyMember != null)
            {
                AddError("You cannot be in another party to create party!");
            }

            if (entityService.IsNameTaken(model.Name))
            {
                AddError("Name is already used!");
            }

            if (entityService.IsSpecialName(model.Name))
            {
                AddError("This is special name. You cannot use it");
            }
        }
Example #6
0
 public virtual void Validate(TEntity model, ValidatorAction action = ValidatorAction.Undefined)
 {
 }