Esempio n. 1
0
 /// <summary>
 /// 更新系统用户
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public OpResult UpdateUser(Entity.SysUserInfo model)
 {
     try
     {
         _dal.Update(model);
         return(OpResult.Success("数据保存成功"));
     }
     catch (Exception ex)
     {
         return(OpResult.Fail("数据保存失败!" + ex.Message));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 保存用户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public OpResult SaveUser(Entity.SysUserInfo model)
        {
            var result = OpResult.Fail("数据保存失败!");

            try
            {
                model.CompanyId = Sys.SysCommonRules.CompanyId;//16.03.24增加企业标识
                if (_dal.ExistName(model))
                {
                    var oldObj = _dal.GetById(model.Id);
                    if (oldObj != null)
                    {
                        var re       = _dal.Update(model);
                        var suserobj = _storedal.GetByColumn(oldObj.UID, "UID");
                        if (suserobj != null)
                        {
                            _storedal.Update(oldObj.UID);
                        }
                        if (re)
                        {
                            result = OpResult.Success("数据保存成功");
                        }
                    }
                    else
                    {
                        //判断员工编号是否重复
                        if (_dal.ExistsColumn(0, "Id", model.UserCode, "UserCode", SysCommonRules.CompanyId))
                        {
                            result = OpResult.Fail("该编号已存在,请重新输入编号");
                        }
                        else
                        {
                            model.CreateDT = DateTime.Now;
                            model.LoginDT  = DateTime.Now;
                            model.UID      = SysCommonRules.GUID;
                            if (model.LoginPwd == null)
                            {
                                result = OpResult.Fail("新增用户,密码不能为空!");
                            }
                            else
                            {
                                var auth = CurrentUser.Company;
                                if (auth != null && auth.UserNum > 0)
                                {
                                    if (_dal.GetUsers(1).Count > auth.UserNum)
                                    {
                                        result.Message = "用户数超过允许的数量,不能再添加!";
                                        return(result);
                                    }
                                }
                                var re = _dal.Insert(model);
                                if (re > 0)
                                {
                                    result = OpResult.Success("数据保存成功");
                                }
                            }
                        }
                    }
                }
                else
                {
                    result = OpResult.Fail("员工姓名或登录帐号重复");
                }
            }
            catch (Exception ex)
            {
                result = OpResult.Fail("数据保存失败!" + ex.Message);
            }
            return(result);
        }