private async void DoSaveFarm()
        {
            //Add Farmtype from picker and user id from UserSettings
            if (SelectedType != null)
            {
                _currentFarm.FarmType_ID = SelectedType.ID;
            }
            _currentFarm.User_ID = UserSettings.UserId;

            FarmValidator    validator = new FarmValidator();
            ValidationResult result    = validator.Validate(_currentFarm);

            if (result.IsValid)
            {
                try
                {
                    if (!Config.TestMode)
                    {
                        await RunSafe(SaveFarm());
                    }
                    await NavigationService.GoBackAsync();
                }
                catch (Exception ex)
                {
                    await PageDialog.AlertAsync("Unable to save farm data", "Error", "OK");

                    MetricsManager.TrackException("Error saving farm details", ex);
                }
            }
            else
            {
                ValidationErrorMessage = result.Errors[0].ErrorMessage;
                ShowValidationErrors   = true;
            }
        }
Esempio n. 2
0
        public string FarmInputValidation(Farm _farmInformation, string _actionType)
        {
            Farm          _farm     = new Farm();
            FarmValidator validator = new FarmValidator(_actionType);

            FluentValidation.Results.ValidationResult results = validator.Validate(_farmInformation);

            bool validationSucceeded = results.IsValid;
            IList <FluentValidation.Results.ValidationFailure> failures = results.Errors;

            string _errorMessage = "";

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    /*"Property " + failure.PropertyName + " failed validation. Error was: " */
                    _errorMessage += failure.ErrorMessage + " <br> ";
                }
            }

            else
            {
                _errorMessage = "Success";
            }

            return(_errorMessage);
        }