Beispiel #1
0
        /// <summary>
        /// called when user is searching for address value
        /// </summary>
        private void SearchAddress()
        {
            if (SearchedAddress != null)
            {
                ObservableCollection <EstateProperties> newProperties    = new ObservableCollection <EstateProperties>();
                ObservableCollection <EstateProperties> deleteProperties = new ObservableCollection <EstateProperties>();
                EstatePropertiesBusiness epBusiness = new EstatePropertiesBusiness();

                _epBusiness      = epBusiness;
                deleteProperties = new ObservableCollection <EstateProperties>(epBusiness.AllEstateProperties());

                foreach (EstateProperties estate in _estateProperties)
                {
                    if (estate.Address.ToUpper().Contains(SearchedAddress.ToUpper()))
                    {
                        newProperties.Add(estate);
                    }
                }

                foreach (EstateProperties estate in deleteProperties)
                {
                    _estateProperties.Clear();
                }
                foreach (EstateProperties estateProperties in newProperties)
                {
                    _estateProperties.Add(estateProperties);
                }
                GetDollarAmount();
            }
        }
Beispiel #2
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();
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Cleater out all properties and also reset the list
        /// </summary>
        private void ClearEstate()
        {
            EstatePropertiesBusiness epBusiness = new EstatePropertiesBusiness();

            _epBusiness       = epBusiness;
            _estateProperties = new ObservableCollection <EstateProperties>(epBusiness.AllEstateProperties());

            OnPropertyChanged("EstateProperties");
            GetDollarAmount();

            _workingProperty = new EstateProperties()
            {
                Address     = "",
                City        = "",
                Zipcode     = 0,
                Price       = 0,
                Bedrooms    = 0,
                Bathrooms   = 0,
                Fireplace   = false,
                Pool        = false,
                Comment     = "",
                Description = "",
                SqrFeet     = 0,
                State       = ""
            };
            OnPropertyChanged("WorkingProperty");
            DeleteVisible = false;
            UpdateVisible = false;
            AddVisible    = true;
            _errors.Clear();
        }
Beispiel #4
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            EstatePropertiesBusiness epBusiness = new EstatePropertiesBusiness();

            MainViewModel mainViewModel = new MainViewModel(epBusiness);

            MainView mainView = new MainView();

            mainView.DataContext = mainViewModel;
            mainView.Show();
        }
Beispiel #5
0
        public MainViewModel(EstatePropertiesBusiness epBusiness)
        {
            //db = new MongoCRUD("PropertyDB");

            _epBusiness       = epBusiness;
            _estateProperties = new ObservableCollection <EstateProperties>(epBusiness.AllEstateProperties());
            GetDollarAmount();
            _selectedProperty = new EstateProperties();
            _workingProperty  = new EstateProperties();
            _errors           = new ObservableCollection <string>();
            AddVisible        = true;
            SortList          = new ObservableCollection <string>()
            {
                "Price", "City", "Zip", "Bedrooms", "SqrFeet", "State"
            };
        }
Beispiel #6
0
        /// <summary>
        /// Calls the method to delete entry from the database
        /// and deletes entry from the list
        /// </summary>
        private void DeleteEstate()
        {
            if (_selectedProperty != null && _selectedProperty.Id == _workingProperty.Id)
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show($"Are you sure you want to delete this entry?", "Delete Entry", System.Windows.MessageBoxButton.OKCancel);

                if (messageBoxResult == MessageBoxResult.OK)
                {
                    EstatePropertiesBusiness epBusiness = new EstatePropertiesBusiness();
                    _epBusiness = epBusiness;
                    _epBusiness.DeleteEstateProperty(_selectedProperty);
                    ClearEstate();
                }
            }
            else
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show($"Please reselect the estate that is shown in the view area?", "OK", System.Windows.MessageBoxButton.OKCancel);
            }
        }
Beispiel #7
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);
                }
            }
        }