protected void btnCreateGroup_Click(object sender, EventArgs e) { #region Check groups per member limit int memberOf = GroupMember.Fetch(CurrentUserSession.Username).Length; int maxGroupsPermitted = 0;// Config.Groups.MaxGroupsPerMember; if (CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value > maxGroupsPermitted) maxGroupsPermitted = CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value; if (CurrentUserSession.Level != null && CurrentUserSession.Level.Restrictions.MaxGroupsPerMember > maxGroupsPermitted) maxGroupsPermitted = CurrentUserSession.Level.Restrictions.MaxGroupsPerMember; if (memberOf >= maxGroupsPermitted && !CurrentUserSession.IsAdmin()) { lblError.Text = String.Format(Lang.Trans("You are already a member of {0} groups. Please leave one of them first."), maxGroupsPermitted); return; } #endregion #region Set fields string terms = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtTerms.Text.Trim()) : txtTerms.Text.Trim(); string name = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtName.Text.Trim()) : txtName.Text.Trim(); string description = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtDescription.Text.Trim()) : txtDescription.Text.Trim(); string question = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtQuestion.Text.Trim()) : txtQuestion.Text.Trim(); Group.eAccessLevel accessLevel = (Group.eAccessLevel) Convert.ToInt32(ddAccessLevel.SelectedValue); string owner = CurrentUserSession.Username; #endregion #region Validate fields #region Validate Group name if (name.Length == 0) { lblError.Text = Lang.Trans("Please enter group name."); return; } if (Group.IsNameUsed(name)) { lblError.Text = Lang.Trans("Group name already exists."); return; } #endregion #region Validate Categories List<int> lCategoriesIDs = new List<int>(); foreach (ListItem item in lbCategories.Items) { if (item.Selected) { lCategoriesIDs.Add(Convert.ToInt32(item.Value)); } } if (lCategoriesIDs.Count == 0) { lblError.Text = Lang.Trans("Please select category."); return; } #endregion #region Validate Description if (description.Length == 0) { lblError.Text = Lang.Trans("Please enter group description."); return; } #endregion #region Validate Group Icon Image image = null; if (fuGroupImage.PostedFile.FileName.Length == 0) { image = Image.FromFile(Server.MapPath("~/Images") + "/defaultgroupicon.jpg"); } else { try { image = Image.FromStream (fuGroupImage.PostedFile.InputStream); } catch { lblError.Text = Lang.Trans("Invalid image!"); return; } } #endregion #endregion if (Group.IsNameUsed(name)) { StatusPageMessage = Lang.Trans("Group with such name already exists!"); Response.Redirect("~/ShowStatus.aspx"); } Group group = new Group(); group.JoinTerms = terms; group.Name = name; group.Description = description; if (ddAgeRestriction.SelectedValue != "-1") group.MinAge = Convert.ToInt32(ddAgeRestriction.SelectedValue); if (CurrentUserSession != null && CurrentUserSession.IsAdmin() || Config.Groups.AutoApproveGroups) { group.Approved = true; } if (cbAutomaticallyJoin.Checked) { group.Autojoin = true; group.AutojoinCountry = dropCountry.SelectedValue.Trim() != String.Empty ? dropCountry.SelectedValue.Trim() : null; group.AutojoinRegion = dropRegion.SelectedValue.Trim() != String.Empty ? dropRegion.SelectedValue.Trim() : null; group.AutojoinCity = dropCity.SelectedValue.Trim() != String.Empty ? dropCity.SelectedValue.Trim() : null; } group.AccessLevel = accessLevel; group.Owner = owner; if (accessLevel == Group.eAccessLevel.Moderated) group.JoinQuestion = question; group.ActiveMembers++; group.Save(); group.SetCategories(lCategoriesIDs.ToArray()); Group.SaveIcon(group.ID, image); GroupMember groupMember = new GroupMember(group.ID, CurrentUserSession.Username); groupMember.Active = true; groupMember.Type = GroupMember.eType.Admin; groupMember.Save(); StatusPageMessage = Lang.Trans("Your group has been created successfully!"); Response.Redirect("~/ShowStatus.aspx"); }