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(); }
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 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); } }
protected virtual bool Validate(Dictionary <string, object> properties = null, Dictionary <string, string> propertiesDisplayName = null, List <Tuple <string, bool, string> > validators = null) { // clean any inline val property AppErrorService.ClearInlineValidators(); if (properties?.Count > 0) { if (ValidatePropertyList(properties, propertiesDisplayName, validators)) { return(true); } } else { var isValid = ValidateProperties(null, validators); if (isValid) { return(true); } } string formattedErrors = ""; var errors = GetAllErrors(); // invalid but no errors: move on if (!errors.Any()) { return(true); } foreach (var key in errors.Keys) { // TODO we would need to replace the CamelCase filed key with a globalized name // in the meantime, we de-camel case //formattedErrors += $"\n\u2022 {key.SplitCamelCase()} : {string.Join("\n", errors[key])}"; if (errors.Keys.Count == 1) { formattedErrors = string.Join("\n", errors[errors.Keys.First()]); } else { formattedErrors += $"\u2022 {string.Join("\n", errors[key])}\n"; } // replace property name with display name if (propertiesDisplayName != null) { formattedErrors = propertiesDisplayName.Aggregate(formattedErrors, (current, propertyDisplayName) => current.Replace(propertyDisplayName.Key, propertyDisplayName.Value)); } // split camel case formattedErrors = formattedErrors.SplitCamelCase(); } formattedErrors = formattedErrors.ReplaceLast("\n", ""); AppErrorService.AddError(formattedErrors, ViewModelError.ErrorAction.Display, ViewModelError.ErrorSeverity.Warning, errors: errors); AppErrorService.ProcessErrors(); return(false); }
protected void OnError(object param) { var error = (Exception)param; AppErrorService.AddError(error.Message, ViewModelError.ErrorAction.DisplayAndLog, ViewModelError.ErrorSeverity.Error); }