shoppinaction.cs

来自「ibatis源码及帮助文档(IBatis源码+xsd+帮助)」· CS 代码 · 共 84 行

CS
84
字号

using System;
using System.Web;

using NPetshop.Domain.Shopping;
using NPetshop.Service;
using NPetshop.Presentation.Core;

namespace NPetshop.Presentation.UserActions
{
	/// <summary>
	/// Summary description for ShoppinAction.
	/// </summary>
	public class ShoppinAction : AbstractWebAction
	{
		private ShoppingCart _cart = null;
		private static readonly CatalogService _catalogService = CatalogService.GetInstance();

		public ShoppinAction(HttpContext context) : base(context) 
		{
			_cart = singleton.CurrentShoppingCart;
		}

		public static ShoppingCart CreateNewShoppingCart()
		{
			return new ShoppingCart();
		}

		public void AddItemToCart(string itemId)
		{
			if (_cart != null)
			{
				_cart.Add(_catalogService.GetItem(itemId));
				this.nextViewToDisplay = WebViews.CART;
			}
			else 
			{
				this.nextViewToDisplay = WebViews.SIGNIN;
			}
		}

		public void RemoveItemFromCart(string itemId)
		{
			if (_cart != null)
			{				
				_cart.RemoveLine(_catalogService.GetItem(itemId));
				this.nextViewToDisplay = WebViews.CART;
			}
			else 
			{
				this.nextViewToDisplay = WebViews.SIGNIN;
			}		
		}

		public void ShowShoppingCart()
		{
			if (_cart != null) 
			{
				this.nextViewToDisplay = WebViews.CART;
			}
			else 
			{
				this.nextViewToDisplay = WebViews.SIGNIN;
			}
		}

		public void UpdateQuantityByItemId(string itemId, int quantity)
		{
			ShoppingCartLine cartLine = _cart.FindLine(_catalogService.GetItem(itemId));
			cartLine.Quantity = quantity;
		}

		public void ProceedCheckout()
		{
			this.nextViewToDisplay = WebViews.CHECKOUT;
		}

		public void ContinueCheckout()
		{
			this.nextViewToDisplay = WebViews.PAYMENT;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?