Beispiel #1
0
        private async void Goto()
        {
            if (this.PageName == "LoginPage")
            {
                Settings.Access_token = string.Empty;
                Settings.Token_type   = string.Empty;
                Settings.IsRemembered = false;
                MainViewModel.GetIntance().Login = new LoginViewModel();
                Application.Current.MainPage = new NavigationPage(new LoginPage());
            }

            else if (this.PageName == "AboutPage")
            {
                App.Master.IsPresented = false;
                await App.Navigator.PushAsync(new MapPage());
            }
        }
Beispiel #2
0
        private async void Login()
        {
            if (string.IsNullOrEmpty(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.EmailValidation,
                    Languages.Accept);

                return;
            }

            if (string.IsNullOrEmpty(this.Password))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PasswordValidation,
                    Languages.Accept);

                return;
            }

            this.IsRunning = true;
            this.IsEnabled = false;

            var conecction = await this.apiService.CheckConnection();

            if (!conecction.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, conecction.Message, Languages.Accept);

                return;
            }
            var url   = Application.Current.Resources["UrlAPI"].ToString();
            var token = await this.apiService.GetToken(url, this.Email, this.Password);

            if (token == null || string.IsNullOrEmpty(token.AccessToken))
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.SomethingWrong,
                    Languages.Accept);

                return;
            }

            Settings.Token_type   = token.TokenType;
            Settings.Access_token = token.AccessToken;
            Settings.IsRemembered = this.IsRemembered;

            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlUsersController"].ToString();
            var response   = await this.apiService.GetUser(url, prefix, $"{controller}/GetUser", this.Email, token.TokenType, token.AccessToken);

            if (response.IsSuccess)
            {
                var userASP = (MyUserASP)response.Result;
                MainViewModel.GetIntance().UserASP = userASP;
                MainViewModel.GetIntance().RegisterDevice();
                Settings.UserASP = JsonConvert.SerializeObject(userASP);
            }

            MainViewModel.GetIntance().Categories = new CategoriesViewModel();
            Application.Current.MainPage = new MasterPage();

            this.IsRunning = false;
            this.IsEnabled = true;
        }
Beispiel #3
0
 private async void Register()
 {
     MainViewModel.GetIntance().Register = new RegisterViewModel();
     await Application.Current.MainPage.Navigation.PushAsync(new RegisterPage());
 }
Beispiel #4
0
 private async void EditProduct()
 {
     MainViewModel.GetIntance().EditProduct = new EditProductViewModel(this);
     await App.Navigator.PushAsync(new EditProductPage());
 }
Beispiel #5
0
 private async void GotoCategory()
 {
     MainViewModel.GetIntance().Products = new ProductsViewModel(this);
     await App.Navigator.PushAsync(new ProductsPage());
 }
        private async void Save()
        {
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Accept);

                return;
            }

            if (string.IsNullOrEmpty(this.Price))
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept);

                return;
            }

            var price = decimal.Parse(this.Price);

            if (price < 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept);

                return;
            }

            if (this.Category == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.CategoryError,
                    Languages.Accept);

                return;
            }


            this.IsRunning = true;
            this.IsEnabled = false;

            var conecction = await this.apiService.CheckConnection();

            if (!conecction.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    conecction.Message,
                    Languages.Accept);

                return;
            }

            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FilesHelper.ReadFully(this.file.GetStream());
            }

            var location = await this.GetLocation();

            var product = new Product
            {
                Description = this.Description,
                Price       = price,
                Remarks     = this.Remarks,
                ImageArray  = imageArray,
                CategoryId  = this.Category.CategoryId,
                UserId      = MainViewModel.GetIntance().UserASP.Id,
                Latitude    = location == null ? 0 : location.Latitude,
                Longitude   = location == null ? 0 : location.Longitude,
            };

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlProductsController"].ToString();
            var response   = await this.apiService.Post(url, prefix, controller, product, Settings.Token_type, Settings.Access_token);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            var newProduct        = (Product)response.Result;
            var productsViewModel = ProductsViewModel.GetIntance();

            productsViewModel.MyProducts.Add(newProduct);
            productsViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;

            await App.Navigator.PopAsync();
        }