Example #1
0
        /// <summary>
        ///     Verifies the required fields selected.
        /// </summary>
        /// <returns></returns>
        private int VerifyRequiredFieldsSelected()
        {
            //Verify Room Values
            if (_txtRoomNumber.Text.Trim() == String.Empty || _txtRoomTitle.Text.Trim() == String.Empty || _txtMaxOccupancy.Text == String.Empty || _cbRoomType.SelectedValue == "NULL")
            {
                return(-1);
            }
            if (_txtPrimaryAddress.Text.Trim() == String.Empty || _txtCity.Text.Trim() == String.Empty || _txtZip.Text.Trim() == String.Empty || _cbState.SelectedValue == "NULL")
            {
                return(-1);
            }

            var db = new UrbanDataContext();

            //Building Exists for another user check
            if (BuildingUtilities.DoesBuildingAlreadyExistNotForUser(ref db, _txtPrimaryAddress.Text.Trim(), _txtSecondaryAddress.Text.Trim(), _txtCity.Text.Trim(), _txtZip.Text.Trim(), _cbState.SelectedValue, Cu.Id))
            {
                return(-2);
            }

            var existingBuilding = BuildingUtilities.DoesBuildingAlreadyExist(ref db, _txtPrimaryAddress.Text.Trim(), _txtSecondaryAddress.Text.Trim(), _txtCity.Text.Trim(), _txtZip.Text.Trim(), _cbState.SelectedValue, Cu.Id);

            if (existingBuilding != null)
            {
                //return existingBuilding.Id;
                if (RoomUtilities.DoesRoomExistWithNumber(ref db, existingBuilding.Id, _txtRoomNumber.Text.Trim()))
                {
                    return(-3);
                }
            }

            return(1);
        }
        /// <summary>
        ///     Handles the Click event of the _btnSave control.
        /// </summary>
        /// <param name = "sender">The source of the event.</param>
        /// <param name = "e">The <see cref = "System.EventArgs" /> instance containing the event data.</param>
        protected void _btnSave_Click(object sender, EventArgs e)
        {
            var      db = new UrbanDataContext();
            Building building;

            if (BuildingId > 0)
            {
                building = db.Manager.Building.GetByKey(BuildingId);
            }
            else
            {
                building = new Building {
                    UserID = Cu.Id
                };
                db.Building.InsertOnSubmit(building);
            }

            building.Name             = _txtBuildingName.Text.Trim() == String.Empty ? null : _txtBuildingName.Text.Trim();
            building.PrimaryAddress   = _txtPrimaryAddress.Text.Trim() == String.Empty ? null : _txtPrimaryAddress.Text.Trim();
            building.SecondaryAddress = _txtSecondaryAddress.Text.Trim() == String.Empty ? null : _txtSecondaryAddress.Text.Trim();
            building.City             = _txtCity.Text.Trim() == String.Empty ? null : _txtCity.Text.Trim();
            building.Zip   = _txtZip.Text.Trim() == String.Empty ? null : _txtZip.Text.Trim();
            building.State = _cbState.SelectedValue == "NULL" ? null : _cbState.SelectedValue;

            var existingBuilding = BuildingUtilities.DoesBuildingAlreadyExist(ref db, building.Name, building.PrimaryAddress, building.SecondaryAddress, building.City, building.Zip, building.State, Cu.Id);

            if (existingBuilding != null && existingBuilding.Id != building.Id)
            {
                WriteFeedBackMaster(FeedbackType.Warning, "Building already exists with this information");
                return;
            }

            if (BuildingUtilities.DoesBuildingAlreadyExistNotForUser(ref db, building.PrimaryAddress, building.SecondaryAddress, building.City, building.Zip, building.State, Cu.Id))
            {
                WriteFeedBackMaster(FeedbackType.Warning, "Building already exists with this information for another user");
                return;
            }

            db.SubmitChanges();

            RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/App/Pages/MyAccount.aspx?message={0}", BuildingId > 0 ? "building updated" : "building created"));
        }