Esempio n. 1
0
        public ProfileViewModel(IProfileDataService profileService, IDialogCoordinator dialogCoordinator, IFileDialogCoordinator fileDialogCoordinator)
        {
            this.FileDialogCoordinator = fileDialogCoordinator;
            this.ProfileService        = profileService;
            this.DialogCoordinator     = dialogCoordinator;

            this.LoadedCommand = AsyncCommand.Create(
                async() =>
            {
                try
                {
                    Profile model = await this.ProfileService.GetCurrentProfileAsync();
                    this.Profile  = new ProfileWrapper(model);
                }
                catch (Exception e)
                {
                    await this.DialogCoordinator.ShowMessageAsync(this, "Oops", e.Message);
                }
            });

            this.ChangePhotoCommand = AsyncCommand.Create(
                async() =>
            {
                try
                {
                    string filename = FileDialogCoordinator.OpenFile("Select image file", "Images (*.jpg;*.png)|*.jpg;*.png");

                    if (string.IsNullOrEmpty(filename))
                    {
                        return;
                    }

                    var bytes = File.ReadAllBytes(filename);

                    this.Profile.Photo = bytes;

                    await this.ProfileService.InsertOrUpdateProfileAsync(this.Profile.Model);
                }
                catch (Exception e)
                {
                    await this.DialogCoordinator.ShowMessageAsync(this, "Oops", e.Message);
                }
            });
        }
        public CreateProfileViewModel(ISuggestionProvider geoSuggestionProvider, IProfileDataService profileService, IBuildingDataService buildingService, IDialogCoordinator dialogCoordinator, IFileDialogCoordinator fileDialogCoordinator)
        {
            this.GeoSuggestionProvider = geoSuggestionProvider;
            this.ProfileService        = profileService;
            this.BuildingService       = buildingService;
            this.DialogCoordinator     = dialogCoordinator;
            this.FileDialogCoordinator = fileDialogCoordinator;

            this.Profile = new ProfileWrapper(new Profile
            {
                DateOfBirth = DateTime.Now
            });

            this.Address = new AddressWrapper(new Address());

            this.AddPhotoCommand      = new RelayCommand(this.OpenPhotoAsBytes);
            this.ValidateCommand      = AsyncCommand.Create(this.ValidateAsync);
            this.CreateProfileCommand = AsyncCommand.Create(this.CreateAndSaveProfileAsync);
        }