Ejemplo n.º 1
0
        public MyResult <object> AddAccount(BackstageUserAdd model)
        {
            MyResult      result  = new MyResult();
            BackstageUser account = this.First <BackstageUser>(t => t.LoginName == model.LoginName);

            if (account != null)
            {
                return(result.SetStatus(ErrorCode.NotFound, "登录名称已经存在!"));
            }
            else
            {
                account = new BackstageUser();
            }
            if (!DataValidUtil.IsIDCard(model.IdCard))
            {
                return(result.SetStatus(ErrorCode.InvalidData, "身份证非法!"));
            }
            model.Password = model.Password == "" ? "123456" : model.Password;
            string pwd = SecurityUtil.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
        public MyResult <object> UpdateAccount(BackstageUserAdd model)
        {
            MyResult      result  = new MyResult();
            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 = SecurityUtil.MD5(model.Password);
                account.Password = pwd;
            }
            if (!DataValidUtil.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);
        }