/// <summary>
    /// Post's grid view data binding.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvPosts_DataBinding(object sender, EventArgs e)
    {
        int iUserID = 0;

        int.TryParse(Request["UserID"], out iUserID);

        int iState = -1;

        if (!String.IsNullOrEmpty(Request["state"]))
        {
            int.TryParse(Request["state"], out iState);
        }

        PostStates postState;

        switch (iState)
        {
        case 1: postState = PostStates.Published;
            break;

        case 0: postState = PostStates.Draft;
            break;

        case 2: postState = PostStates.Removed;
            break;

        default: postState = PostStates.All;
            break;
        }


        string searchText = Request["Search"];

        List <BSPost> posts;

        GridView gv = (GridView)sender;

        if (!String.IsNullOrEmpty(searchText))
        {
            posts = User.IsInRole("editor") ? BSPost.GetPostsByTitle(searchText, Blogsa.ActiveUser.UserID) : BSPost.GetPostsByTitle(searchText, 0);
        }
        else if (User.IsInRole("editor"))
        {
            posts = BSPost.GetPostsByColumnValue("UserID", Blogsa.ActiveUser.UserID, 0, String.Empty, PostTypes.Article, postState);
        }
        else if (Request["UserID"] != null && iUserID != 0)
        {
            posts = BSPost.GetPostsByColumnValue("UserID", Blogsa.ActiveUser.UserID, 0, String.Empty, PostTypes.Article, postState);
        }
        else
        {
            posts = BSPost.GetPosts(PostTypes.Article, postState, 0);
        }

        gv.DataSource = posts;
        gv.Attributes.Add("totalItemCount", posts.Count.ToString(CultureInfo.InvariantCulture));
    }
예제 #2
0
 public List <BSPost> GetPosts(PostTypes postType)
 {
     return(BSPost.GetPostsByColumnValue("UserID", UserID, 0, "ORDER By CreateDate DESC", postType, PostStates.All));
 }