private async Task PickerTapped(ProductType item)
        {
            try
            {
                AppSpinner.ShowLoading();

                var response = await _services.UserService.GetSuppliers(UserDetails.UserId.Value, item.ProductTypeId, 4);

                if (response.Data.Item1 != null && response.Data.Item1.Count > 0)
                {
                    IsSupplierSearched = true;
                    Suppliers          = response.Data.Item1;
                }
                else
                {
                    Suppliers          = null;
                    IsSupplierSearched = false;
                }

                AppSpinner.HideLoading();
            }
            catch (Exception ex)
            {
            }
        }
        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)
            {
            }
        }
Esempio n. 3
0
        protected void HandleUIError(Exception ex, bool hideSpinner = true, ViewModelError.ErrorAction action = ViewModelError.ErrorAction.DisplayAndLog)
        {
            string title = null;

            if (hideSpinner)
            {
                AppSpinner.HideLoading();
            }

            if (ex is HandledException exception && !exception.IsLog)
            {
                action = ViewModelError.ErrorAction.Display;
            }

            if (ex is HandledException exception2)
            {
                title = exception2.Title;
            }

            // hack: we just use this exception to surface messages to ui from any lib without including it
            if (ex is RankException)
            {
                action = ViewModelError.ErrorAction.Display;
            }

            AppErrorService.AddError(ex.Message, action, ViewModelError.ErrorSeverity.Error, title, ex: ex);
            AppErrorService.ProcessErrors();
        }
        /// <summary>
        /// Loads the map.
        /// </summary>
        /// <returns>The map.</returns>
        private async Task LoadMap()
        {
            AppSpinner.ShowLoading();
            await CheckLocationPermission();
            await InitializeGoogleMap();

            AppSpinner.HideLoading();
        }
Esempio n. 5
0
        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)
            {
            }
        }
Esempio n. 6
0
        public async Task GetMasterData()
        {
            try
            {
                AppSpinner.ShowLoading();
                var lookUpData = await _services.MasterDataService.GetMasterData();

                App.MasterData = lookUpData.Data;
            }
            catch (Exception ex)
            {
            }
            finally
            {
                AppSpinner.HideLoading();
            }
        }
        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();
        }
Esempio n. 8
0
        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();
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
        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)
            {
            }
        }
Esempio n. 11
0
        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);
            }
        }