private async Task DeleteProductAction(Product item) { var response = await AppPopupInputService.ShowMessageOkCancelAlertPopup("Remove Product", "Are you sure to remove product?", "OK", "CANCEL"); if (!response.Equals("ok", StringComparison.InvariantCultureIgnoreCase)) { return; } ThreadingHelpers.InvokeOnMainThread(() => { Orders.Remove(item); var orders = Orders.ToList(); Orders.Clear(); Orders = null; Orders = orders; if (IsOrderAvailable) { OrderSubmitText = "SUBMIT ORDER"; } else { OrderSubmitText = "PLACE ORDER"; OrdersHeadingText = "No order has been placed."; } } ); }
private void SaveNewProductNameAction() { try { ThreadingHelpers.InvokeOnMainThread(() => { //LinCComonModel prdNameObj = new LinCComonModel() { Name = NewProductName, Value = NewProductName, ItemId = string.Empty }; //var controlValues = DefaultProductName.ControlValues.ToList(); //controlValues.Add(prdNameObj); //DefaultProductName.ControlValues.Clear(); //DefaultProductName.ControlValues = null; //DefaultProductName.ControlValues = controlValues; //DefaultProductName.DefaultItem = prdNameObj; //DefaultProductName.SelectedIndex = controlValues.Count - 1; //Product.ProductNameId = string.Empty; //Product.ProductName = prdNameObj.Name; //Product.IsNewProductName = true; NewProductName = string.Empty; ProductNameEntryVisibility = false; }); } catch (Exception) { } }
private void PlaceOrderAction() { try { /*ThreadingHelpers.InvokeOnMainThread(async () => * { * AppInitialiserService.SetInitialiser<ProductCataloguePageViewModel>((ProductCataloguePageViewModel vm) => * { * vm.UserDetails = UserDetails; * vm.ProductTypes = App.MasterData.ProductTypeMaster; * }); * * await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower()); * });*/ ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(SupplierCataloguePage).ToLower(), (SupplierCataloguePageViewModel vm) => { vm.UserDetails = UserDetails; vm.ProductTypes = App.MasterData.ProductTypeMaster; }) ); } catch (Exception ex) { } }
public void HideLoading() { ThreadingHelpers.InvokeOnMainThread(async() => { int retry = 0; if (_spinnerPageInstance == null) { return; } while (!_isSpinning && retry <= 5) { await Task.Delay(200); retry++; } if (_spinnerPageInstance != null) { await _navigationService.Navigation.RemovePopupPageAsync(_spinnerPageInstance, true); //await _navigationService.Navigation.PopPopupAsyncSafe(_popupNavigation, true); } _spinnerPageInstance = null; _isSpinning = false; }); }
private void PlaceOrderAction() { if (IsOrderAvailable) { // Save to backend DB ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(UserDashboardPage).ToLower(), (UserDashboardPageViewModel vm) => { vm.UserDetails = App.UserDetails; vm.Products = this.Products; //vm.Orders = Orders.Where(o => o.IsSubmitted).ToList(); }) ); } else { ThreadingHelpers.InvokeOnMainThread(async() => { AppInitialiserService.SetInitialiser <ProductCataloguePageViewModel>((ProductCataloguePageViewModel vm) => { vm.UserDetails = UserDetails; vm.ProductTypes = App.MasterData.ProductTypeMaster; //vm.ProductList = Products; //vm.Product = new Product(); //vm.ProductTypes = App.MasterData.ProductTypeMaster; }); await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower()); }); } }
private async Task SupplierTapped(LinCUser item) { try { AppSpinner.ShowLoading(); var response = await _services.UserService.GetUserProducts(UserDetails.UserId, item.UserId, SelectedProductType.ProductTypeId); if (response.Data.Item1 != null && response.Data.Item1.Count > 0) { ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(ProductsPage).ToLower(), (ProductsPageViewModel vm) => { vm.UserDetails = App.UserDetails; vm.Products = response.Data.Item1; vm.SupplierId = item.UserId; }) ); } AppSpinner.HideLoading(); } catch (Exception ex) { } }
internal static async Task NavigatePopToRootAsync() { var modalCount = App.NavigationRoot.Navigation.ModalStack.Count; for (int currModal = 0; currModal < modalCount; currModal++) { ThreadingHelpers.InvokeOnMainThread(async() => await App.NavigationRoot.Navigation.PopModalAsync(false)); } }
private void CallCustomerCare() { ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(ChatPage).ToLower(), (ChatPageViewModel vm) => { vm.UserDetails = App.UserDetails; }) ); }
private void Register() { ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(RegistrationPage).ToLower(), (RegistrationPageViewModel vm) => { //vm.UserDetails = new LinCUser(); }) ); }
private void ProductCatAction() { ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower(), (ProductCataloguePageViewModel vm) => { vm.UserDetails = App.UserDetails; }) ); }
private void IncreaseQuantityAction(Product item) { int qty = item.Quantity; qty += 1; ThreadingHelpers.InvokeOnMainThread(() => { item.Quantity = qty; item.Price = (item.UnitPrice == 0 ? 10:item.UnitPrice) * qty; }); }
private void DisplayNetworkError(ViewModelError error) { var alert = new ErrorAlert() { Description = error.Description, Title = _errorTitle, ViewModelType = this.GetType(), Severity = ViewModelError.ErrorSeverity.Warning }; ThreadingHelpers.InvokeOnMainThread(async() => await _popupInputService.ShowMessageOkAlertPopup(alert.Title, alert.Description, "OK")); }
public void ShowLoading(bool isCancellable = true) { ThreadingHelpers.InvokeOnMainThread(async() => { if (_spinnerPageInstance == null) { _spinnerPageInstance = new ProgressSpinnerPage(isCancellable); await _navigationService.Navigation.PushPopupAsyncSafe(_spinnerPageInstance, _popupNavigation, true) .ContinueWith((t) => _isSpinning = true); } }); }
private async Task RegisterAction() { //AppSpinner.ShowLoading(); //await GetMasterData(); //AppSpinner.HideLoading(); ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(RegistrationPage).ToLower(), (RegistrationPageViewModel vm) => { //vm.UserDetails = new LinCUser(); }) ); }
private async Task SubmitProductsAction() { if (Products == null || Products.Count == 0) { await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", "No product available to submit.", "OK"); return; } var selectedPrdCount = Products.Count(p => p.IsSubmitted); if (selectedPrdCount == 0) { await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", "Please select one product to submit.", "OK"); return; } // save to db try { AppSpinner.ShowLoading(); var response = await _services.UserService.SaveOrders(Products, UserDetails, SupplierId); AppSpinner.HideLoading(); if (response.Data != null) { ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(UserDashboardPage).ToLower(), (UserDashboardPageViewModel vm) => { vm.UserDetails = App.UserDetails; vm.Products = Products; vm.Orders = response.Data; }) ); } else { await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", "Unable to place order. Please try again.", "OK"); } } catch (Exception ex) { } }
private void DecreaseQuantityAction(Product item) { int qty = item.Quantity; qty -= 1; if (qty < 1) { qty = 1; } ThreadingHelpers.InvokeOnMainThread(() => { item.Quantity = qty; item.Price = item.UnitPrice * qty; }); }
private void AddProductAction() { ThreadingHelpers.InvokeOnMainThread(async() => { AppInitialiserService.SetInitialiser <AddProductPageViewModel>((AddProductPageViewModel vm) => { vm.UserDetails = UserDetails; vm.ProductList = Products; vm.Product = new Product(); vm.ProductTypes = App.MasterData.ProductTypeMaster; vm.IsAddProduct = true; }); await AppNavigationService.GoToAsync(nameof(AddProductPage).ToLower()); }); }
private void AddProductAction() { ThreadingHelpers.InvokeOnMainThread(async() => { // AppInitialiserService.SetInitialiser<AddProductPageViewModel>((AddProductPageViewModel vm) => // { // vm.UserDetails = UserDetails; // vm.ProductList = Products; // vm.Product = new Product(); // vm.ProductTypes = App.MasterData.ProductTypeMaster; // vm.IsAddProduct = true; // }); await AppNavigationService.GoBackAsync(); }); }
private async Task AddToCartAction() { try { ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(CartPage).ToLower(), (CartPageViewModel vm) => { vm.UserDetails = App.UserDetails; vm.Products = this.Products; vm.Orders = this.Products.Where(p => p.ShouldAddToCart).ToList(); }) ); } catch (Exception ex) { } }
public async Task DeleteProductAction(Product item) { var response = await AppPopupInputService.ShowMessageOkCancelAlertPopup("Remove Product", "Are you sure to remove product?", "OK", "CANCEL"); if (!response.Equals("ok", StringComparison.InvariantCultureIgnoreCase)) { return; } ThreadingHelpers.InvokeOnMainThread(() => { Products.Remove(item); var prds = Products.ToList(); Products.Clear(); Products = null; Products = prds; } ); }
private async Task EditProductAction(Product item) { AppSpinner.ShowLoading(); await Task.Delay(10); ThreadingHelpers.InvokeOnMainThread(async() => { AppInitialiserService.SetInitialiser <ProductCataloguePageViewModel>((ProductCataloguePageViewModel vm) => { vm.UserDetails = UserDetails; vm.Products = Products; }); await AppNavigationService.GoToAsync(nameof(ProductCataloguePage).ToLower()); //await AppNavigationService.GoBackAsync(); } ); AppSpinner.HideLoading(); }
public async Task EditProductAction(Product item) { AppSpinner.ShowLoading(); await Task.Delay(10); ThreadingHelpers.InvokeOnMainThread(async() => { // AppInitialiserService.SetInitialiser<AddProductPageViewModel>((AddProductPageViewModel vm) => // { // vm.UserDetails = UserDetails; // vm.ProductList = Products; // vm.Product = item; // vm.IsAddProduct = false; // }); await AppNavigationService.GoBackAsync(); } ); AppSpinner.HideLoading(); }
private void AdjustQuantityAction(string item) { int qty = Product.Quantity; if (item.Equals("Minus")) { qty -= 1; } else { qty += 1; } if (qty <= 0) { qty = 1; } ThreadingHelpers.InvokeOnMainThread(() => { Product.Quantity = qty; }); }
/// <summary> /// Handle popup page Navigation /// </summary> /// <typeparam name="T"></typeparam> /// <param name="popup"></param> /// <returns></returns> private async Task <T> Navigate <T>(CustomGeneralPopupView <T> popup) { if (Device.RuntimePlatform == "Test") { return(default(T)); } ThreadingHelpers.InvokeOnMainThread(async() => { await _popupNavigation.PushAsync(popup); }); // await for the user to enter the text input var result = await popup.PageClosingTask; // Pop the page from Navigation Stack ThreadingHelpers.InvokeOnMainThread(async() => { try { await _popupNavigation.RemovePageAsync(popup); } catch { try { await _popupNavigation.PopAsync(); } catch { } } }); return(result); }
private async Task NextButtonTapped() { if (SelectedProductType != null) { if (Product.ProductTypeId == 0) { Product.ProductTypeId = SelectedProductType.ProductTypeId; Product.ProductType = SelectedProductType.ProductTypeName; } } if (SelectedProductCategory != null) { if (Product.ProductCategoryId == 0) { Product.ProductCategoryId = SelectedProductCategory.ProductCategoryId; Product.ProductCategory = SelectedProductCategory.ProductCategoryName; } } if (Product.Quantity == 0) { await AppPopupInputService.ShowMessageOkAlertPopup("Add Product", "Quantity cannot be zero.", "OK"); return;; } if (Product.ProductTypeId == 0) { await AppPopupInputService.ShowMessageOkAlertPopup("Add Product", "Please select product type.", "OK"); return;; } if (Product.ProductCategoryId == 0) { await AppPopupInputService.ShowMessageOkAlertPopup("Add Product", "Please select product category.", "OK"); return;; } //ThreadingHelpers.InvokeOnMainThread(async () => // await AppNavigationService.GoToAsync(nameof(ChatPage).ToLower(), // (ChatPageViewModel vm) => // { // }) // ); try { if (ProductList == null) { ProductList = new List <Product>(); } if (IsAddProduct) { ProductList.Add(Product); } ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(ReviewProductsPage).ToLower(), (ReviewProductsPageViewModel vm) => { vm.UserDetails = UserDetails; vm.Products = ProductList; }) ); } catch (Exception ex) { } }
private async Task NextButtonTapped() { try { if (!await ValidateFields()) { return; } //if (!IsOrgVisible) //{ // UserDetails.Organization = string.Empty; //} //switch (LinCAppUserType) //{ // case LinCUserType.Consumer: // UserDetails.Organization = string.Empty; // UserDetails.RegisterType = string.Empty; // break; // default: // break; //} AppSpinner.ShowLoading(); if (ShouldUseCurrentLocation) { var status = await CheckPermission(Permission.Location); if (status == PermissionStatus.Granted) { var location = await GetUserLocation(); if (location != null) { UserDetails.Latitude = location.Latitude; UserDetails.Longitude = location.Longitude; var placemark = await GetUserAddressFromLatLong(location.Latitude, location.Longitude); if (placemark != null) { UserDetails.Pin = string.IsNullOrEmpty(placemark.PostalCode) ? 0 : int.Parse(placemark.PostalCode); UserDetails.AddressLine1 = $"{placemark.FeatureName}, {placemark.SubLocality}, {placemark.Locality}"; UserDetails.AddressLine2 = string.Empty; UserDetails.CountryId = CountryMasterData.Where(l => l.CountryCode.Equals(placemark.CountryCode)).FirstOrDefault().CountryId; UserDetails.StateId = StateMasterData.Where(l => l.StateName.Contains(placemark.AdminArea)).FirstOrDefault().StateId; } } } } else { string countryName = CountryMasterData.Where(l => l.CountryId.Equals(UserDetails.CountryId)).FirstOrDefault()?.CountryName; string stateCode = StateMasterData.Where(l => l.StateId.Equals(UserDetails.StateId)).FirstOrDefault()?.StateCode; string address = $"{UserDetails.AddressLine1} {UserDetails.AddressLine2} {stateCode} {countryName}"; // get location from address var location = await GetUserLocationFromAddress(address); if (location != null) { UserDetails.Latitude = location.Latitude; UserDetails.Longitude = location.Longitude; //var placemark = await GetUserAddressFromLatLong(location.Latitude, location.Longitude); } } if (!UserDetails.UserTypeId.Equals(2)) { if (UserDetails.ProductTypeIds.Count > 0) { UserDetails.ProductTypeIds = UserDetails.ProductTypeIds; } } else { UserDetails.ProductTypeIds = null; } // Create User //string userTypeId = UserDetails.UserTypeId; //remove later UserDetails.UserId = null; var response = await _services.UserService.CreateUserAsync(null, null, UserDetails); //response.ServiceErrorCode = LinCTrasactionStatus.Success.ToString(); // remove later if (response.ServiceErrorCode.Equals(LinCTrasactionStatus.Success.ToString())) { ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoBackAsync()); /*UserDetails = response.Data; * App.UserDetails = UserDetails; * * // get product category list * var responsePrdCategory = await _services.UserService.GetProductCategoryByUser(UserDetails.UserId.Value); * * if(responsePrdCategory.ServiceErrorCode.Equals(LinCTrasactionStatus.Success.ToString())) * { * App.MasterData.ProductCategoryList = responsePrdCategory.Data.ProductCategoryList; * * ThreadingHelpers.InvokeOnMainThread(async () => * await AppNavigationService.GoToAsync(nameof(AddProductPage).ToLower(), * (AddProductPageViewModel vm) => * { * vm.UserDetails = UserDetails; * vm.IsAddProduct = true; * vm.ProductTypes = App.MasterData.ProductTypeMaster; * }) * ); * } * else * { * AppErrorService.AddError(response); * }*/ } else { AppErrorService.AddError(response); } AppSpinner.HideLoading(); AppErrorService.ProcessErrors(); } catch (Exception ex) { HandleUIError(ex); } }
private async Task Login() { try { //if(UserDetails.Email) AppSpinner.ShowLoading(); var response = await _services.UserService.GetUserAsync(null, null, null, UserDetails.UserName, UserDetails.UserSecret); //Get Products & orders if (response.Data.Item1 != null) { App.UserDetails = response.Data.Item1; int? supplierId = null; List <Product> prdList = new List <Product>(); switch (App.UserDetails.UserTypeId) { case 1: // SUPPLIER var responseProdCat = await _services.UserService.GetProductCategoryByUser(App.UserDetails.UserId.Value); App.MasterData.ProductCategoryList = responseProdCat.Data.ProductCategoryList; var productTypes = responseProdCat.Data.ProductCategoryList.Select(l => l.ProductTypeId).Distinct(); supplierId = App.UserDetails.UserId.Value; foreach (var item in productTypes) { var products = await _services.UserService.GetUserProducts(App.UserDetails.UserId.Value, supplierId, item); if (products.Data.Item1 != null && products.Data.Item1.Count > 0) { prdList.AddRange(products.Data.Item1); } } break; case 2: //CONSUMER break; case 3: // VOLUNTEER break; default: break; } // get orders for the user var orders = _services.UserService.GetOrders(App.UserDetails); ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(UserDashboardPage).ToLower(), (UserDashboardPageViewModel vm) => { vm.UserDetails = App.UserDetails; vm.Products = prdList; vm.Orders = orders.Result.Data; }) ); } else { AppErrorService.AddError(response); } AppSpinner.HideLoading(); AppErrorService.ProcessErrors(); } catch (Exception ex) { HandleUIError(ex); } }
private async Task SubmitProductsAction() { if (Products == null || Products.Count == 0) { await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", "No product available to submit.", "OK"); return; } try { AppSpinner.ShowLoading(); // Save to backend DB var response = await _services.UserService.SaveProduct(Products, UserDetails.UserId); AppSpinner.HideLoading(); if (response.Data) { var productTypes = App.MasterData.ProductCategoryList.Select(l => l.ProductTypeId).Distinct(); int?supplierId = null; switch (App.UserDetails.UserTypeId) { case 1: // SUPPLIER supplierId = App.UserDetails.UserId.Value; break; case 2: //CONSUMER break; case 3: // VOLUNTEER break; default: break; } List <Product> prdList = new List <Product>(); foreach (var item in productTypes) { var products = await _services.UserService.GetUserProducts(App.UserDetails.UserId.Value, supplierId, item); if (products.Data.Item1 != null && products.Data.Item1.Count > 0) { prdList.AddRange(products.Data.Item1); } } ThreadingHelpers.InvokeOnMainThread(async() => await AppNavigationService.GoToAsync(nameof(UserDashboardPage).ToLower(), (UserDashboardPageViewModel vm) => { vm.UserDetails = App.UserDetails; vm.Products = prdList; }) ); } else { await AppPopupInputService.ShowMessageOkAlertPopup("Submit Product", response.ErrorMessage, "OK"); } } catch (Exception ex) { } }
private void ShowHideFlyout() { ThreadingHelpers.InvokeOnMainThread(() => ShowFlyoutCommand.Execute()); }
public static async Task NavigateModallyToAsync(Page page, bool animated = true) { ThreadingHelpers.InvokeOnMainThread(async() => await App.NavigationRoot.Navigation.PushModalAsync(page, animated).ConfigureAwait(false)); }