Exemplo n.º 1
0
        public EditarJogadorPopupViewModel(INavigationService navigationService,
                                           IDialogService dialogService,
                                           ITeeService teeService,
                                           IHandicapService handicapService,
                                           IGeneroService generoService,
                                           ICameraService cameraService)
            : base(navigationService, dialogService)
        {
            _teeService      = teeService;
            _handicapService = handicapService;
            _generoService   = generoService;
            _cameraService   = cameraService;

            InicializarComunicacaoMediador();

            Task.Run(async() => await InicializarDados());

            Email = new ValidatableObject <string>();
            Email.RegrasValidacao.AddRange(new List <IValidationRule <string> >()
            {
                new EmailValidationRule <string>(), new EspacoEmBrancoValidationRule <string>(), new EmptyValidationRule <string>()
            });

            Nome = new ValidatableObject <string>();
            Nome.RegrasValidacao.AddRange(new List <IValidationRule <string> >()
            {
                new EspacoEmBrancoValidationRule <string>(), new EmptyValidationRule <string>()
            });
        }
Exemplo n.º 2
0
        public BelegDetailsViewModel(Beleg beleg)
        {
            if (beleg == null)
            {
                throw new ArgumentNullException("beleg");
            }

            _validatableLabel       = new ValidatableObject <string>(true);
            _validatableDescription = new ValidatableObject <string>(true);
            _validatableType        = new ValidatableObject <string>(true);

            Belegnummer = beleg.Belegnummer;
            _statusEnum = beleg.Status;
            Label       = beleg.Label;
            Description = beleg.Description;
            _datum      = beleg.Date;

            Type       = beleg.Type;
            _thumbnail = beleg.Thumbnail;
            _belegSize = beleg.BelegSize;
            _iconName  = beleg.Status + ".png";
            _image     = beleg.Image;
            _betrag    = beleg.Betrag / 100m;
            //decimal.Parse(beleg.Betrag / 100m)).ToString("c")); //e.g. 12345 becomes €123.45 for me)
            //_betrag = (decimal)(beleg.Betrag / 100);

            selected = false;

            Init();
        }
        public SowDetailsViewModel()
        {
            try
            {
                // activate for validation
                _name = new ValidatableObject <string>();
                _box  = new ValidatableObject <string>();



                // set mock
                InvalidateMock();

                // add validations
                AddValidations();
            }
            catch (Exception ex)
            {
                var viewModelName = this.GetType().FullName;
                var methodName    = nameof(SowDetailsViewModel);
                var exMessage     = ex.InnerException == null?string.Format($"ErrorMessage: {ex.Message}") : string.Format($"ErrorMessage: {ex.Message}, InnerException Message: {ex.InnerException.Message}");

                NavigationService.DisplayAlert(AppResources.ErrorOccured, new ViewModelMethodExecutionException(viewModelName, methodName, exMessage).Message, "Ok");
                throw ex;
            }
        }
Exemplo n.º 4
0
        public LoginViewModel()
        {
            cache = DependencyService.Get <SubscriptionsCache>();

            string emptyValidationMessage = Translations.Validations_NullOrEmptyMessage;
            var    emptyRule = new IsNotNullOrEmptyRule
            {
                ValidationMessage = emptyValidationMessage,
            };

            password = new ValidatableObject <string>();
            password.Validations.Add(emptyRule);

            clientId = new ValidatableObject <string>();
            clientId.Validations.Add(emptyRule);

            tenantId = new ValidatableObject <string>();
            tenantId.Validations.Add(emptyRule);

#if DEBUG
            /*
             * Avoid having to enter credentials every time app is deployed
             * during development
             */

            ClientId.Value = AppSettings.ClientId;
            TenantId.Value = AppSettings.TenantId;


            ClientId.IsValid = TenantId.IsValid = Password.IsValid = true;
#else
            ClientId.IsValid = TenantId.IsValid = Password.IsValid = false;
#endif
        }
