using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LazyEating.Model;
using LazyEating.Repository;

namespace LazyEating.UI.Web
{
    public partial class Register1 : System.Web.UI.Page
    {
        UserRepository userRepository = new UserRepository();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["txtRealName"] != null)
            {
                OnRegister();
            }
        }

        private void OnRegister()
        {
            User user = new Model.User();
            user.RealName = Request.Form["txtRealName"].ToString();
            user.UserName = Request.Form["txtUserName"].ToString();
            user.Password = Request.Form["txtPassword"].ToString();
            user.Addess = Request.Form["txtAddress"].ToString();
            user.Phone = Request.Form["txtPhone"].ToString();

            try
            {
                userRepository.Add(user);
                Session["loginUserName"] = user.UserName;
                Message.Text = "注册成功！";
            }
            catch (Exception ex)
            {
                Message.Text = "注册失败！";
            }

        }
    }
}