private 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 (string.IsNullOrEmpty(NickName))
            {
                await _dialogService.ShowMessage("Error", "You must enter a nick name.");

                return;
            }

            if (FavoriteTeamId == 0)
            {
                await _dialogService.ShowMessage("Error", "You must select a favorite team.");

                return;
            }

            if (!CrossConnectivity.Current.IsConnected)
            {
                await _dialogService.ShowMessage("Error", "Check you internet connection.");

                return;
            }

            var isReachable = await CrossConnectivity.Current.IsRemoteReachable("notasti.com");

            if (!isReachable)
            {
                await _dialogService.ShowMessage("Error", "Check you internet connection.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

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


            var user = new User
            {
                Email          = Email,
                FavoriteTeamId = FavoriteTeamId,
                FirstName      = FirstName,
                ImageArray     = imageArray,
                LastName       = LastName,
                NickName       = NickName,
                Password       = Password,
                UserTypeId     = 1,
                UserId         = _currentUser.UserId
            };

            var parameters = _dataService.First <Parameter>(false);
            var response   = await _apiService.Put(parameters.UrlBase, "/api", "/Users",
                                                   _currentUser.TokenType, _currentUser.AccessToken, user);


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

                return;
            }

            response = await _apiService.GetUserByEmail(parameters.UrlBase,
                                                        "/api", "/Users/GetUserByEmail", _currentUser.TokenType, _currentUser.AccessToken, Email);

            var newUser = (User)response.Result;

            newUser.AccessToken  = _currentUser.AccessToken;
            newUser.TokenType    = _currentUser.TokenType;
            newUser.TokenExpires = _currentUser.TokenExpires;
            newUser.IsRemembered = _currentUser.IsRemembered;
            newUser.Password     = _currentUser.Password;
            _dataService.DeleteAllAndInsert(newUser.FavoriteTeam);
            _dataService.DeleteAllAndInsert(newUser.UserType);
            _dataService.DeleteAllAndInsert(newUser);

            IsRunning = false;
            IsEnabled = true;

            var mainViewModel = MainViewModel.GetInstance();

            //currentUser.Email = Email;
            //currentUser.FavoriteTeamId = FavoriteTeamId;
            //currentUser.FirstName = FirstName;
            //currentUser.ImageArray = imageArray;
            //currentUser.LastName = LastName;
            //currentUser.NickName = NickName;
            //currentUser.Password = Password;
            mainViewModel.CurrentUser = newUser;
            await _navigationService.Back();
        }
