view Demo/Asp.Net/Web/Controls/WishListControl.ascx.cs @ 3:1ef98bd70424

!bug 100 +3h Исправление проблемы BLToolkit + mono 3.4
author cin
date Fri, 22 Aug 2014 17:34:46 +0400
parents f990fcb411a9
children
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;

using PetShop.ObjectModel;

namespace PetShop.Web
{
	public partial class WishListControl : System.Web.UI.UserControl
	{
		/// <summary>
		/// Handle Page load event
		/// </summary>
		protected void Page_PreRender(object sender, EventArgs e)
		{
			if (!IsPostBack)
				BindCart();
		}

		/// <summary>
		/// Bind repeater to Cart object in Profile
		/// </summary>
		private void BindCart()
		{
			ICollection<CartItem> wishList = Profile.WishList.Items;

			if (wishList.Count > 0)
			{
				repWishList.DataSource = wishList;
				repWishList.DataBind();
			}
			else
			{
				repWishList.Visible = false;
				lblMsg.Text = "Your wish list is empty.";
			}
		}

		/// <summary>
		/// Handler for Delete/Move buttons
		/// </summary>
		protected void CartItem_Command(object sender, CommandEventArgs e)
		{
			switch (e.CommandName.ToString())
			{
				case "Del":
					Profile.WishList.Remove(e.CommandArgument.ToString());
					break;

				case "Move":
					Profile.WishList.Remove(e.CommandArgument.ToString());
					Profile.ShoppingCart.Add(e.CommandArgument.ToString());
					break;
			}

			Profile.Save();
			BindCart();
		}
	}
}