示例#1
0
        /// <summary>
        /// Display the main user groups.
        /// </summary>
        /// <param name="UserForms">A form of user data passed up from the client.</param>
        /// <param name="UserGroup">The name of the current user group to display users for.</param>
        /// <returns>A view to show a list of users in the current user group.</returns>
        public ActionResult Index( FormCollection UserForms, string UserGroup )
        {
            CrashRepository Crashes = new CrashRepository();

            // Examine an incoming form for a new user group
            foreach( var FormInstance in UserForms )
            {
                string UserName = FormInstance.ToString();
                string NewUserGroup = UserForms[UserName];
                FRepository.Get( Crashes ).SetUserGroup( UserName, NewUserGroup );
            }

            UsersViewModel Model = new UsersViewModel();

            Model.UserGroup = UserGroup;
            Model.Users = FRepository.Get( Crashes ).GetUserNamesFromGroupName( UserGroup );
            Model.GroupCounts = FRepository.Get( Crashes ).GetCountsByGroup();

            return View( "Index", Model );
        }
        /// <summary>
        /// Create the html required to change the current user group to filter users by.
        /// </summary>
        /// <param name="Helper">The Url helper object.</param>
        /// <param name="UserGroup">The user group to generate a link for.</param>
        /// <param name="Model">The view model for the current page.</param>
        /// <returns>A string suitable for MVC to render.</returns>
        public static MvcHtmlString UserGroupLink( this UrlHelper Helper, string UserGroup, UsersViewModel Model )
        {
            StringBuilder Result = new StringBuilder();
            TagBuilder Tag = new TagBuilder( "a" );

            Tag.MergeAttribute( "href", "/Users/Index/" + UserGroup );
            Tag.InnerHtml = UserGroup;
            Result.AppendLine( Tag.ToString() );

            return MvcHtmlString.Create( Result.ToString() );
        }