/// <summary> /// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e) { InitPage("Post A Room", MainTabs.PostARoom); //If current user is null then only show image instead. if (CurrentUserUtilities.GetCuIdSafely() <= 0) { _pnlPostARoom.Visible = false; _pnlPostARoom.Enabled = false; _pnlCreateNoAccount.Visible = true; _pnlCreateNoAccount.Enabled = true; return; } if (Page.IsPostBack) { return; } if (_cbState.Items.Count > 0) { return; } //Load state information. _cbState.LoadXml(Utilities.GetXmlForPath(Utilities.StatePathWithNoneXml)); _cbState.FindItemByValue("NULL").Selected = true; _cbRoomType.Items.AddRange(RoomTypeUtilties.GetAll(true)); _cbBuilding.Items.AddRange(BuildingUtilities.GetByUserId(Cu.Id, true)); }
/// <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")); }
/// <summary> /// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e) { InitPage("Edit Room Details", MainTabs.MyAccount); if (Page.IsPostBack) { return; } RoomId = Utilities.GetQueryStringInt("RoomId"); if (RoomId <= 0) { RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/Default.aspx?message={0}&messageType={1}", "Invalid room", FeedbackType.Warning)); } var db = new UrbanDataContext(); var room = db.Manager.Room.GetByKey(RoomId); if (CurrentUserUtilities.GetCuIdSafely() <= 0 || room == null || room.UserID != Cu.Id) { RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/Default.aspx?message={0}&messageType={1}", "Invalid room", FeedbackType.Warning)); } _cbRoomType.Items.AddRange(RoomTypeUtilties.GetAll(false)); _cbBuilding.Items.AddRange(BuildingUtilities.GetByUserId(Cu.Id, false)); LoadPageFields(room); }
/// <summary> /// Handles the Click event of the _btnCreateRoom 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 _btnCreateRoom_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } var db = new UrbanDataContext(); //Verify All sections from user are valid var validationCheck = VerifyRequiredFieldsSelected(); switch (validationCheck) { case -1: { WriteFeedBackMaster(FeedbackType.Warning, "Please fill in required fields"); return; } case -2: { WriteFeedBackMaster(FeedbackType.Warning, "Building already exists with this address information"); return; } case -3: { WriteFeedBackMaster(FeedbackType.Warning, "Room already exists for this building and room number"); return; } case 1: { break; } } try { db.Connection.Open(); _transac = db.Connection.BeginTransaction(); db.Transaction = _transac; //Building Creation var buildingCreateParams = GetBuildingCreateParams(); var buidlingResult = BuildingUtilities.ProcessBuildingCreation(ref db, Cu.Id, buildingCreateParams); if (buidlingResult != -1) { //Room Creation var roomCreateParams = GetRoomCreateParams(); var roomResult = RoomUtilities.ProcessRoomCreation(ref db, buidlingResult, Cu.Id, AvailabilityList, roomCreateParams); if (roomResult == -1) { WriteFeedBackMaster(FeedbackType.Warning, "Room already exists with this number for this building please select another."); _transac.Rollback(); } else { //_transac.Rollback(); _transac.Commit(); //Move every temp image to full image foreach (var file in ImageList) { var filesTemp = Server.MapPath("~/FilesTemp"); var imageToCopy = Path.Combine(filesTemp, file.ImageUrl); var files = Server.MapPath("~/Files"); var imagePathToCopy = Path.Combine(files, file.ImageUrl); File.Copy(imageToCopy, imagePathToCopy); var f = new Files { Extension = file.Extension, FilesName = file.FileName, FileSubType = "Image", ServerFileName = file.ImageUrl }; db.Files.InsertOnSubmit(f); db.SubmitChanges(); var link = new RoomImageLink { ImageDescription = file.Description, Title = file.Title, RoomID = roomResult, FileID = f.Id }; db.RoomImageLink.InsertOnSubmit(link); db.SubmitChanges(); } RadAjaxManager.GetCurrent(Page).Redirect(String.Format("~/App/Pages/MyAccount.aspx?message={0}", ("Room " + _txtRoomNumber.Text + " created"))); } } else { WriteFeedBackMaster(FeedbackType.Warning, "This address information already eixsts for a different user. Please modify and resubmit"); _transac.Rollback(); } } catch (Exception) { if (_transac != null) { _transac.Rollback(); } throw; } finally { if (db.Connection.State == ConnectionState.Open) { db.Connection.Close(); } } }