Beispiel #1
0
        async void Sync()
        {
            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    connection.Message);

                return;
            }
            var products = dataService.Get <Product>(false).Where(p => p.PendingToSave).ToList();

            //validamos que haya productos
            if (products.Count == 0)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "There are not products to sync!");
            }

            var urlApi         = Application.Current.Resources["URLAPI"].ToString();
            var mainViewModels = MainViewModels.GetInstance();

            foreach (var product in products)
            {
                var response = await apiService.Post(
                    urlApi,
                    "/api",
                    "/Products",
                    mainViewModels.Token.TokenType,
                    mainViewModels.Token.AccessToken
                    , product);

                if (response.IsSuccess)
                {
                    product.PendingToSave = false;
                    dataService.Update(product);
                }
            }

            IsRunning = false;
            IsEnabled = true;

            await dialogService.ShowMessage(
                "Confirmation",
                "Data Base sync!!");

            //Volvemos a la pagina principal
            await navigationService.BackOnMaster();
        }
Beispiel #2
0
        async void LoadCategories()
        {
            IsRefreshing = true;
            var connetion = await apiService.CheckConnection();

            if (!connetion.IsSuccess)
            {
                categories = dataService.Get <Category>(true);
                if (categories.Count == 0)
                {
                    await dialogService.ShowMessage(
                        "Error",
                        "No cuenta con internet y No hay ninguna categoria cargada.");

                    return;
                }
            }
            else
            {
                var mainViewModel = MainViewModels.GetInstance();

                var response = await apiService.GetList <Category>(
                    "http://productsapiis.azurewebsites.net",
                    "/api",
                    "/Categories",
                    mainViewModel.Token.TokenType,
                    mainViewModel.Token.AccessToken);

                if (!response.IsSuccess)
                {
                    await dialogService.ShowMessage(
                        "Error",
                        response.Message);

                    return;
                }

                categories = (List <Category>)response.Result;
                SaveCategoriesOnDB();
            }


            // CategoriesList = new ObservableCollection<Category>(categories.OrderBy(c => c.Description));
            Search();
            IsRefreshing = false;
        }
        public async Task LoadPines()
        {
            var connetion = await apiService.CheckConnection();

            if (!connetion.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    connetion.Message);

                return;
            }

            var mainViewModel = MainViewModels.GetInstance();

            var response = await apiService.GetList <Ubication>(
                "http://productsapiis.azurewebsites.net",
                "/api",
                "/Ubications",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken);

            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            var ubications = (List <Ubication>)response.Result;

            Pins = new ObservableCollection <Pin>();
            foreach (var ubication in ubications)
            {
                Pins.Add(new Pin
                {
                    Address  = ubication.Address,
                    Label    = ubication.Description,
                    Position = new Position(ubication.Latitude, ubication.Longitude),
                    Type     = PinType.Place,
                });
            }
        }
Beispiel #4
0
        public async Task DeleteCategory(Category category)
        {
            IsRefreshing = true;

            //buscamos la vieja categoria, por el ID

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRefreshing = false;
                await dialogService.ShowMessage(
                    "Error",
                    connection.Message);

                return;
            }

            var mainViewModels = MainViewModels.GetInstance();

            var response = await apiService.Delete(
                "http://productsapiis.azurewebsites.net",
                "/api",
                "/Categories",
                mainViewModels.Token.TokenType,
                mainViewModels.Token.AccessToken
                , category);

            if (!response.IsSuccess)
            {
                IsRefreshing = false;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            //Eliminamos el objeto de la lista de categorias
            categories.Remove(category);

            CategoriesList = new ObservableCollection <Category>(categories.OrderBy(c => c.Description));
            IsRefreshing   = false;
        }
Beispiel #5
0
        public async Task Delete(Product product)
        {
            IsRefreshing = true;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRefreshing = false;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }

            var mainViewModel = MainViewModels.GetInstance();

            var response = await apiService.Delete(
                "http://productsapiis.azurewebsites.net",
                "/api",
                "/Products",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                product);

            if (!response.IsSuccess)
            {
                IsRefreshing = false;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            products.Remove(product);
            Products = new ObservableCollection <Product>(
                products.OrderBy(c => c.Description));

            IsRefreshing = false;
        }
