private async Task UploadHundle() { var validator = new ValidationHelper(); try { Position position = new Position(); var request = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location); if (request[Permission.Location] == PermissionStatus.Granted) { position = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(5)); } var createRequest = new ImageModel.R { Description = _description, Hashtag = _hashtag, Latitude = position.Latitude, Longitude = position.Longitude }; var(success, error) = await _requestProvider .PostFormDataAsync <ImageModel.R, ImageModel.S, ImageModel.E>( GlobalSetting.Instance.ImageEndpoint, createRequest, _image?.GetStream(), "image" ); if (error != null) { validator.AddErrors(nameof(Description), error.Children.Description.Errors); validator.AddErrors(nameof(Hashtag), error.Children.Hashtag.Errors); validator.AddErrors(nameof(Latitude), error.Children.Latitude.Errors); validator.AddErrors(nameof(Longitude), error.Children.Longitude.Errors); validator.AddErrors(nameof(Image), error.Children.Image.Errors); } if (!Validate(validator)) { return; } if (success != null) { await LoadAll(); await _context.Navigation.PopAsync(); } } catch (Exception e) { Debug.WriteLine($"--- Error: {e.StackTrace}"); } }
private async Task CreateHundle() { var validator = new ValidationHelper(); try { var createRequest = new CreateModel.R { UserName = _userName, Email = _email, Password = _password }; var(success, error) = await _requestProvider .PostFormDataAsync <CreateModel.R, CreateModel.S, CreateModel.E>( GlobalSetting.Instance.SignUpEndpoint, createRequest, _avatar?.GetStream(), "avatar" ); if (error != null) { validator.AddErrors(nameof(UserName), error.Children.Username.Errors); validator.AddErrors(nameof(Email), error.Children.Email.Errors); validator.AddErrors(nameof(Password), error.Children.Password.Errors); validator.AddErrors(nameof(Avatar), error.Children.Avatar.Errors); } if (!Validate(validator)) { return; } if (success != null) { await Settings.Set(Settings.Key.IsLogged, true); await Settings.Set(Settings.Key.Avatar, success.Avatar); await Settings.Set(Settings.Key.Token, success.Token); App.SetMainPage(new Gallery()); } } catch (Exception e) { Debug.WriteLine($"--- Error: {e.StackTrace}"); } }
public void AddErrors(string propertyName, HashSet <string> validationResults) { ValidationHelper.AddErrors(Errors, propertyName, validationResults); }