private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (tbPrice.Text != string.Empty)
            {
                _itemToUpdate.Price = int.Parse(tbPrice.Text);
            }

            if (tbSquare.Text != string.Empty)
            {
                _itemToUpdate.Square = int.Parse(tbSquare.Text);
            }

            if (tbRoomsCount.Text != string.Empty)
            {
                _itemToUpdate.RoomsCount = int.Parse(tbRoomsCount.Text);
            }

            if (tbAdress.Text != string.Empty)
            {
                _itemToUpdate.Adress = tbAdress.Text;
            }

            _unitOfWork.AdvertisementRepository.Update(_itemToUpdate);

            CustomerWindow customerWindow = new CustomerWindow();

            customerWindow.Show();
            this.Close();
        }
Exemple #2
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            bool isParsedPrice  = false;
            bool isParsedSquare = false;
            bool isParsedCountR = false;

            int price;

            isParsedPrice = int.TryParse(tbPrice.Text, out price);
            if (!isParsedPrice || price < 0)
            {
                MessageBox.Show(this, "Enter price correctly.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                int square;
                isParsedSquare = int.TryParse(tbSquare.Text, out square);
                if (!isParsedSquare || square < 0)
                {
                    MessageBox.Show(this, "Enter square of apartment correctly.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    int roomsCount;
                    isParsedCountR = int.TryParse(tbRoomsCount.Text, out roomsCount);
                    if (!isParsedCountR || roomsCount < 0)
                    {
                        MessageBox.Show(this, "Enter count of rooms correctly.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        var advertisement = new Advertisement()
                        {
                            Price      = price,
                            Square     = square,
                            RoomsCount = roomsCount,
                            Adress     = tbAdress.Text,
                            UserId     = LoginWindow.UserId
                        };
                        var currentUser = CustomerWindow.unitOfWork.UserRepository.FindByID(LoginWindow.UserId);
                        currentUser.MyAdvertisements.Add(advertisement);
                        _unitOfWork.AdvertisementRepository.Insert(advertisement);
                        _unitOfWork.Save();

                        MessageBox.Show("Your advertisement is added.");
                        CustomerWindow customerWindow = new CustomerWindow();
                        customerWindow.Show();
                        this.Close();
                    }
                }
            }
        }
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            var login    = loginText.Text;
            var password = GetMd5HashPassword(passwordBox.Password);

            bool isExistingLogin = false;
            bool isRightPassword = false;

            foreach (var item in ListOfUsers)
            {
                if (item.Login == login)
                {
                    isExistingLogin = true;
                    UserId          = item.UserId;
                    break;
                }
            }

            if (!isExistingLogin)
            {
                MessageBox.Show(this, "Invalid user name", "Authentication Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (isExistingLogin)
            {
                foreach (var item in ListOfUsers)
                {
                    if (item.Password == password)
                    {
                        isRightPassword = true;
                        break;
                    }
                }

                if (!isRightPassword)
                {
                    MessageBox.Show(this, "Invalid password", "Authentication Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            if (isExistingLogin && isRightPassword)
            {
                CustomerWindow customerWindow = new CustomerWindow();
                customerWindow.Show();
                this.Close();
            }
        }