Beispiel #2
0
        async Task BeginDownload()
        {
            try
            {
                IsRunning = true;
                IsEnabled = false;

                Progress = 0;
                int processes = 7 * 2;
                var url       = Application.Current.Resources["URLAPI"].ToString();

                Message = "Descargando clientes...";
                var customers = await DownloadMaster <Customer>(url, "/api/Customers");

                Progress += (double)1 / processes;

                Message = "Descargando sucursales...";
                var shipTos = await DownloadMaster <ShipTo>(url, "/api/ShipToes");

                Progress += (double)1 / processes;

                Message = "Descargando contactos...";
                var contacts = await DownloadMaster <Contact>(url, "/api/Contacts");

                Progress += (double)1 / processes;

                Message = "Descargando Productos...";
                var parts = await DownloadMaster <Part>(url, "/api/Parts");

                Progress += (double)1 / processes;

                Message = "Descargando lista de precios...";
                var pricelist = await DownloadMaster <PriceList>(url, "/api/PriceLists");

                Progress += (double)1 / processes;

                Message = "Descargando lista de precios x parte...";
                var pricelistpart = await DownloadMaster <PriceListPart>(url, "/api/PriceListParts");

                Progress += (double)1 / processes;

                Message = "Descargando lista de precios x cliente...";
                var customerpricelist = await DownloadMaster <CustomerPriceList>(url, "/api/CustomerPriceLists");

                Progress += (double)1 / processes;

                Message = "Termino todas las descargas...";

                if (customers != null && customers.Count > 0)
                {
                    DeleteAndInsert(customers);
                    await Task.Delay(100);

                    Progress += (double)1 / processes;
                }

                if (shipTos != null && shipTos.Count > 0)
                {
                    DeleteAndInsert(shipTos);
                    await Task.Delay(100);

                    Progress += (double)1 / processes;
                }

                if (contacts != null && contacts.Count > 0)
                {
                    DeleteAndInsert(contacts);
                    await Task.Delay(100);

                    Progress += (double)1 / processes;
                }

                if (parts != null && parts.Count > 0)
                {
                    DeleteAndInsert(parts);
                    await Task.Delay(100);

                    Progress += (double)1 / processes;
                }

                if (pricelist != null && pricelist.Count > 0)
                {
                    DeleteAndInsert(pricelist);
                    await Task.Delay(100);

                    Progress += (double)1 / processes;
                }

                if (pricelistpart != null && pricelistpart.Count > 0)
                {
                    DeleteAndInsert(pricelistpart);
                    await Task.Delay(100);

                    Progress += (double)1 / processes;
                }

                if (customerpricelist != null && customerpricelist.Count > 0)
                {
                    DeleteAndInsert(customerpricelist);
                    await Task.Delay(100);

                    Progress += (double)1 / processes;
                }

                Message  = "Proceso finalizado...";
                Progress = 1;

                IsRunning = false;
                IsEnabled = true;

                await dialogService.ShowMessage(
                    "Confirmación",
                    "Proceso finalizado con éxito.");

                await navigationService.Back();
            }
            catch (System.Exception ex)
            {
                Message = ex.Message;;
            }
        }
        private 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(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.");

                return;
            }

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

                return;
            }

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

                return;
            }

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

                return;
            }

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

                return;
            }

            if (FavoriteTeamId == 0)
            {
                await dialogService.ShowMessage("Error", "You must select a favorite team.");

                return;
            }

            if (!CrossConnectivity.Current.IsConnected)
            {
                await dialogService.ShowMessage("Error", "Check you internet connection.");

                return;
            }

            var isReachable = await CrossConnectivity.Current.IsRemoteReachable("google.com");

            if (!isReachable)
            {
                await dialogService.ShowMessage("Error", "Check you internet connection.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var imageArray = FilesHelper.ReadFully(file.GetStream());

            file.Dispose();

            var user = new User
            {
                Email          = Email,
                FavoriteTeamId = FavoriteTeamId,
                FirstName      = FirstName,
                ImageArray     = imageArray,
                LastName       = LastName,
                NickName       = NickName,
                Password       = Password,
                UserTypeId     = 1,
            };

            var parameters = dataService.First <Parameter>(false);
            var response   = await apiService.Post(parameters.URLBase, "/api", "/Users", user);

            IsRunning = false;
            IsEnabled = true;

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

                return;
            }

            await dialogService.ShowMessage("Confirmation", "The user was created, please login.");

            await navigationService.Back();
        }
Beispiel #4
0
        private async void SaveNewProduct()
        {
            if (Price <= 0)
            {
                await dialogService.ShowMessage(Languages.Error, Languages.NewProductErrorEmptyPrice);

                return;
            }
            if (string.IsNullOrEmpty(Description))
            {
                await dialogService.ShowMessage(Languages.Error, Languages.NewProductErrorEmptyDescription);

                return;
            }

            IsRunning = true;
            IsEnable  = false;

            var connection = await apiService.CheckConnection();

            if (!connection.isSuccess)
            {
                IsRunning = false;
                IsEnable  = true;
                await dialogService.ShowMessage(Languages.Error, connection.Message);

                return;
            }

            var product = new Product
            {
                Description  = Description,
                Price        = Price,
                IsActive     = IsActive,
                Stock        = Stock,
                CategoryId   = _categoryId,
                LastPurchase = DateTime.Now,
            };

            var mainViewModel = MainViewModel.GetInstance();
            var response      = await apiService.Post(
                Application.Current.Resources["URLAPI"].ToString(),
                Application.Current.Resources["URLPREFIX"].ToString(),
                Application.Current.Resources["PRODUCTCONTROLLER"].ToString(),
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                product
                );

            if (!response.isSuccess)
            {
                IsEnable = true;
                await dialogService.ShowMessage(Languages.Error, response.Message);

                IsRunning = false;
                IsEnable  = true;
                return;
            }

            product = (Product)response.Result;

            var productViewModel = ProductsViewModel.GetInstance();

            productViewModel.AddProduct(product);
            await navigationService.Back();

            IsRunning = false;
            IsEnable  = true;
        }
