Ejemplo n.º 1
0
        /// <summary>
        /// 添加后台管理员
        /// </summary>
        /// <param name="model">AccountAdd</param>
        /// <returns></returns>
        public ResponsResult AddAccount(BackstageUserAdd model)
        {
            ResponsResult result  = new ResponsResult();
            BackstageUser account = this.First <BackstageUser>(t => t.LoginName == model.LoginName);

            if (account != null)
            {
                return(result.SetStatus(ErrorCode.NotFound, "登录名称已经存在!"));
            }
            else
            {
                account = new BackstageUser();
            }
            if (!MethordExtensions.IsIDCard(model.IdCard))
            {
                return(result.SetStatus(ErrorCode.InvalidData, "身份证非法!"));
            }
            model.Password = model.Password == "" ? "123456" : model.Password;
            string pwd = Security.MD5(model.Password);

            account.Id            = Guid.NewGuid().ToString("N");
            account.LoginName     = model.LoginName;
            account.FullName      = model.FullName;
            account.CreateTime    = DateTime.Now;
            account.AccountType   = (int)model.AccountType;
            account.RoleId        = (int)model.AccountType;
            account.Password      = pwd;
            account.Mobile        = model.Mobile;
            account.AccountStatus = (int)AccountStatus.Normal;
            account.SourceType    = (int)SourceType.Web;
            account.Gender        = model.Gender;
            account.IdCard        = model.IdCard;
            this.Add(account, true);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 后台管理员修改
        /// </summary>
        /// <param name="model">BackstageUserAdd</param>
        /// <returns></returns>
        public ResponsResult UpdateAccount(BackstageUserAdd model)
        {
            ResponsResult result  = new ResponsResult();
            BackstageUser account = base.First <BackstageUser>(t => string.IsNullOrEmpty(model.Id) && t.LoginName.Equals(model.LoginName));

            if (account != null)
            {
                return(result.SetStatus(ErrorCode.NotFound, "登录名称已经存在!"));
            }
            else
            {
                account = this.First <BackstageUser>(t => t.Id.Equals(model.Id));
                if (account == null)
                {
                    return(result.SetStatus(ErrorCode.NotFound, "用户异常操作失败!"));
                }
            }
            if (!string.IsNullOrEmpty(model.Password))
            {
                string pwd = Security.MD5(model.Password);
                account.Password = pwd;
            }
            if (!MethordExtensions.IsIDCard(model.IdCard))
            {
                return(result.SetStatus(ErrorCode.InvalidData, "身份证非法!"));
            }
            account.LoginName     = model.LoginName;
            account.AccountStatus = (int)model.AccountStatus;
            account.FullName      = model.FullName;
            account.RoleId        = (int)model.AccountType;
            account.Mobile        = model.Mobile;
            account.UpdateTime    = DateTime.Now;
            account.Gender        = model.Gender;
            account.AccountType   = (int)model.AccountType;
            account.IdCard        = model.IdCard;
            this.Update(account, true);
            return(result);
        }