Esempio n. 1
0
    /// <summary>
    /// Event handler for the gvPost_RowCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void gvPost_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "removeFavorite")
        {
            // Retrieve index of row generating event
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the id of the object bound to row
            int id = Convert.ToInt32(gvPost.DataKeys[index].Values["Id"].ToString());

            // Create a temp post with same id
            TravelPost post = new TravelPost();
            post.Id = id;

            // Remove from session
            FavoritesSessionFacade.Remove(post);

            // Display message
            if (FavoritesSessionFacade.PostCount() > 0)
            {
                lbPostErrorMessage.Text = "";
            }
            else
            {
                lbPostErrorMessage.Text = "No favorited posts.";
            }

            // Rebind
            gvPost.DataSource = FavoritesSessionFacade.PostCollection;
            gvPost.DataBind();
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Event handler for the gvImage_RowCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void gvImage_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "removeFavorite")
        {
            // Retrieve the row index
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the id of the object bound to row
            int id = Convert.ToInt32(gvImage.DataKeys[index].Values["Id"].ToString());

            // Create a temp image with same id
            TravelImage image = new TravelImage();
            image.Id = id;

            // Remove from session
            FavoritesSessionFacade.Remove(image);

            // Display message
            if (FavoritesSessionFacade.ImageCount() > 0)
            {
                lbImageErrorMessage.Text = "";
            }
            else
            {
                lbImageErrorMessage.Text = "No favorited images.";
            }

            // Rebind
            gvImage.DataSource = FavoritesSessionFacade.ImageCollection;
            gvImage.DataBind();
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Helper adds image to favorites
    /// </summary>
    /// <param name="item"></param>
    private void AddImageToFavorites(ListViewItem item)
    {
        // Retrieve item index
        int index = Convert.ToInt32(item.DisplayIndex);

        // Initialize object
        TravelImage image = new TravelImage();

        image.Id    = Convert.ToInt32(lvImageData.DataKeys[index].Values["Id"]);;
        image.Title = lvImageData.DataKeys[index].Values["Title"].ToString();
        image.Path  = lvImageData.DataKeys[index].Values["Path"].ToString();

        // Save to session (favorites)
        FavoritesSessionFacade.Add(image);
    }
Esempio n. 4
0
    /// <summary>
    /// Event handler for the lvPostData_ItemCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void lvPostData_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        // Retrieve item which raised item command event
        ListViewItem item = (ListViewItem)e.Item;

        // Retrieve item index
        int index = Convert.ToInt32(item.DisplayIndex);

        // Initialize object
        TravelPost post = new TravelPost();

        post.Id    = Convert.ToInt32(lvPostData.DataKeys[index].Values["Id"]);;
        post.Title = lvPostData.DataKeys[index].Values["Title"].ToString();;

        // Save to session (favorites)
        FavoritesSessionFacade.Add(post);

        // Redirect to favorites page upon redirect
        Response.Redirect("./Favorites.aspx");
    }
Esempio n. 5
0
    /// <summary>
    /// Event handler for rptImageBox_ItemCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void rptImageBox_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        // Retrieve item which raised item command event
        ListViewItem item = (ListViewItem)e.Item;

        // Retrieve item index
        int index = Convert.ToInt32(item.DisplayIndex);

        // Initialize object
        TravelImage image = new TravelImage();

        image.Id    = Convert.ToInt32(lvImageBox.DataKeys[index].Values["Id"]);;
        image.Title = lvImageBox.DataKeys[index].Values["Title"].ToString();;
        image.Path  = lvImageBox.DataKeys[index].Values["Path"].ToString();;

        // Save to session
        FavoritesSessionFacade.Add(image);

        // Redirect to favorites page upon adding
        Response.Redirect("./Favorites.aspx");
    }
Esempio n. 6
0
    /// <summary>
    /// Event handler for the gvPost_RowCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void gvPost_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "addFavorite")
        {
            // Retrieve index of row generating event
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the id of the object bound to row
            int id = Convert.ToInt32(gvPost.DataKeys[index].Values["Id"].ToString());

            // Initialize object
            TravelPost post = new TravelPost();
            post.Id    = id;
            post.Title = gvPost.DataKeys[index].Values["Title"].ToString();

            // Add to session
            FavoritesSessionFacade.Add(post);

            // Redirect to favorites page
            Response.Redirect("./Favorites.aspx");
        }
    }