Beispiel #5
0
        async void Save()
        {
            if (string.IsNullOrEmpty(Description))
            {
                await dialogServices.ShowMessage("Error", "you must a Description");

                return;
            }


            if (string.IsNullOrEmpty(Price))
            {
                await dialogServices.ShowMessage("Error", "you must a price");

                return;
            }


            var price = decimal.Parse(Price);

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

                return;
            }


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

                return;
            }


            var stock = double.Parse(Stock);

            if (stock < 0)
            {
                await dialogServices.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 dialogServices.ShowMessage("Error", connection.Message);

                return;
            }

            var mainViewModel = MainViewModel.GetInstance();
            var product       = new Product
            {
                CategoryId  = mainViewModel.Category.CategoryId,
                Description = Description,
                IsActivte   = IsActive,
                LastEvent   = LastEvent,
                Price       = price,
                Remarks     = Remarks,
                Stock       = stock,
            };

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

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

                return;
            }

            var productsViewModels = ProductsViewModels.GetInstance();

            productsViewModels.Update(product);

            await navigationService.Back();

            IsRunning = true;
            IsEnabled = false;
        }
Beispiel #6
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(GoalsLocal))
            {
                await _dialogService.ShowMessage("Error", "Necesitas ingresar una prediccion para el Local");

                return;
            }
            if (string.IsNullOrEmpty(GoalsVisitor))
            {
                await _dialogService.ShowMessage("Error", "Necesitas ingresar una prediccion para el Visitante");

                return;
            }

            if (!CrossConnectivity.Current.IsConnected)
            {
                // IsRunning = false;
                // IsEnabled = true;
                await _dialogService.ShowMessage("Error", "Check you internet connection.");

                return;
            }

            var isReachable = await CrossConnectivity.Current.IsRemoteReachable("praysoft.net");

            if (!isReachable)
            {
                // IsRunning = false;
                // IsEnabled = true;
                await _dialogService.ShowMessage("Error", "Check you internet connection.");

                return;
            }
            IsRunning = true;
            IsEnabled = false;

            var parameters = _dataService.First <Parameter>(false);
            var user       = _dataService.First <User>(false);

            var prediction = new Prediction
            {
                LocalGoals   = int.Parse(GoalsLocal),
                MatchId      = MatchId,
                Points       = 0,
                UserId       = user.UserId,
                VisitorGoals = int.Parse(GoalsVisitor),
            };


            var response = await _apiService.Post(parameters.UrlBase, "/api", "/Predictions",
                                                  user.TokenType,
                                                  user.AccessToken, prediction);

            IsRunning = false;
            IsEnabled = true;

            if (!response.IsSuccess)
            {
                // IsRunning = false;
                // IsEnabled = true;
                await _dialogService.ShowMessage("Error", "Ha ocurrido un error al momento de guardar la prediccion, intente luego");

                return;
            }
            await _navigationService.Back();

            //if (LocalGoals2 == null)
            //{
            //    await dialogService.ShowMessage("Error","Necesitas ingresar una prediccion para el Local");
            //    return;
            //}
        }