Exemplo n.º 5
0
        public ViewModel()
        {
            User      = MySingleton.Instance.User;
            MenuItems = MySingleton.Instance.MenuItems;

            _email       = new ValidatableObject <string>();
            _username    = new ValidatableObject <string>();
            _phonenumber = new ValidatableObject <string>();
            _name        = new ValidatableObject <string>();

            AddValidations();

            Command = new Command(async() => {
                bool isValid = Validate();
                if (isValid)
                {
                    UpdateUserData();
                    await Application.Current.MainPage.Navigation.PushAsync(new MainPage());
                }
                else
                {
                    Debug.WriteLine("Error");
                }
            });
        }
        public RegistrationViewModel()
        {
            Return   = new Command(async() => await Shell.Current.GoToAsync("//login"));
            Register = new Command(async() => await Registration());
            Email    = new ValidatableObject <string>();
            Password = new ValidatablePair <string>();

            Email.Validations.Add(new IsNotNullOrEmptyRule <string> {
                ValidationMessage = "Email Required"
            });
            Email.Validations.Add(new IsValidEmailRule <string> {
                ValidationMessage = "Invalid Email"
            });

            Password.Item1.Validations.Add(new IsNotNullOrEmptyRule <string> {
                ValidationMessage = "Password Required"
            });
            Password.Item1.Validations.Add(new IsLenghtValidRule <string> {
                ValidationMessage = "Password between 6-20 characters", MinimunLength = 6, MaximunLength = 20
            });
            Password.Item2.Validations.Add(new IsNotNullOrEmptyRule <string> {
                ValidationMessage = "Confirm password required"
            });
            Password.Validations.Add(new PasswordsMatchRule <string> {
                ValidationMessage = "Password and confirm password don't match"
            });
        }
        private void InitializeValidation()
        {
            _username = new ValidatableObject <string>();
            _password = new ValidatableObject <string>();

            AddSpecificPropertyValidations();
        }
Exemplo n.º 8
0
 public LoginViewModel(UserDataService userDataService)
 {
     _userDataService = userDataService;
     _userMail        = new ValidatableObject <string>();
     _userPassword    = new ValidatableObject <string>();
     AddValidations();
 }
Exemplo n.º 9
0
        protected EmployeeBaseViewModel(
            IGooglePlacesService googlePlacesService,
            INetworkService networkService,
            INavigationService navigationService)
            : base(navigationService)
        {
            GooglePlacesService = googlePlacesService;
            NetworkService      = networkService;

            MinDateOfBirth = DateTime.UtcNow.AddYears(-65).Date;
            MaxDateOfBirth = DateTime.UtcNow.AddYears(-18).Date;

            FirstName   = new ValidatableObject <string>();
            Surname     = new ValidatableObject <string>();
            LastName    = new ValidatableObject <string>();
            Address     = new ValidatableObject <string>();
            PhoneNumber = new ValidatableObject <string>();
            Salary      = new ValidatableObject <double>();
            DateOfBirth = new ValidatableObject <DateTime> {
                Value = MaxDateOfBirth
            };
            Position = new ValidatableObject <string>();

            AddValidations();
        }
Exemplo n.º 10
0
        public LoginPageModel()
        {
            UserName = new ValidatableObject <string>();
            Password = new ValidatableObject <string>();

            SetValidationRules();
        }
        public void ValidModelItem_BuildsLogEntry()
        {
            var server = new TestServerBuilder()
                         .AddGraphType <LogTestController>()
                         .Build();

            var builder = server.CreateFieldContextBuilder <LogTestController>(nameof(LogTestController.ValidatableInputObject));

            var context = builder.CreateExecutionContext();

            // valid range 0 - 35
            var item = new ValidatableObject()
            {
                Age = 18,
            };

            var generator      = new ModelStateGenerator();
            var argumentToTest = CreateArgument("testItem", item);
            var dictionary     = generator.CreateStateDictionary(argumentToTest);

            var entry = new ActionMethodModelStateValidatedLogEntry(
                builder.GraphMethod.Object,
                context.Request,
                dictionary);

            this.ValidateModelDictionaryToLogEntry(builder.GraphMethod.Object, context.Request, dictionary, entry);
        }
 public MainPageViewModel(INavigationService navigationService, IAppSettings settings, IPageDialogService pageDialogService, IAccountService accountServic)
     : base(navigationService, settings, pageDialogService)
 {
     _accountService = accountServic;
     _userName       = new ValidatableObject <string>();
     AddValidations();
 }
