private void buttonSave_Click(object sender, EventArgs e)
        {
            realEsate = db.RealEstate.Single(x => x.Id == realEsate.Id);

            if (String.IsNullOrWhiteSpace(textBoxStreet.Text) ||
                String.IsNullOrWhiteSpace(textBoxPrice.Text) ||
                String.IsNullOrWhiteSpace(textBoxDescription.Text))
            {
                MessageBox.Show("Fields can not be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                realEsate.Street      = textBoxStreet.Text;
                realEsate.Description = textBoxDescription.Text;
                realEsate.Rooms       = Convert.ToInt32(numericUpDownRooms.Value);
                realEsate.Floor       = Convert.ToInt32(numericUpDownFloor.Value);
            }

            Cities city;

            Enum.TryParse(comboBoxCity.SelectedValue.ToString(), out city);
            realEsate.City = city;

            if (FormRealEstateCreator.CheckPrice(textBoxPrice.Text))
            {
                realEsate.Price = Convert.ToInt32(textBoxPrice.Text);
            }
            else
            {
                MessageBox.Show("Invalid price value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool hasPhoto = false;
            int  photoIdx = 0;

            foreach (var arr in photoSlider)
            {
                if (arr != null)
                {
                    if (photoSlider[photoIdx++].GetUpperBound(0) > 1)
                    {
                        hasPhoto = true;
                    }
                }
            }
            if (!hasPhoto)
            {
                MessageBox.Show("Pick at least one photo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            realEsate.PhotoSlider = ImageManip.PhotoSliderToByteArray(photoSlider);

            db.SaveChanges();

            textBoxStreet.Text       = String.Empty;
            textBoxDescription.Text  = String.Empty;
            textBoxPrice.Text        = "0";
            numericUpDownRooms.Value = 1;
            numericUpDownFloor.Value = 1;
            pictureBoxSlider.Image   = null;
            photoNumber           = 0;
            labelPhotoNumber.Text = "1/5";
        }
Exemplo n.º 2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            FormRealEstateCreator realEstateManager = new FormRealEstateCreator();

            realEstateManager.ShowDialog();
        }