Beispiel #7
0
        private async void SaveProfile()
        {
            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 (EmployeeCode == 0)
            {
                await dialogService.ShowMessage("Error", "You must enter an employee code.");

                return;
            }

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

                return;
            }

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

                return;
            }

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

                return;
            }

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

                return;
            }


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

            var newProfile = new Employee
            {
                EmployeeId     = EmployeeId,
                FirstName      = FirstName,
                LastName       = LastName,
                EmployeeCode   = EmployeeCode,
                DocumentTypeId = DocumentTypeId,
                LoginTypeId    = LoginTypeId,
                Password       = Password,
                Document       = Document,
                ImageArray     = imageArray,
                Email          = Email,
                Phone          = Phone,
                Address        = Address,
            };

            IsRunning = true;
            IsEnabled = false;

            var urlAPI   = Application.Current.Resources["URLAPI"].ToString();
            var response = await apiService.Put <Employee>(
                urlAPI,
                "/api",
                "/Employees",
                profile.TokenType,
                profile.AccessToken,
                newProfile);

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

                return;
            }

            var mainViewModel = MainViewModel.GetInstance();

            mainViewModel.Employee = this;
            dataService.DeleteAllAndInsert(this);
            await navigationService.Back();
        }
Beispiel #8
0
        async void SelectRecord()
        {
            var mainviewmodel = MainViewModel.GetInstance();

            switch (mainviewmodel.EjecutadoDesde)
            {
            case "SearchInvoicesViewModel":
                try
                {
                    var searchinvoice = SearchInvoicesViewModel.GetInstance();
                    searchinvoice.Calendar = null;
                    searchinvoice.Customer = this;
                    searchinvoice.InvoiceHeaders.Clear();
                    searchinvoice.TotalLineas           = 0;
                    searchinvoice.IsEnabled             = true;
                    searchinvoice.FiltroFechasIsEnabled = true;
                    await navigationService.Back();
                }
                catch (System.Exception ex)
                {
                    await dialogService.ShowMessage("Error", ex.Message);
                }

                break;

            case "NewOrderViewModel":
                try
                {
                    if (CreditHold == true)
                    {
                        var answer = await dialogService.ShowConfirm("Informacion",
                                                                     "El cliente tiene credito retenido. ¿Desea continuar?");

                        if (!answer)
                        {
                            return;
                        }
                    }
                    var newOrderViewModel = NewOrderViewModel.GetInstance();
                    newOrderViewModel.Customer = this;
                    newOrderViewModel.LoadPriceLists();
                    await navigationService.Back();
                }
                catch (System.Exception ex)
                {
                    await dialogService.ShowMessage("Error", ex.Message);
                }

                break;

            case "SearchCashHeaderPage":
                try
                {
                    var searchvashheaderviewmodel = SearchCashHeaderViewModel.GetInstance();
                    searchvashheaderviewmodel.Calendar    = null;
                    searchvashheaderviewmodel.Customer    = this;
                    searchvashheaderviewmodel.TotalLineas = 0;
                    searchvashheaderviewmodel.CashHeaders.Clear();
                    searchvashheaderviewmodel.IsEnabled = true;
                    await navigationService.Back();
                }

                catch (System.Exception ex)
                {
                    await dialogService.ShowMessage("Error", ex.Message);
                }

                break;
            }
        }