Exemplo n.º 13
0
        public PetAdditionInfoVM(int petId)
        {
            petAdditionalInfo = new PetAdditionalInfo();
            _id                   = new ValidatableObject <int>();
            _petId                = new ValidatableObject <int>();
            _insurer              = new ValidatableObject <string>();
            _policyNumber         = new ValidatableObject <string>();
            _insurerContactNumber = new ValidatableObject <string>();
            _vet                  = new ValidatableObject <string>();
            _vetContactNumber     = new ValidatableObject <string>();
            _chipNumber           = new ValidatableObject <string>();
            _petId.Value          = petId;
            _policyExpiryDate     = new ValidatableObject <DateTime>();
            AddValidations();
            PetAdditionalInfoRepository petAdditionalInfoRepository = new PetAdditionalInfoRepository();

            var petAddInfo = petAdditionalInfoRepository.GetPetAddInfoAsync(_petId.Value);

            if (petAddInfo != null)
            {
                _insurer.Value              = petAddInfo.Insurer;
                _policyNumber.Value         = petAddInfo.PolicyNumber;
                _insurerContactNumber.Value = petAddInfo.InsurerContactNumber;
                _vet.Value = petAddInfo.Vet;
                _vetContactNumber.Value = petAddInfo.VetContactNumber;
                _chipNumber.Value       = petAddInfo.ChipNumber;
                _id.Value = petAddInfo.Id;
            }
        }
Exemplo n.º 14
0
        public InputPopup(ValidatableObject <string> text, string title, InputOption inputOption = null)
        {
            InitializeComponent();

            if (inputOption == null)
            {
                this.Option = new InputOption
                {
                    Keyboard = Keyboard.Default
                };
            }
            else
            {
                this.Option = inputOption;
            }

            if (Option.Animation == null)
            {
                this.Animation = new FadeAnimation()
                {
                    DurationIn  = 100,
                    DurationOut = 100
                };
            }
            else
            {
                this.Animation = Option.Animation;
            }

            this.Title = title;
            this.Text  = text;
        }
Exemplo n.º 15
0
        public PetProfileViewModel(int petId)
        {
            _id              = new ValidatableObject <int>();
            _petName         = new ValidatableObject <string>();
            _petBreed        = new ValidatableObject <string>();
            _petDOB          = new ValidatableObject <DateTime>();
            _petSex          = new ValidatableObject <string>();
            _petNeutered     = new ValidatableObject <string>();
            _petWeight       = new ValidatableObject <int>();
            _petExerciseGoal = new ValidatableObject <int>();
            _petImagePath    = new ValidatableObject <string>();
            _petImageStream  = new ValidatableObject <Stream>();
            _petDOB.Value    = DateTime.Now;
            _petWeight.Value = 0;
            _isBusy          = false;
            pet              = new Pet();
            PetRepository petRepository = new PetRepository();

            pet = petRepository.GetPetWithIdAsync(petId);

            if (pet != null)
            {
                _id.Value              = pet.Id;
                _petName.Value         = pet.Name;
                _petBreed.Value        = pet.Breed;
                _petDOB.Value          = pet.DOB;
                _petSex.Value          = pet.Sex;
                _petNeutered.Value     = pet.Neutered;
                _petWeight.Value       = pet.Weight;
                _petExerciseGoal.Value = pet.Weight;
                _petImagePath.Value    = pet.DPPath;
            }

            AddValidations();
        }
Exemplo n.º 16
0
        public AddUserViewModel()
        {
            UserListCommand = new Command(async() =>
            {
                var page = new UserListPage();
                await Application.Current.MainPage.Navigation.PushAsync(page);
            });

            SaveUserCommand = new Command(async() =>
            {
                UserDTO user = new UserDTO()
                {
                    UserName = this.UserName.Value,
                    Password = this.Password.Value
                };
                if (Validate())
                {
                    SaveUserToDatabase(user);
                    UserName.Value = "";
                    Password.Value = "";
                    var page       = new UserListPage();
                    await Application.Current.MainPage.Navigation.PushAsync(page);
                }
                else
                {
                    PasswordErrors = Password.ErrorMessages();
                }
            });

            userName = new ValidatableObject <string>();
            password = new ValidatableObject <string>();

            AddValidations();
        }