Beispiel #6
0
        async void Login()
        {
            if (string.IsNullOrEmpty(Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an email.");

                return;
            }
            if (string.IsNullOrEmpty(Password))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an password.");

                return;
            }
            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    connection.Message);

                return;
            }

            var urlAPI = Application.Current.Resources["URLAPI"].ToString();


            var response = await apiService.GetToken(
                urlAPI,
                Email,
                Password);

            if (response == null)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    "The service is not available, please try latter.");

                return;
            }

            if (string.IsNullOrEmpty(response.AccessToken))
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.ErrorDescription);

                return;
            }

            response.IsRemembered = IsToggled;
            response.Password     = Password;
            dataService.DeleteAllAndInsert(response);

            var mainViewModel = MainViewModels.GetInstance();

            mainViewModel.Categories = new CategoriesViewModel();
            mainViewModel.Token      = response;
            navigationService.SetMainPage("MasterView");

            IsRunning = false;
            IsEnabled = true;
            Email     = null;
            Password  = null;
        }
Beispiel #7
0
 async void RegisterNewUser()
 {
     MainViewModels.GetInstance().NewCustomer = new NewCustomerViewModel();
     await navigationService.NavigateOnLogin("NewCustomerView");
 }
Beispiel #8
0
        async void Save()
        {
            if (string.IsNullOrEmpty(Description))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an Category.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    connection.Message);

                return;
            }

            var category = new Category();

            {
                category.Description = Description;
            };

            var mainViewModels = MainViewModels.GetInstance();

            var urlAPI = Application.Current.Resources["URLAPI"].ToString();

            var response = await apiService.Post(
                urlAPI,
                "/api",
                "/Categories",
                mainViewModels.Token.TokenType,
                mainViewModels.Token.AccessToken
                , category);

            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            category = (Category)response.Result;
            var categoriesViewModel = CategoriesViewModel.GetInstance();

            categoriesViewModel.AddCategory(category);

            await navigationService.BackOnMaster();

            IsRunning = false;
            IsEnabled = true;
        }
Beispiel #9
0
        async void Save()
        {
            if (string.IsNullOrEmpty(Description))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an Product.");

                return;
            }

            if (string.IsNullOrEmpty(Price))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an Price.");

                return;
            }
            var price = decimal.Parse(Price);

            if (price <= 0)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter aun Price > 0");
            }

            if (string.IsNullOrEmpty(Stock))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an Stock.");

                return;
            }
            var stock = Double.Parse(Price);

            if (stock <= 0)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter aun Stock > 0");
            }

            if (string.IsNullOrEmpty(Stock))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an Stock.");

                return;
            }


            byte[] imageArray = null;
            if (file != null)
            {
                imageArray = FilesHelper.ReadFully(file.GetStream());
                file.Dispose();
            }
            var mainViewModels = MainViewModels.GetInstance();
            var product        = new Product
            {
                CategoryId   = mainViewModels.Category.CategoryId,
                Description  = Description,
                ImageArray   = imageArray,
                IsActive     = IsActive,
                LastPurchase = LastPurchase,
                Price        = price,
                Remarks      = Remarks,
                Stock        = stock,
            };

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                product.PendingToSave = true;
                dataService.Insert(product);
                await dialogService.ShowMessage(
                    "Message",
                    "The product was save to DB Local, don't forget to upload when to have connection to internet"
                    );
            }
            else
            {
                var response = await apiService.Post(
                    "http://productsapiis.azurewebsites.net",
                    "/api",
                    "/Products",
                    mainViewModels.Token.TokenType,
                    mainViewModels.Token.AccessToken
                    , product);

                if (!response.IsSuccess)
                {
                    IsRunning = false;
                    IsEnabled = true;
                    await dialogService.ShowMessage(
                        "Error",
                        response.Message);

                    return;
                }

                product = (Product)response.Result;
            }

            var productsViewModel = ProductsViewModel.GetInstance();

            productsViewModel.Add(product);

            await navigationService.BackOnMaster();

            IsRunning = false;
            IsEnabled = true;
        }
        async void Save()
        {
            if (string.IsNullOrEmpty(FirstName))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a first name.");

                return;
            }

            if (string.IsNullOrEmpty(LastName))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a last name.");

                return;
            }

            if (string.IsNullOrEmpty(Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a email.");

                return;
            }

            if (!RegexUtilities.IsValidEmail(Email))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a valid email.");

                return;
            }

            if (string.IsNullOrEmpty(Password))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a password.");

                return;
            }

            if (Password.Length < 6)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The password must have at least 6 characters length.");

                return;
            }

            if (string.IsNullOrEmpty(Confirm))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a password confirm.");

                return;
            }

            if (!Password.Equals(Confirm))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The password and confirm, does not match.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }

            var customer = new Customer
            {
                Address      = Address,
                CustomerType = 1,
                Email        = Email,
                FirstName    = FirstName,
                LastName     = LastName,
                Password     = Password,
                Phone        = Phone,
            };

            var response = await apiService.Post(
                "http://productsapiis.azurewebsites.net",
                "/api",
                "/Customers",
                customer);

            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            var response2 = await apiService.GetToken(
                "http://productsapiis.azurewebsites.net",
                Email,
                Password);

            if (response2 == null)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    "The service is not available, please try latter.");

                Password = null;
                return;
            }

            if (string.IsNullOrEmpty(response2.AccessToken))
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response2.ErrorDescription);

                Password = null;
                return;
            }

            var mainViewModel = MainViewModels.GetInstance();

            mainViewModel.Token      = response2;
            mainViewModel.Categories = new CategoriesViewModel();
            await navigationService.BackOnLogin();

            navigationService.SetMainPage("MasterView");

            IsRunning = false;
            IsEnabled = true;
        }