Beispiel #9
0
        async void Save()
        {
            if (ProjectId == 0)
            {
                await dialogService.ShowMessage("Error", "You must select a project.");

                return;
            }

            if (ActivityId == 0)
            {
                await dialogService.ShowMessage("Error", "You must select an activity.");

                return;
            }

            ConvertHours();

            if (To <= From)
            {
                await dialogService.ShowMessage("Error", "The hour 'To' must be greather hour 'From'.");

                return;
            }

            IsEnabled = false;
            IsRunning = true;

            var checkConnetion = await apiService.CheckConnection();

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

                return;
            }

            var urlAPI        = Application.Current.Resources["URLAPI"].ToString();
            var mainViewModel = MainViewModel.GetInstance();
            var employee      = mainViewModel.Employee;

            await geolocatorService.GetLocation();

            var newTimeRequest = new NewTimeRequest
            {
                ActivityId        = ActivityId,
                DateReported      = DateReported,
                EmployeeId        = employee.EmployeeId,
                From              = From,
                Latitude          = geolocatorService.Latitude,
                Longitude         = geolocatorService.Longitude,
                IsRepeated        = IsRepeated,
                IsRepeatFriday    = IsRepeatFriday,
                IsRepeatMonday    = IsRepeatMonday,
                IsRepeatSaturday  = IsRepeatSaturday,
                IsRepeatSunday    = IsRepeatSunday,
                IsRepeatThursday  = IsRepeatThursday,
                IsRepeatTuesday   = IsRepeatTuesday,
                IsRepeatWednesday = IsRepeatWednesday,
                ProjectId         = ProjectId,
                Remarks           = Remarks,
                To    = To,
                Until = Until,
            };

            var response = await apiService.Post(
                urlAPI,
                "/api",
                "/Times",
                employee.TokenType,
                employee.AccessToken,
                newTimeRequest);

            IsEnabled = true;
            IsRunning = false;

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

                return;
            }

            await navigationService.Back();
        }
        async void Save()
        {
            if (string.IsNullOrEmpty(Description))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "Debe introducir una descripción de categoría.");

                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
            {
                Description = Description,
            };

            var mainViewModel = MainViewModel.GetInstance();

            var response = await apiService.Post(
                "https://products4grp1api100593.azurewebsites.net",
                "/api",
                "/Categories",
                mainViewModel.Token.TokenType,
                mainViewModel.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.Back();

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

                return;
            }
            var mainViewModel = MainViewModel.GetInstance();

            if (mainViewModel.CurrentUser.Password != CurrentPassword)
            {
                await dialogService.ShowMessage("Error", "the current password does not match");

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

                return;
            }
            if (NewPassword == CurrentPassword)
            {
                await dialogService.ShowMessage("Error", "the current password is the same than current password");

                return;
            }

            if (string.IsNullOrEmpty(ConfirmPassword))
            {
                await dialogService.ShowMessage("Error", "You must enter the current password.");

                return;
            }

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

                return;
            }

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

                return;
            }

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

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var parameters = dataService.First <Parameter>(false);
            var user       = dataService.First <User>(false);
            var request    = new ChangePasswordRequest
            {
                CurrentPassword = CurrentPassword,
                Email           = user.Email, NewPassword = NewPassword
            };

            var response = await apiService.ChangePassword(parameters.UrlBase, "/api", "/Users/ChangePassword",
                                                           user.TokenType, user.AccessToken, request);

            IsRunning = false;
            IsEnabled = true;

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

                return;
            }
            await dialogService.ShowMessage("Confirm", "Your Password has been changed successfully");

            await navigationService.Back();
        }
        async void Save()
        {
            if (String.IsNullOrEmpty(Description))
            {
                await dialogService.ShowMessage("Error", "You must enter a description");

                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 = MainViewModel.GetInstance();

            var product = new Product
            {
                Description  = Description,
                Price        = Price,
                IsActive     = IsActive,
                LastPurchase = LastPurchase,
                Stock        = Stock,
                Remarks      = Remarks,
                CategoryId   = mainViewModel.category.CategoryId,
                Image        = "Sin Imagen"
            };

            var response = await apiService.Post(
                "http://200.76.182.140:8085",
                "/api",
                "/Products",
                mainViewModel.Token.TokenType,
                mainViewModel.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(mainViewModel.category.Products);

            productsViewModel.AddProduct(product);
            await navigationService.Back();

            IsRunning = false;
            IsEnabled = true;
        }
Beispiel #13
0
        async void SaveShipTo()
        {
            try
            {
                var answer = await dialogService.ShowConfirm(
                    "Confirmación",
                    "¿Guardar sucursal?");

                var connection = await netService.CheckConnectivity();

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

                    return;
                }

                if (string.IsNullOrEmpty(NewShipTo.ShipToNum))
                {
                    await dialogService.ShowMessage(
                        "Error",
                        "Debes ingresar un ShipToNum.");

                    return;
                }

                if (string.IsNullOrEmpty(NewShipTo.ShipToName))
                {
                    await dialogService.ShowMessage(
                        "Error",
                        "Debes ingresar nombre de sucursal.");

                    return;
                }

                if (string.IsNullOrEmpty(NewShipTo.Description))
                {
                    await dialogService.ShowMessage(
                        "Error",
                        "Debes seleccionar un pais.");

                    return;
                }

                NewShipTo.IsRunning = true;

                //var UltimoRegistro = dataService
                //.Get<ShipTo>(false)
                //.OrderByDescending(t => t.ShipToId)
                //.FirstOrDefault();

                //if (UltimoRegistro.ShipToId == 0)
                //{
                //    UltimoRegistro.ShipToId = 1;

                //}else{

                //    UltimoRegistro.ShipToId = UltimoRegistro.ShipToId + 1;
                //}

                var shipto = new ShipTo
                {
                    ShipToId          = 0,
                    CustomerId        = NewShipTo.CustomerId,
                    CustNum           = EditCustomer.Customer.CustNum,
                    ShipToNum         = NewShipTo.ShipToNum,
                    Company           = User.Company,
                    ShipToName        = NewShipTo.ShipToName,
                    TerritoryEpicorID = NewShipTo.TerritoryEpicorID,
                    Country           = NewShipTo.Description,
                    State             = NewShipTo.State,
                    City               = NewShipTo.City,
                    Address            = NewShipTo.Address,
                    PhoneNum           = NewShipTo.PhoneNum,
                    Email              = NewShipTo.Email,
                    SincronizadoEpicor = false,
                };



                #region Sincronizo Shipto
                var url = Application.Current.Resources["URLAPI"].ToString();

                var shiptorequest = new SyncShiptoRequest
                {
                    ShipToId          = shipto.ShipToId,
                    CustomerId        = shipto.CustomerId,
                    ShipToNum         = shipto.ShipToNum,
                    CustNum           = shipto.CustNum,
                    Company           = shipto.Company,
                    ShipToName        = shipto.ShipToName,
                    TerritoryEpicorID = shipto.TerritoryEpicorID,
                    Country           = shipto.Country,
                    State             = shipto.State,
                    City               = shipto.City,
                    Address            = shipto.Address,
                    PhoneNum           = shipto.PhoneNum,
                    Email              = shipto.Email,
                    VendorId           = User.VendorId,
                    SincronizadoEpicor = false,
                };


                var response = await apiService
                               .PostMaster(url, "/api/ShipToes", shiptorequest);

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

                    return;
                }

                var syncShiptoRequest = (SyncShiptoRequest)response.Result;
                var ShipToToInsert    = new ShipTo
                {
                    Address            = syncShiptoRequest.Address,
                    City               = syncShiptoRequest.City,
                    Company            = syncShiptoRequest.Company,
                    Country            = syncShiptoRequest.Country,
                    CustNum            = syncShiptoRequest.CustNum,
                    CustomerId         = syncShiptoRequest.CustomerId,
                    Email              = syncShiptoRequest.Email,
                    PhoneNum           = syncShiptoRequest.PhoneNum,
                    ShipToId           = syncShiptoRequest.ShipToId,
                    ShipToName         = syncShiptoRequest.ShipToName,
                    ShipToNum          = syncShiptoRequest.ShipToNum,
                    SincronizadoEpicor = syncShiptoRequest.SincronizadoEpicor,
                    State              = syncShiptoRequest.State,
                    TerritoryEpicorID  = syncShiptoRequest.TerritoryEpicorID,
                    VendorId           = User.VendorId,
                };

                dataService.Insert(ShipToToInsert);
                NewShipTo.IsRunning = false;
                await dialogService.ShowMessage("Exito", "Se inserto el registro con exito.");

                EditCustomer.RefreshShipTo();
                await navigationService.Back();

                #endregion
            }
            catch (Exception ex)
            {
                await dialogService.ShowMessage("Error", ex.Message);
            }
        }