Exemplo n.º 17
0
 public LoginPageModel(IAuthenticationService authenticationService)
 {
     _authenticationService = authenticationService;
     _email    = new ValidatableObject <string>();
     _password = new ValidatableObject <string>();
     AddValidations();
 }
Exemplo n.º 18
0
        public AccountViewModel()
        {
            _email = new ValidatableObject <string>();
            _skype = new ValidatableObject <string>();

            AddValidations();
        }
Exemplo n.º 19
0
        public SignUpPageViewModel(
            INavigationService navigationService,
            ILoggerService loggerService,
            IAuthService authService)
            : base(navigationService)
        {
            Title = "Sign Up";

            _loggerService = loggerService;
            _authService   = authService;

            DisplayName = new ValidatableObject <string>();
            DisplayName.Validations.Add(new IsNotNullOrEmptyRule <string>()
            {
                ValidationMessage = $"A display name is required.\nName should be at least 4 characters"
            });

            Email = new ValidatableObject <string>();
            Email.Validations.Add(new EmailValidatorRule <string>()
            {
                ValidationMessage = "Enter a valid email.",
            });

            Password = new ValidatableObject <string>();
            Password.Validations.Add(new PasswordValidatorRule <string>()
            {
                ValidationMessage = $"The given password is invalid.\nPassword should be at least 6 characters"
            });
        }
Exemplo n.º 20
0
        private void ValidatableObjectJSONSerializeTest()
        {
            string standardString = "STANDARD STRING";
            string unicodeString  = "Testing «ταБЬℓσ»: 1<2 & 4+1>3, now 20% off!";
            string emptyString    = "";
            string nullString     = null;

            void StringValidatableObjectTest(string inputString)
            {
                var validatableObject = new ValidatableObject <string>()
                {
                    Value = inputString
                };
                //Serialization test
                var inputJSON             = JsonConvert.SerializeObject(inputString);
                var validatableObjectJSON = JsonConvert.SerializeObject(validatableObject);

                Assert.Equal(inputJSON, validatableObjectJSON);
            }

            StringValidatableObjectTest(standardString);
            StringValidatableObjectTest(unicodeString);
            StringValidatableObjectTest(emptyString);
            StringValidatableObjectTest(nullString);
        }
Exemplo n.º 21
0
 public BillEditorValidator(BillEditorValidatorContext context)
 {
     _hotWaterBulk    = context.HotWaterBulk;
     _coldWaterBulk   = context.ColdWaterBulk;
     _electricityBulk = context.ElectricityBulk;
     _note            = context.Note;
 }
Exemplo n.º 22
0
 public MainPageViewModel(INavigationService navigationService)
     : base(navigationService)
 {
     _email = new ValidatableObject <string>();
     AddValidations();
     Title = "Main Page";
 }
Exemplo n.º 23
0
        public EditActivityViewModel()
        {
            UpdateActivityCommand = new Command(async() => await UpdateActivity(), () => CanUpdateActivity);
            CancelCommand         = new Command(async() => await Cancel());
            RemoveTagCommand      = new Command <TagModel>(RemoveTag);
            AddNewTagCommand      = new Command(async() => await AddNewTag());

            HoursTextInput = new ValidatableObject <string>()
            {
                Value = "00"
            };
            HoursTextInput.Validations.Add(new HourTextIsValidRule <string>("Hours must be a number between 0 and 24"));

            MinutesTextInput = new ValidatableObject <string>()
            {
                Value = "00"
            };
            MinutesTextInput.Validations.Add(new MinuteTextIsValidRule <string>("Minutes must be a number between 0 and 59"));

            SecondsTextInput = new ValidatableObject <string>()
            {
                Value = "00"
            };
            SecondsTextInput.Validations.Add(new SecondsTextIsValidRule <string>("Seconds must be a number between 0 and 59"));
        }
        public void Validate_ShouldRaisePropertyChanged_When_Value_Is_Changed()
        {
            var v = new ValidatableObject <string>();

            v.Validations.Add(new IsNotNullOrEmptyRule <string>("Email must not be empty"));

            v.Validations.Add(new EmailRule <string>()
            {
                ValidationMessage = "You have entered an invalid email"
            });

            bool isPropertyChangedRaised = false;

            v.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName.Equals(nameof(v.Value)))
                {
                    isPropertyChangedRaised = true;
                    v.Validate();
                }
            };

            Assert.True(v.IsValid);
            v.Value = "t";
            Assert.False(v.IsValid);
            Assert.True(isPropertyChangedRaised);
            Assert.Equal("You have entered an invalid email", v.Errors[0]);
        }
