using System;
using System.Collections.Generic;
using System.Text;
using Model;
using ImpDDal;
using IDDal;
/*********关于用户操作的业务逻辑层************************
 * 这里有关于用户的增加,删除,修改信息,设定认证,废除认证
 * 检测用户名是否存在,登陆等一些操作
 * 设计者:魏莹
 * 设计时间:5月30日
 * 修改者:王枢昊
 * 修改时间:6月2日
 * ******************************************************/
namespace Business
{
    /// <summary>
    /// 用户操作的类
    /// </summary>
    public class BUser
    {
        UserDal<User> userop = new ImpUserDal();
        /// <summary>
        /// 登陆方法
        /// </summary>
        /// <param name="account">用户登录名</param>
        /// <param name="pwd">登录密码</param>
        /// <returns>返回一个用户对象</returns>
        public User Login(string account, string pwd)
        {
           
            try
            {
                return userop.Login(account, pwd);
            }
            catch (Exception ex)
            {
                throw new Exception("登陆失败"+ex.Message);
            }
        }

        /// <summary>
        /// 创建一个新用户
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <returns>1表示成功创建,0表示创建失败</returns>
        public int CreateUser(User user)
        {
            try
            {
                return userop.CreateNewUser(user);
            }
            catch (Exception ex)
            {
                throw new Exception("创建用户失败" + ex.Message);
            }
        }

        /// <summary>
        /// 删除一个用户
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <returns>1表示删除成功,0表示删除失败</returns>
        public int DeleteUser(User user)
        {
            try
            {
                return userop.DeleteUser(user);
            }
            catch (Exception ex)
            {
                throw new Exception("删除用户失败" + ex.Message);
            }
        }

        /// <summary>
        /// 编辑用户信息
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <returns>1表示编辑成功,0表示编辑失败</returns>
        public int ModifyUser(User user)
        {
            try
            {
                return userop.ModifyUser(user);
            }
            catch (Exception ex)
            {
                throw new Exception("修改用户失败" + ex.Message);
            }
        }
        /// <summary>
        /// 编辑用户信息(顾客用)
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <returns>1表示编辑成功,0表示编辑失败</returns>
        public int ModifyUserInfo(User user)
        {
            try
            {
                return userop.ModifyUserInfo(user);
            }
            catch (Exception ex)
            {
                throw new Exception("修改用户失败" + ex.Message);
            }
        }
        /// <summary>
        /// 判断是否已经存在这个用户名
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <returns>1表示存在,0表示不存在</returns>
        public int ExsitUser(User user)
        {
            try
            {
                return userop.ExsitUser(user);
            }
            catch (Exception ex)
            {
                throw new Exception("检索用户失败" + ex.Message);
            }
        }

        /// <summary>
        /// 返回未通过认证的用户
        /// </summary>
        /// <returns>用户列表</returns>
        public IList<User> UserNoVerifyFilter()
        {
            try
            {
                return userop.SelectNoVerify();
            }
            catch (Exception ex)
            {
                throw new Exception("检索用户失败" + ex.Message);
            }
        }
        /// <summary>
        /// 返回已通过认证的用户
        /// </summary>
        /// <returns>用户列表</returns>
        public IList<User> UserVerifiedFilter()
        {
            try
            {
                return userop.SelectVerified();
            }
            catch (Exception ex)
            {
                throw new Exception("检索用户失败" + ex.Message);
            }
        }
        /// <summary>
        /// 返回所有用户
        /// </summary>
        /// <returns>用户列表</returns>
        public IList<User> UserList()
        {
            try
            {
                return userop.UserList();
            }
            catch (Exception ex)
            {
                throw new Exception("检索用户失败" + ex.Message);
            }
        }

        /// <summary>
        /// 设定用户为认证用户
        /// </summary>
        /// <param name="userName">需要认证的用户名</param>
        /// <returns>1认证成功,0认证失败</returns>
        public int SetVerify(string userName)
        {
            try
            {
                return userop.SetVerify(userName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 设定用户为非认证用户
        /// </summary>
        /// <param name="userName">需要废除认证的用户名</param>
        /// <returns>1废除认证成功,0废除认证失败</returns>
        public int SetNoVerify(string userName)
        {
            try
            {
                return userop.SetNoVerify(userName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 根据用户名获取该用户对象
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <returns>用户对象</returns>
        public User GetUserInfo(string UserName)
        {
            try
            {
                return userop.GetUserInfo(UserName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 选出活跃用户
        /// </summary>
        /// <returns></returns>
        public IList<User> GetActiveUser()
        {
            try
            {
                return userop.SelectActiveUser();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

    }
}