Beispiel #14
0
        private async void NewCustomer()
        {
            //validar los campos:


            if (!Utilities.IsValidEmail(UserName))
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un correo valido.");

                return;
            }

            if (string.IsNullOrEmpty(FirstName))
            {
                await dialogService.ShowMessage("Error", "Debe ingrsar nombres.");

                return;
            }

            if (string.IsNullOrEmpty(LastName))
            {
                await dialogService.ShowMessage("Error", "Debe ingrsar un apellidos.");

                return;
            }

            if (string.IsNullOrEmpty(Phone))
            {
                await dialogService.ShowMessage("Error", "Debe ingrsar un teléfono.");

                return;
            }

            if (string.IsNullOrEmpty(Address))
            {
                await dialogService.ShowMessage("Error", "Debe ingrsar un dirección.");

                return;
            }

            if (DepartmentId == 0)
            {
                await dialogService.ShowMessage("Error", "Debe ingrsar un departamento.");

                return;
            }

            if (CityId == 0)
            {
                await dialogService.ShowMessage("Error", "Debe ingrsar una ciudad.");

                return;
            }

            IsRunning = true;

            await geolocatorService.getLocation();

            var customer = new Customer()
            {
                CityId       = CityId,
                DepartmentId = DepartmentId,
                UserName     = UserName,
                FirstName    = FirstName,
                LastName     = LastName,
                Address      = Address,
                IsUpdated    = IsUpdated,
                Latitude     = geolocatorService.Latitude,
                Longitude    = geolocatorService.Longitud,
                Phone        = Phone,
            };

            var response = await apiService.NewCustomer(customer);

            if (response.IsSuccess && file != null)
            {
                var newCustomer = (Customer)response.Result;
                var response2   = await apiService.SetPhoto(newCustomer.CustomerId, file.GetStream());

                var fileName = $"{newCustomer.CustomerId}.jpg";
                var folder   = "~/Content/Customers";
                var fullPath = $"({folder}/{fileName})";

                customer.Photo = fullPath;

                var response3 = await apiService.Update(customer, "Customers");
            }

            IsRunning = false;

            //aqui pregunso si genoro o no el nuevo cliente

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

                return;
            }

            await dialogService.ShowMessage("Confirmación", response.Message);

            //aqui no envia ala pagina atras, osea la pagina index:
            await navigationService.Back();
        }