Exemplo n.º 25
0
        public SignUpViewModel()
        {
            AddPhotoCommand      = new Command(OnAddPhoto);
            CreateAccauntCommand = new Command(OnCreateAccauntCommand);

            Email = new ValidatableObject <string>
            {
                ValidationsRules =
                {
                    new IsNotNullOrEmptyRule(),
                    new EmailRule()
                }
            };

            Password = new ValidatableObject <string>
            {
                ValidationsRules =
                {
                    new IsNotNullOrEmptyRule(),
                    new PasswordRule()
                }
            };

            ConfirmPassword = new ValidatableObject <string>
            {
                ValidationsRules =
                {
                    new IsNotNullOrEmptyRule(),
                    new PasswordRule(),
                    new ConfirmPasswordRule(() => Password.Value)
                }
            };
        }
Exemplo n.º 26
0
        public LoginViewModel()
        {
            _userName = new ValidatableObject <string>();
            _password = new ValidatableObject <string>();

            AddValidations();
        }
Exemplo n.º 27
0
        public LoginPageViewModel(
            INavigationService navigationService,
            ILoggerService loggerService,
            IAuthService authService)
            : base(navigationService)
        {
            Title = "Login";

            _loggerService = loggerService;
            _authService   = authService;

            Email = new ValidatableObject <string>()
#if DEBUG
            {
                Value = "*****@*****.**"
            };
#endif
                    Email.Validations.Add(new EmailValidatorRule <string>()
            {
                ValidationMessage = "Enter a valid email.",
            });

            Password = new ValidatableObject <string>()
#if DEBUG
            {
                Value = "Qwerty1234!"
            };
#endif
                       Password.Validations.Add(new PasswordValidatorRule <string>()
            {
                ValidationMessage = $"The given password is invalid.\nPassword should be at least 6 characters."
            });

            InitializeCommands();
        }
Exemplo n.º 28
0
 public WorkoutDTO()
 {
     ValidName     = new ValidatableObject <string>();
     Name          = string.Empty;
     Id            = Guid.NewGuid().ToString();
     ExerciseItems = new List <ExerciseItemDTO>();
 }
Exemplo n.º 29
0
 /// <summary>
 /// Sets the validation rules for the specified instance.
 /// </summary>
 /// <param name="item">The item.</param>
 public void SetValidationLogic(ValidatableObject item)
 {
     var user = item as User;
     user.AddValidationRule(() => user.Name
         , () => !user.Name.ToLower().StartsWith("r")
         , "This name starts with 'r', it is bad");
 }
Exemplo n.º 30
0
 public ForgotPasswordPageViewModel(IUserDialogs userDialogs, IAppSettings appSettings, IPageDialogService pageDialogService, INavigationService navigationService, IAccountService accountService) : base(navigationService, appSettings, pageDialogService)
 {
     UserEmail       = new ValidatableObject <string>();
     UserEmail.Value = string.Empty;
     _accountService = accountService;
     AddValidations();
 }
Exemplo n.º 31
0
        public void Validation_after_construct_should_be_true()
        {
            ValidatableObject <string> stringObject = new ValidatableObject <string>();

            stringObject.Value = "42";
            stringObject.IsValid.Should().BeTrue();
        }
Exemplo n.º 32
0
        public void SetValidationLogic(ValidatableObject item)
        {
            var book = item as BookDto;

            if (book == null) throw new ArgumentException("item");

            book.AddValidationRule(() => book.Pages
                , () => book.Pages > 10
                , "A book should have more than 10 pages");

            book.AddValidationRule(() => book.Title
                , () => book.Title.Length > 5
                , "A title should be longer than 5 char");
        }
Exemplo n.º 33
0
 public void SetValidationLogic(ValidatableObject item)
 {
     //Always valid
 }