Beispiel #11
0
        async void Save()
        {
            if (string.IsNullOrEmpty(CurrentPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter the current password.");

                return;
            }

            var mainViewModel = MainViewModels.GetInstance();

            if (!mainViewModel.Token.Password.Equals(CurrentPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The current password is not valid");

                return;
            }

            if (string.IsNullOrEmpty(NewPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a new password.");

                return;
            }

            if (NewPassword.Length < 6)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The new password must have at least 6 characters length.");

                return;
            }

            if (string.IsNullOrEmpty(ConfirmPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a new password confirm.");

                return;
            }

            if (!NewPassword.Equals(ConfirmPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The new password and confirm, does not match.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }

            var changePasswordRequest = new ChangePasswordRequest
            {
                CurrentPassword = CurrentPassword,
                Email           = mainViewModel.Token.UserName,
                NewPassword     = NewPassword,
            };

            var urlAPI = Application.Current.Resources["URLAPI"].ToString();

            var response = await apiService.ChangePassword(
                urlAPI,
                "/api",
                "/Customers/",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                changePasswordRequest);

            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            mainViewModel.Token.Password = NewPassword;
            dataService.Update(mainViewModel.Token);

            await dialogService.ShowMessage(
                "Confirm",
                "The password was changed successfully");

            await navigationService.BackOnMaster();

            IsRunning = false;
            IsEnabled = true;
        }
Beispiel #12
0
        async void Save()
        {
            if (string.IsNullOrEmpty(Description))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter an Category.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    connection.Message);

                return;
            }

            //Asignamos la nueva descripción al objeto, con lo que el usuario digitó
            category.Description = Description;

            var mainViewModels = MainViewModels.GetInstance();

            var response = await apiService.Put(
                "http://productsapiis.azurewebsites.net",
                "/api",
                "/Categories",
                mainViewModels.Token.TokenType,
                mainViewModels.Token.AccessToken
                , category);

            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            var categoriesViewModel = CategoriesViewModel.GetInstance();

            //actualizamos la categoria.
            categoriesViewModel.UpdateCategory(category);

            await navigationService.BackOnMaster();

            IsRunning = false;
            IsEnabled = true;
        }
Beispiel #13
0
        async void Save()
        {
            if (string.IsNullOrEmpty(Description))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a product description.");

                return;
            }

            if (string.IsNullOrEmpty(Price))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a product price.");

                return;
            }

            var price = decimal.Parse(Price);

            if (price < 0)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The price must be a value greather or equals than zero.");

                return;
            }

            if (string.IsNullOrEmpty(Stock))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a product stock.");

                return;
            }

            var stock = double.Parse(Stock);

            if (stock < 0)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The stock must be a value greather or equals than zero.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }

            var mainViewModel = MainViewModels.GetInstance();

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

            product.Description  = Description;
            product.IsActive     = IsActive;
            product.LastPurchase = LastPurchase;
            product.Price        = price;
            product.Remarks      = Remarks;
            product.Stock        = stock;
            product.ImageArray   = imageArray;


            var response = await apiService.Put(
                "http://productsapiis.azurewebsites.net",
                "/api",
                "/Products",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                product);

            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            ProductsViewModel.GetInstance().Update(product);


            IsRunning = false;
            IsEnabled = true;
        }