Beispiel #1
0
        public async Task <IActionResult> AddEstate([FromBody] EstateForAddDto estate)
        {
            var user           = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var estateToCreate = new Estate
            {
                AdType      = estate.Type,
                Title       = estate.Title,
                Description = estate.Description,
                Price       = estate.Price,
                OwnerId     = user,
                Square      = estate.Square,
                Rooms       = estate.Rooms,
                Floors      = estate.Floors,
                Country     = estate.Country,
                City        = estate.City,
                Street      = estate.Street,
                IsActive    = estate.IsActive,
                Created     = DateTime.Now
            };

            var creatEstate = await _repo.AddEstate(estateToCreate);

            return(StatusCode(201));
        }
        private void ButtonAddEstate_Click(object sender, RoutedEventArgs e)
        {
            bool beOwner    = true;
            int  oldOwnerId = 0;

            try
            {
                if (!string.IsNullOrWhiteSpace(_newEstate.Error))
                {
                    return;
                }
                int idCounter = 1;
                foreach (Estate _estate in estateRepository.GetAll())
                {
                    idCounter++;
                }

                _newEstate.EstateID              = idCounter++;
                _newEstate.EstateName            = ((ComboBoxItem)ComboBoxAddEstateName.SelectedItem).Content.ToString();
                _newEstate.EstateInventoryNumber = TextBoxAddEstateInventoryNumber.Text;
                _newEstate.EstateSpace           = double.Parse(TextBoxAddEstateSpace.Text);
                _newEstate.EstateAdress          = TextBoxAddEstateAdress.Text;
                _newEstate.EstateFunction        = ((ComboBoxItem)ComboBoxAddEstateFunction.SelectedItem).Content.ToString();
                _newEstate.EstateYear            = int.Parse(TextBoxAddEstateYear.Text);
                _newEstate.EstateWall            = TextBoxAddEstateWall.Text;
                _newEstate.EstateState           = "Не продан";
                _newEstate.EstateOwner           = ComboBoxAddEstateOwner.Text;
                _newEstate.EstateCostOfSale      = double.Parse(TextBoxAddEstateSale.Text);
                _newEstate.EstateDescription     = TextBoxAddEstateDescription.Text;
                foreach (Owner owner in new OwnerRepository().GetAll())
                {
                    if (_newEstate.EstateOwner.Trim() == owner.OwnerName.Trim())
                    {
                        oldOwnerId = owner.OwnerID;
                        beOwner    = true;
                        break;
                    }
                    else
                    {
                        beOwner = false;
                    }
                }

                if (beOwner == false)
                {
                    WindowAddOwner winAddOwner = new WindowAddOwner(_newEstate.EstateOwner);
                    winAddOwner.ShowDialog();
                    foreach (Owner newOwner in new OwnerRepository().GetAll())
                    {
                        _newEstate.EstateOwnerID = newOwner.OwnerID;
                    }
                }
                else
                {
                    _newEstate.EstateOwnerID = oldOwnerId;
                }

                estateRepository.AddEstate(_newEstate);

                MessageBox.Show("Данные добавлены.");
                this.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка");
            }
        }