当前位置: 首页>>代码示例>>C#>>正文


C# Group.SetCategories方法代码示例

本文整理汇总了C#中Group.SetCategories方法的典型用法代码示例。如果您正苦于以下问题:C# Group.SetCategories方法的具体用法?C# Group.SetCategories怎么用?C# Group.SetCategories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Group的用法示例。


在下文中一共展示了Group.SetCategories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnCreateGroup_Click


//.........这里部分代码省略.........

            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");
        }
开发者ID:haimon74,项目名称:Easy-Fixup,代码行数:101,代码来源:CreateGroup.aspx.cs


注:本文中的Group.SetCategories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。