/// <summary>
 /// Initializes a new instance of the <see cref="BuildingSerialObj"/> class.
 /// </summary>
 /// <param name="b">The b.</param>
 /// <param name="rList">The r list.</param>
 public BuildingSerialObj(Building b, IEnumerable<Room> rList)
 {
     BuildAddress(b);
     foreach (var r in rList)
     {
         BuildContent(r);
     }
 }
 /// <summary>
 /// Builds the address.
 /// </summary>
 /// <param name="b">The b.</param>
 private void BuildAddress(Building b)
 {
     var sb = new StringBuilder();
     sb.Append(b.PrimaryAddress + " ");
     if (b.SecondaryAddress != null)
         sb.Append(b.SecondaryAddress + " ");
     sb.Append(b.City + " ");
     sb.Append(b.Zip + " ");
     sb.Append(b.State + " ");
     Address = sb.ToString();
 }
 /// <summary>
 ///     Loads the page fields.
 /// </summary>
 /// <param name = "b">The b.</param>
 private void LoadPageFields(Building b)
 {
     if (b != null)
     {
         _txtBuildingName.Text = b.Name;
         _txtPrimaryAddress.Text = b.PrimaryAddress;
         _txtSecondaryAddress.Text = b.SecondaryAddress;
         var li = _cbState.FindItemByValue(b.State);
         if (li != null) li.Selected = true;
         _txtCity.Text = b.City;
         _txtZip.Text = b.Zip;
     }
     else
     {
         _btnSave.Text = "Create Building";
     }
 }
 private void OnBuildingListRemove(Building entity)
 {
     SendPropertyChanging(null);
     entity.User = null;
     SendPropertyChanged(null);
 }
 private void OnBuildingListAdd(Building entity)
 {
     SendPropertyChanging(null);
     entity.User = this;
     SendPropertyChanged(null);
 }
        /// <summary>
        ///     Processes the building creation.
        /// </summary>
        /// <param name = "db">The db.</param>
        /// <param name = "userId">The user id.</param>
        /// <param name = "params">The @params.</param>
        /// <returns></returns>
        public static int ProcessBuildingCreation(ref UrbanDataContext db, int userId, ProcessBuildingCreationParams @params)
        {
            //Check if already exists then return buidling Id
            var existingBuilding = DoesBuildingAlreadyExist(ref db, @params.PrimaryAddress, @params.SecondaryAddress, @params.City, @params.Zip, @params.State, userId);
            if (existingBuilding != null)
                return existingBuilding.Id;

            //Check if valid if not return -1 
            if (DoesBuildingAlreadyExistNotForUser(ref db, @params.PrimaryAddress, @params.SecondaryAddress, @params.City, @params.Zip, @params.State, userId))
                return -1;

            //create new building then return new building id
            var building = new Building
                               {
                                   PrimaryAddress = @params.PrimaryAddress,
                                   SecondaryAddress = @params.SecondaryAddress,
                                   City = @params.City,
                                   Zip = @params.Zip,
                                   State = @params.State,
                                   Name = @params.Name,
                                   UserID = userId
                               };
            db.Building.InsertOnSubmit(building);
            db.SubmitChanges();
            return building.Id;
        }
        /// <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"));
        }
 partial void OnBuildingChanging(Building value);