Beispiel #15
0
            private async void Save()
            {
                if (string.IsNullOrEmpty(GoalsLocal))
                {
                    await dialogService.ShowMessage("Error", "You must enter a valid local goals.");
                }

                if (string.IsNullOrEmpty(GoalsVisitor))
                {
                    await dialogService.ShowMessage("Error", "You must enter a valid visitor goals.");
                }

                if (!CrossConnectivity.Current.IsConnected)
                {
                    await dialogService.ShowMessage("Error", "Check you internet connection.");

                    await navigationService.Clear();

                    return;
                }


                var isReachable = await CrossConnectivity.Current.IsRemoteReachable("google.com");

                if (!isReachable)
                {
                    await dialogService.ShowMessage("Error", "Check you internet connection.");

                    return;
                }

                isRunning = true;
                isEnabled = false;

                var parameters = dataService.First <Parameter>(false);
                var user       = dataService.First <User>(false);

                var prediction = new Prediction
                {
                    LocalGoals = int.Parse(GoalsLocal)
                    ,
                    MatchId      = MatchId,
                    Points       = 0,
                    UserId       = user.UserId,
                    VisitorGoals = int.Parse(GoalsVisitor),
                };

                var response = await apiService.Post(parameters.URLBase, "/api", "/Predictions", user.TokenType, user.AccessToken, prediction);

                isRunning = false;
                isEnabled = true;

                if (!response.IsSuccess)
                {
                    await dialogService.ShowMessage("Error", "Problem ocurred retrieving user information, try latter.");

                    return;
                }

                await navigationService.Back();
            }
        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 = MainViewModel.GetInstance();

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

            var response = await apiService.Put(
                "http://productszuluapi.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);

            await navigationService.Back();

            IsRunning = false;
            IsEnabled = true;
        }