// För att skapa en ny community
        protected void ButtonCreateComm_OnClick(object sender, EventArgs e)
        {
            bool isUniqueName = true;

            //Kontrollera att namnet inte redan finns
            foreach (communities commChecking in CommunityDB.GetAllCommunities())
            {
                if (commChecking.Name == TextBoxCommNameCreate.Text)
                {
                    isUniqueName = false;
                }
            };

            if (!isUniqueName)
            {
                LabelCreateComm.Text = "Community was not created. A community with the same name already exists. ";
                LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                return;
            }

                var comm = new communities
                {
                    Name = TextBoxCommNameCreate.Text,
                    LogoUrl = TextBoxCommLogoUrl.Text,
                    CreatedBy = HttpContext.Current.User.Identity.Name,
                    UpdatedBy = HttpContext.Current.User.Identity.Name
                };

                if (CommunityDB.AddCommunity(comm))
                {
                    webpages wp = new webpages
                    {
                        Title = TextBoxCommNameCreate.Text,
                        CommunityId = CommunityDB.GetCommunityByName(comm.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))
                        {
                            MultiViewCommDetails.ActiveViewIndex = 0;
                            MultiViewCommCreate.ActiveViewIndex = -1;
                            ShowCommunityDetails(CommunityDB.GetCommunityByName(comm.Name));
                        }
                        else
                        {
                            LabelCreateComm.Text = "Components could not be created. Please try again!";
                            LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                        }
                    }
                    else
                    {
                        LabelCreateComm.Text = "Webpage could not be created. Try again!";
                        LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                    }

                    //Välj admin för communityn som skapas
                    if (UserDB.GetUserByUsername(ddlAdminUser.SelectedValue) != null)
                    {
                        community_permissions cP = new community_permissions
                        {
                            users_Id = UserDB.GetUserByUsername(ddlAdminUser.SelectedValue).Id,
                            communities_Id = CommunityDB.GetCommunityByName(comm.Name).Id, //comm.Id
                            Role = "Administrators"
                        };
                        CommunityPermissionsDB.AddCommunityPermissions(cP);

                        if (!Roles.IsUserInRole(ddlAdminUser.SelectedValue, "Administrators"))
                        {
                            Roles.AddUserToRole(ddlAdminUser.SelectedValue, "Administrators");
                        }
                    }
                }
                else
                {
                    LabelCreateComm.Text = "Community could not be created. Try again!";
                    LabelCreateComm.Style.Add(HtmlTextWriterStyle.Color, "red");
                }

            PopulateCommunityDropDownList(DropDownListCommunity);
            ListBoxAsso.Items.Clear();
            LabelCommSave.Text = string.Empty; //Use string.Empty instead of "". ALWAYS.
        }
        // För att lägga till nya komponenter
        protected void AddControl_OnClick(object sender, EventArgs e)
        {
            lbWebPageUpdate.Text = string.Empty;

            components newComponent = new components();

            int oNo;
            newComponent.webpages_Id = int.Parse(hdnfWebpageId.Value);
            newComponent.OrderingNumber = int.TryParse(tbAddOrderingNumber.Text, out oNo) ? oNo : 1;
            newComponent.controls_Id = int.Parse(ddlAddComControls.SelectedValue);

            if (ComponentDB.AddComponent(newComponent))
            {
                LabelActionStatus.Text = "New component has successfully been added!";
                LabelActionStatus.ForeColor = Color.CornflowerBlue;
            }
            else
            {
                LabelActionStatus.Text = "Sorry! New component was not added.";
                LabelActionStatus.ForeColor = Color.Red;
            }
            ShowComponentsInWebPage();
        }
        // 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();
        }