Example #1
0
        /// <summary>
        /// Calls the method to insert entry into the database
        /// and adds the entry to the end of the list
        /// </summary>
        private void AddEstate()
        {
            _errors.Clear();
            EstateValidator validator = new EstateValidator();

            ValidationResult results = validator.Validate(_workingProperty);

            if (results.IsValid == false)
            {
                foreach (ValidationFailure failure in results.Errors)
                {
                    _errors.Add($"{failure.ErrorMessage}");
                    OnPropertyChanged("Errors");
                }
            }
            else
            {
                if (_workingProperty != null)
                {
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show($"Are you sure you want to add this entry?", "Add Entry", System.Windows.MessageBoxButton.OKCancel);

                    if (messageBoxResult == MessageBoxResult.OK)
                    {
                        EstatePropertiesBusiness epBusiness = new EstatePropertiesBusiness();
                        _epBusiness = epBusiness;
                        _epBusiness.AddEstateProperty(_workingProperty);
                        ClearEstate();
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Validates the working property and then calls the update crud operation
        /// </summary>
        private void UpdateEstate()
        {
            _errors.Clear();
            //OnPropertyChanged("WorkingProperty");
            // Instantiate the validator and save the result
            EstateValidator  validator = new EstateValidator();
            ValidationResult results   = validator.Validate(_workingProperty);

            // if the result is false spit out errors
            if (results.IsValid == false)
            {
                foreach (ValidationFailure failure in results.Errors)
                {
                    _errors.Add($"{failure.ErrorMessage}");
                    OnPropertyChanged("Errors");
                }
            }
            // if no errors call the CRUD operations update method
            else
            {
                if (_selectedProperty.Id == _workingProperty.Id && _selectedProperty != null && _workingProperty != null)
                {
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show($"Are you sure you want to Update this entry?", "Update Entry", System.Windows.MessageBoxButton.OKCancel);

                    if (messageBoxResult == MessageBoxResult.OK)
                    {
                        EstatePropertiesBusiness epBusiness = new EstatePropertiesBusiness();
                        _epBusiness = epBusiness;
                        _epBusiness.UpdateEstateProperty(_workingProperty);
                        ClearEstate();
                    }
                }
                else
                {
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show($"Please reselect the estate that is shown in the view area?", "OK", System.Windows.MessageBoxButton.OKCancel);
                }
            }
        }