accountaction.cs

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

CS
106
字号

using System;
using System.Web;

using NPetshop.Service;

using NPetshop.Domain.Accounts;
using NPetshop.Presentation.Core;
using NPetshop.Presentation.Exceptions;

namespace NPetshop.Presentation.UserActions
{
	/// <summary>
	/// Summary description for AccountAction.
	/// </summary>
	public class AccountAction : AbstractWebAction
	{
		private Account _account =null;

		private static readonly AccountService _accountService = AccountService.GetInstance();
		private static readonly CatalogService _catalogService = CatalogService.GetInstance();

		public AccountAction(HttpContext context) : base(context) 
		{
			_account = new Account();
		}

		private void CreateUserEnvironment()
		{
			singleton.CurrentUser = _account;
			singleton.CurrentShoppingCart = ShoppinAction.CreateNewShoppingCart();
			singleton.CurrentOrder = null;
			this.nextViewToDisplay = WebViews.STARTUP;
		}

		public Account Account
		{
			get
			{
				return _account;
			}
			set
			{
				_account = value;
			}
		}

		public void EditAccount()
		{
			if (singleton.CurrentUser != null) 
			{
				this.nextViewToDisplay = WebViews.EDIT_ACCOUNT;
			}
			else 
			{
				this.nextViewToDisplay = WebViews.REGISTER_USER;			
			}
		}

//		public void ExistingUserSignIn()
//		{
//			this.nextViewToDisplay = WebViews.EXISTING_USER_SIGNIN;
//		}

		public void SignIn()
		{
			this.nextViewToDisplay = WebViews.SIGNIN;
		}

		public void RegisterUser()
		{
			this.nextViewToDisplay = WebViews.REGISTER_USER;
		}

		public void SignOut()
		{
			this.singleton.CurrentUser = null;
			this.singleton.CurrentShoppingCart = null;
			this.nextViewToDisplay = WebViews.SIGNOUT;
		}

		public void TryToAuthenticate()
		{
			_account = _accountService.GetAccount(this.Account.Login, this.Account.Password);

			if (this.Account!=null)
			{
				//myList = catalogService.getProductListByCategory(account.getFavouriteCategoryId());
				CreateUserEnvironment();
			}
		}

		public void CreateNewAccount()
		{
			_accountService.InsertAccount(this.Account);
			CreateUserEnvironment();
		}

		public void UpdateAccount()
		{
			_accountService.UpdateAccount(this.Account);
			this.nextViewToDisplay = WebViews.STARTUP;
		}
	}
}

⌨️ 快捷键说明

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