public associations GetAssociationFromQueryStringAndSelectInDropDown() { var asso = new associations(); //Hämtar WebPageId från URL. var stId = Request.QueryString["Id"]; int id; //Om Id värdet som tas från URLn är i giltigt format hämtas WebPage objektet och visas på sidan. if (!string.IsNullOrWhiteSpace(stId) && int.TryParse(stId, out id)) { webpages webPage = WebPageDB.GetWebPageById(id); if (webPage != null) { if (webPage.AssociationId != null) { asso = AssociationDB.GetAssociationById(webPage.AssociationId.GetValueOrDefault()); if (asso != null) { DropDownListAsso.SelectedIndex = DropDownListAsso.Items.IndexOf( DropDownListAsso.Items.FindByValue( asso.Id.ToString())); } else { DropDownListAsso.SelectedIndex = DropDownListAsso.Items.IndexOf( DropDownListAsso.Items.FindByValue("")); } } } } return asso; }
private void FindSubAssociationsAndAddToParentNode(associations asso, TreeNode parentNode) { foreach ( var a in AssociationDB.GetAllSubAssociationsByParentAssociationId(asso.Id).OrderBy(a => a.Name).ToList() ) { TreeNode childAssociationNode = new TreeNode { Text = a.Name, Value = "A-" + a.Id, Expanded = false, NavigateUrl = "/SitePage?id=" + (WebPageDB.GetWebPageByAssociationId(a.Id) != null ? WebPageDB.GetWebPageByAssociationId(a.Id).Id.ToString() : "") + "&type=A", SelectAction = TreeNodeSelectAction.Select }; if (a.ParentAssociationId == null) { if (AssociationDB.GetAllCategoriesForAssociationByAssociation(a).Count == 0) { TreeNode uncategorized = new TreeNode() { Text = "Övrigt", Value = "Ovrigt-" + parentNode.Value, Expanded = false, SelectAction = TreeNodeSelectAction.Expand }; if (!associationTypesNodes.Exists( categoryNode => categoryNode.Value.Equals("Ovrigt-" + parentNode.Value))) { //parentNode.ChildNodes.Add(uncategorized); categoryNodesToAdd.Add(uncategorized, parentNode); associationTypesNodes.Add(uncategorized); } associationTypesNodes.Find(t => t.Value.Equals("Ovrigt-" + parentNode.Value)) .ChildNodes.Add(childAssociationNode); } else { string typeName = AssociationDB.GetAllCategoriesForAssociationByAssociation(a)[0].Name; TreeNode category = new TreeNode { Text = typeName, Value = typeName + "-" + parentNode.Value, Expanded = false, SelectAction = TreeNodeSelectAction.Expand }; if ( !associationTypesNodes.Exists( categoryNode => categoryNode.Value.Equals(typeName + "-" + parentNode.Value))) { //parentNode.ChildNodes.Add(category); categoryNodesToAdd.Add(category, parentNode); associationTypesNodes.Add(category); } associationTypesNodes.Find(t => t.Value.Equals(typeName + "-" + parentNode.Value)) .ChildNodes.Add(childAssociationNode); } } else { parentNode.ChildNodes.Add(childAssociationNode); } //För att hitta alla ChildAssociationNodes till den aktuella AssociationNoden. //Rekursiv anropning av metoden görs för att bygga upp hela "grenen". FindSubAssociationsAndAddToParentNode(a, childAssociationNode); } }
private void AddParentAssociationNodesToCommunityNode(associations parentAsso, TreeNode communityNode) { //Lägger till alla ParentAssociationNodes (ex. Vikingen IF/Föreningar). TreeNode parentAssociationNode = new TreeNode { Text = parentAsso.Name, Value = "A-" + parentAsso.Id, Expanded = false, NavigateUrl = "/SitePage?id=" + (WebPageDB.GetWebPageByAssociationId(parentAsso.Id) != null ? WebPageDB.GetWebPageByAssociationId(parentAsso.Id).Id.ToString() : "") + "&type=A", SelectAction = TreeNodeSelectAction.Select }; if (AssociationDB.GetAllCategoriesForAssociationByAssociation(parentAsso).Count == 0) { TreeNode uncategorized = new TreeNode() { Text = "Övrigt", Value = "Ovrigt-" + communityNode.Value, Expanded = false, SelectAction = TreeNodeSelectAction.Expand }; if (!associationTypesNodes.Exists( categoryNode => categoryNode.Value.Equals("Ovrigt-" + communityNode.Value))) { //parentNode.ChildNodes.Add(uncategorized); categoryNodesToAdd.Add(uncategorized, communityNode); associationTypesNodes.Add(uncategorized); } associationTypesNodes.Find(t => t.Value.Equals("Ovrigt-" + communityNode.Value)) .ChildNodes.Add(parentAssociationNode); } else { string typeName = AssociationDB.GetAllCategoriesForAssociationByAssociation(parentAsso)[0].Name; TreeNode category = new TreeNode() { Text = typeName, Value = typeName + "-" + communityNode.Value, Expanded = false, SelectAction = TreeNodeSelectAction.Expand }; if ( !associationTypesNodes.Exists( categoryNode => categoryNode.Value.Equals(typeName + "-" + communityNode.Value))) { //parentNode.ChildNodes.Add(category); categoryNodesToAdd.Add(category, communityNode); associationTypesNodes.Add(category); } associationTypesNodes.Find(t => t.Value.Equals(typeName + "-" + communityNode.Value)) .ChildNodes.Add(parentAssociationNode); } FindSubAssociationsAndAddToParentNode(parentAsso, parentAssociationNode); }
private List<categories> FilterDropDownCatItems(associations a) { PopulateDropDownCat(a.categories.ToList()); return a.categories.ToList(); }
public List<events> RenderEventList(associations asso) { List<events> eventList = new List<events>(); if (asso != null) { eventList = EventDB.GetEventsByAssociation(asso).Where(e => !e.IsDeleted).ToList(); GridViewEventList.DataSource = eventList.OrderBy(e => e.StartDate); GridViewEventList.DataBind(); return eventList; } return RenderEventList(); }
// Still in use ^^^ public List<events> RenderEventList(associations asso, string searchStr) { List<events> eventList = new List<events>(); if (asso != null) { foreach (events e in EventDB.GetEventsBySearchWord(searchStr)) { foreach (associations a in e.associations) { if (a.Id == asso.Id) { eventList.Add(e); break; } } } GridViewEventList.DataSource = eventList.OrderBy(e => e.StartDate); GridViewEventList.DataBind(); return eventList; } else { return RenderEventList(); } }
public List<events> RenderEventList(DateTime sDate, DateTime eDate, associations asso) { List<events> eventList = new List<events>(); if (asso != null) { foreach (events e in EventDB.GetEventsByRangeDate(sDate, eDate)) { foreach (associations a in e.associations) { if (a.Id == asso.Id) { eventList.Add(e); break; } } } GridViewEventList.DataSource = eventList.OrderBy(e => e.StartDate); GridViewEventList.DataBind(); return eventList; } else { return RenderEventList(); } }
// För att SKAPA en ny förening protected void ButtonCreateAsso_OnClick(object sender, EventArgs e) { bool isUniqueName = true; //Kontrollera att förening inte redan finns foreach (associations assoChecking in AssociationDB.GetAllAssociations()) { if (assoChecking.Name == TextBoxCreateAssoName.Text) { isUniqueName = false; } } if (!isUniqueName) { LabelErrorMessage.Text = "Association was not created. Name already exists. "; LabelErrorMessage.Style.Add(HtmlTextWriterStyle.Color, "red"); return; } associations asso = new associations { Name = TextBoxCreateAssoName.Text, ParentAssociationId = string.IsNullOrWhiteSpace(DropDownListCreateParAsso.SelectedValue) ? (int?) null : int.Parse(DropDownListCreateParAsso.SelectedItem.Value), LogoUrl = TextBoxAssoImgUrl.Text, CreatedBy = HttpContext.Current.User.Identity.Name, UpdatedBy = HttpContext.Current.User.Identity.Name, Communities_Id = int.Parse(DropDownListCommunity.SelectedItem.Value) }; if (AssociationDB.AddAssociation(asso)) { webpages wp = new webpages { Title = TextBoxCreateAssoName.Text, AssociationId = AssociationDB.GetAssociationByName(asso.Name).Id, //Layout och style - fixa dropdownlistor senare! CreatedBy = HttpContext.Current.User.Identity.Name, UpdatedBy = HttpContext.Current.User.Identity.Name }; if (WebPageDB.AddWebPage(wp)) { components compCal = new components { webpages_Id = wp.Id, OrderingNumber = 1, controls_Id = 3 //Calendar }; components compAbout = new components { webpages_Id = wp.Id, OrderingNumber = 2, controls_Id = 1 //About }; if (ComponentDB.AddComponent(compCal) && ComponentDB.AddComponent(compAbout)) { MultiViewAssoCreate.ActiveViewIndex = -1; PopulateAssociationListBox(); LabelErrorMessage.Text = asso.Name + " has been successfully created! (^o^)/"; LabelErrorMessage.Style.Add(HtmlTextWriterStyle.Color, "#217ebb"); } else { LabelCreateComm.Text = "Components could not be created. Please try again!"; } } else { LabelErrorMessage.Text = "Webpage could not be created. Try again!"; LabelErrorMessage.Style.Add(HtmlTextWriterStyle.Color, "red"); } //Välj admin för association som skapas if (UserDB.GetUserByUsername(ddlAdminUserAsso.SelectedValue) != null) { association_permissions aP = new association_permissions { users_Id = UserDB.GetUserByUsername(ddlAdminUserAsso.SelectedValue).Id, associations_Id = AssociationDB.GetAssociationByName(asso.Name).Id, Role = "Administrators" }; AssociationPermissionsDB.AddAssociationPermissions(aP); if (!Roles.IsUserInRole(ddlAdminUserAsso.SelectedValue, "Administrators")) { Roles.AddUserToRole(ddlAdminUserAsso.SelectedValue, "Administrators"); } LabelErrorMessage.Text += "User was successfully added as administrator in Association"; } else { LabelErrorMessage.Text += "No user was added as administrator."; LabelErrorMessage.Style.Add(HtmlTextWriterStyle.Color, "red"); } } else { LabelErrorMessage.Text = "Association could not be created. Try again!"; LabelErrorMessage.Style.Add(HtmlTextWriterStyle.Color, "red"); } PopulateAssociationListBox(); }
public void ShowAssociationDetails(associations a) { associations asso = a; //Visa Association Name i textboxen TextBoxAssoName.Text = a.Name; //Visa Description i multitextbox TextBoxAssoDescript.Text = a.Description ?? ""; //Visa Association logga plus web page link ImageLogoAssociation.ImageUrl = a.LogoUrl ?? "~/Images/Association.jpg"; HyperLinkLogoAssociation.NavigateUrl = "/SitePage.aspx?id=" + (WebPageDB.GetWebPageByAssociationId(a.Id) != null ? WebPageDB.GetWebPageByAssociationId(a.Id).Id.ToString() : "") + "&type=A"; HyperLinkLogoAssociation.Target = "_blank"; HyperLinkLogoAssociation.ToolTip = "This link goes to the web page of " + a.Name + "! o(^O^)o "; // Visa Community-dropdownlista PopulateCommunityDropDownList(DropDownListCommunityInAsso); DropDownListCommunityInAsso.SelectedIndex = DropDownListCommunityInAsso.Items.IndexOf( DropDownListCommunityInAsso.Items.FindByValue(asso.Communities_Id.ToString())); // Visa ParentAssociation-dropdownlista PopulateAssociationInCommunityDropDownList(asso.Id, DropDownListParentAsso); ////Om community stämmer överens ska PA inte visa AssoId och subAssos //if((int.Parse(DropDownListCommunityInAsso.SelectedItem.Value) == asso.Communities_Id)) //{ // PopulateAssociationInCommunityDropDownList(asso.Id, DropDownListParentAsso); //} //else //{ // PopulateAssociationInCommunityDropDownList(DropDownListParentAsso, DropDownListCommunityInAsso); //} if (asso.ParentAssociationId == null) { //Om föreningen inte har en förälder ska dropdownlistan visa blankt DropDownListParentAsso.SelectedIndex = 0; } else { DropDownListParentAsso.SelectedIndex = DropDownListParentAsso.Items.IndexOf( DropDownListParentAsso.Items.FindByValue(asso.ParentAssociationId.ToString())); } // Visa alla kategorier i dropdownlista PopulateAllAssociationCategoriesDropDownList(); PopulateCategoriesInAssoListBox(); DropDownListCategories.SelectedIndex = 0; //Visa Logo Url i textbox TextBoxAssoLogoImgUrl.Text = a.LogoUrl ?? "~/Images/Association.jpg"; // Visa Created, Created By och Publishing TermSet LabelCreatedAsso.Text = "<b>Created: </b>" + AssociationDB.GetAssociationById(int.Parse(ListBoxAsso.SelectedValue)) .Created.ToShortDateString(); LabelCreatedByAsso.Text = "<b>Created by: </b>" + AssociationDB.GetAssociationById(int.Parse(ListBoxAsso.SelectedValue)).CreatedBy; // Visa underföreningar för en förening i en lista if (AssociationDB.GetAllSubAssociationsByParentAssociationId(asso.Id).Count != 0) { PopulateSubAssociationsBulletedList(); } else { BulletedListSubAssociations.Items.Clear(); ListItem emptyItem = new ListItem(" --- ", " "); BulletedListSubAssociations.Items.Add(emptyItem); //index 0 } bullListMemberList.Items.Clear(); lnkbtnMembers.Text = "Show members"; }
// Metod för att hitta alla under- och underföreningar protected void FindSubAssociationsAndAddtoDeleteList(associations asso) { List<ListItem> subAssoDeleteList = new List<ListItem>(); //Lägg in alla underföreningar som ska tas bort i en itemlista foreach (var subasso in AssociationDB.GetAllSubAssociationsByParentAssociationId(asso.Id)) { subAssoDeleteList.Add(new ListItem { Text = subasso.Name, Value = subasso.Id.ToString() }); } //Lägg underföreningarna i ordning i punktlistan foreach (ListItem item in subAssoDeleteList.OrderBy(item => item.Text)) { BulletedListSubAssoToDelete.Items.Add((item)); //Hitta alla underföreningar och lägg till i listan - rekursiv FindSubAssociationsAndAddtoDeleteList(AssociationDB.GetAssociationById(int.Parse(item.Value))); } }
// För att spara ändringar i Association details - UPDATE-knappen protected void ButtonUpdateAsso_OnClick(object sender, EventArgs e) { bool isUniqueName = true; if (string.IsNullOrWhiteSpace(ListBoxAsso.SelectedValue)) { LabelUpdateAsso.Text = "Select an association in the listbox before trying to save changes again."; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "red"); LabelAssoInComm.Text = "Select An Association in this Listbox"; LabelAssoInComm.Style.Add(HtmlTextWriterStyle.Color, "red"); return; } //Hitta Association-Id i listboxen - value int assoId; if (!int.TryParse(ListBoxAsso.SelectedValue, out assoId)) { LabelUpdateAsso.Text = "Selected value could not be parsed. "; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "red"); return; } if (AssociationDB.GetAssociationById(assoId) == null) { LabelUpdateAsso.Text = "Select an association in the listbox before trying to save changes again."; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "red"); return; } // UPPDATERA det nya namnet från textboxen associations assoToUpdate = AssociationDB.GetAssociationById(assoId); //Kontrollera så att det inte blir namnduplikationer foreach (associations assoChecking in AssociationDB.GetAllAssociations()) { if (TextBoxAssoName.Text == assoChecking.Name) { isUniqueName = false; } } if (isUniqueName) { assoToUpdate.Name = TextBoxAssoName.Text; } else { LabelUpdateAsso.Text = "Association name was not updated, specified name already exists. "; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "red"); } PopulateAssociationListBox(assoId); //UPPDATERA Description från textboxen assoToUpdate.Description = TextBoxAssoDescript.Text; // UPPDATERA community i vilken föreningen finns assoToUpdate.Communities_Id = int.Parse(DropDownListCommunityInAsso.SelectedItem.Value); // UPPDATERA ParentAssociation - omflyttningar i strukturen associations newParentAsso = new associations(); if (assoToUpdate.ParentAssociationId == null) //assoToUpdate är en parentAsso, flyttar neråt eller under en annan asso { if (!string.IsNullOrWhiteSpace(DropDownListParentAsso.SelectedItem.Value)) { //Den nya ParentAsso blir den valda i ddl-listan newParentAsso.Id = int.Parse(DropDownListParentAsso.SelectedItem.Value); if (assoToUpdate.Id != newParentAsso.Id) //Får inte välja sig själv { //Om assoToUpdate flyttar till en annan ParentAsso behåller den sina barn if (newParentAsso.ParentAssociationId == null) { //Får ny PAId assoToUpdate.ParentAssociationId = newParentAsso.Id; } else //om den flyttar under sig själv eller till en childAsso { //Hitta alla barnen för att släppa dem. De blir alla parentAssos och får PA = null foreach ( var subAsso in AssociationDB.GetAllSubAssociationsByParentAssociationId(assoToUpdate.Id)) { subAsso.ParentAssociationId = null; affectedRows += AssociationDB.UpdateAssociation(subAsso); } } } else { LabelUpdateAsso.Text = TextBoxAssoName.Text + " cannot be Parent Association to itself. Please try again. \n"; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "red"); } } else { //Om man väljer blankt i ddl blir ParentAssociation null assoToUpdate.ParentAssociationId = null; } } else //assoToUpdate är en childAsso { int? oldPAId = assoToUpdate.ParentAssociationId; if (!string.IsNullOrWhiteSpace(DropDownListParentAsso.SelectedItem.Value)) { //assoToUpdate får ny PAId, får inte välja sig själv if (assoToUpdate.Id != int.Parse(DropDownListParentAsso.SelectedItem.Value)) { assoToUpdate.ParentAssociationId = int.Parse(DropDownListParentAsso.SelectedItem.Value); } else { LabelUpdateAsso.Text = TextBoxAssoName.Text + " cannot be Parent Association to itself. Please try again. \r\n"; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "red"); } } else { //Om man väljer blankt i ddl blir ParentAssociation null assoToUpdate.ParentAssociationId = null; } if (assoToUpdate.ParentAssociationId > oldPAId) //assoToUpdate flyttar neråt { //Hitta barnen och ge dem assoToUpdates gamla PAId foreach ( var subAsso in AssociationDB.GetAllSubAssociationsByParentAssociationId(assoToUpdate.Id)) { subAsso.ParentAssociationId = oldPAId; affectedRows += AssociationDB.UpdateAssociation(subAsso); } } } // UPPDATERA föreningskategori, lägg till de valda kategorierna från listboxen List<categories> catToAddList = new List<categories>(); List<categories> catToRemoveList = new List<categories>(); foreach (ListItem addedCategory in ListBoxCatInAsso.Items) { categories category = CategoryDB.GetCategoryById(int.Parse(addedCategory.Value)); if (assoToUpdate.categories.Count != 0) { catToAddList.AddRange(from item in assoToUpdate.categories where item.Id != category.Id select category); } else { catToAddList.Add(category); } } foreach (categories addItem in catToAddList) { assoToUpdate.categories.Add(addItem); } // Föreningskategori - REMOVE foreach (var removedItem in assoToUpdate.categories) { bool exist = false; foreach (ListItem item in ListBoxCatInAsso.Items) { if (item.Value == removedItem.Id.ToString()) { exist = true; break; } exist = false; } if (!exist) { catToRemoveList.Add(removedItem); } } foreach (categories removeItem in catToRemoveList) { assoToUpdate.categories.Remove(removeItem); } //UPPDATERA Logo Url assoToUpdate.LogoUrl = TextBoxAssoLogoImgUrl.Text; //Anropa Update-metoden affectedRows = AssociationDB.UpdateAssociation(assoToUpdate); //affectedRows += WebPageDB.UpdateWebPage(wpToUpdate); PopulateAssociationListBox(); if (affectedRows != 0) { LabelUpdateAsso.Text = assoToUpdate.Name + " has been updated!"; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "#217ebb"); MultiViewManageMembers.ActiveViewIndex = -1; } else { LabelUpdateAsso.Text += "Error: Changes might not have been made in " + assoToUpdate.Name + "... Make sure to set the update information."; LabelUpdateAsso.Style.Add(HtmlTextWriterStyle.Color, "red"); } }