예제 #1
0
        /// <summary>
        /// 添加运营商
        /// </summary>
        public bool AddMerchant(VMerchant merchant, out string msg)
        {
            msg = string.Empty;

            //检查是否存在注册用户
            if (DACFacade.Movo.UserDAC.SelectByName(merchant.UserName) != null)
            {
                msg = "用户名重复,请重新输入";
                return false;
            }

            //检查是否存在运营商
            if (DACFacade.Movo.TenantDAC.SelectByName(merchant.TenantName) != null)
            {
                msg = "公司名称重复,请重新输入";
                return false;
            }

            //创建运营商tenant
            ETenant tenant = new ETenant();
            tenant.ContactName = merchant.ContactName;
            tenant.ExpireTime = merchant.ExpireTime.Equals(DateTime.MaxValue) ? null : (DateTime?)merchant.ExpireTime;
            tenant.TenantName = merchant.TenantName;
            tenant.TenantCode = DACFacade.Movo.IdentityNoDAC.GetTenantSerialNo();
            tenant.SuperTenantID = merchant.SuperTenantID;
            tenant.Email = merchant.Email;
            tenant.QQ = merchant.QQ;
            tenant.PhoneNumber = merchant.PhoneNumber;
            tenant.LogoUrl = UploadImageHelper.GetImgName(merchant.TenantLogoImgURl);
            tenant.TenantType = EnumTenantType.OperatingMerchant;
            tenant.OperatorLevel = merchant.OperatorLevel;
            tenant.CreateTime = DateTime.Now;
            tenant.IsFreeze = false;
            tenant.RegisterUserName = merchant.UserName;
            tenant.IsEnableAddDevice = merchant.IsEnableAddDevice;

            //创建用户组userGroup
            EUserGroup userGroup = new EUserGroup();
            userGroup.IsAdminGroup = true;
            userGroup.TenantCode = tenant.TenantCode;
            userGroup.UserGroupID = DACFacade.Movo.IdentityNoDAC.GetUserGroupID();
            userGroup.UserGroupName = merchant.UserName;

            //创建注册用户User
            EUser user = new EUser();
            user.PassWord = merchant.Password;
            user.UserCode = DACFacade.Movo.IdentityNoDAC.GetUserSerialNo();
            user.UserName = merchant.UserName;
            user.CreateTime = DateTime.Now;
            user.IsRegisterUser = true;
            user.UserGroupID = userGroup.UserGroupID;
            user.TenantCode = tenant.TenantCode;

            tenant.RegisterUserCode = user.UserCode;

            using (var trans = DACFacade.Movo.TenantDAC.BeginTransaction())
            {
                try
                {
                    int addtenant = DACFacade.Movo.TenantDAC.Insert(trans, tenant);
                    int addusergroup = DACFacade.Movo.UserGroupDAC.Insert(trans, userGroup);
                    int adduser = DACFacade.Movo.UserDAC.Insert(trans, user);
                    if (addtenant >= 1 && addusergroup >= 1 && adduser >= 1)
                    {
                        trans.Commit();
                        return true;
                    }
                    else
                    {
                        trans.Rollback();
                        msg = "添加运营商数据异常(addtenant:" + addtenant.ToString() + "addusergroup:" + addusergroup.ToString() + "adduser:"******")";
                        Logger.Error(msg);
                        return false;
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    trans.Rollback();
                    Logger.Error(ex.Message, ex);
                }
            }

            return false;
        }
예제 #2
0
        /// <summary>
        /// 新增客户
        /// </summary>
        public void AddCustomer(SessionContext passport, string userName, string password, string tenantName, string phoneNumber, string email)
        {
            var selected = this.GetSelectedTenant(passport);
            var parentMerchant = DACFacade.Movo.TenantDAC.Select(selected.TenantCode);
            if (parentMerchant == null) throw new BusinessException("父级运营商不存在!");
            //if (parentMerchant.OperatorLevel + 1 > 5) throw new BusinessException("新增失败,子运营商不能多于5级!");

            var existUser = DACFacade.Movo.UserDAC.SelectByName(userName);
            if (existUser != null) { throw new BusinessException("用户名" + userName + "已经存在,请重新输入!"); }

            var existTenant = DACFacade.Movo.TenantDAC.SelectByName(tenantName);
            if (existTenant != null) { throw new BusinessException("公司名称" + tenantName + "已经存在,请重新输入!"); }


            // 构建Tenant
            var tenant = new ETenant();
            tenant.TenantCode = DACFacade.Movo.IdentityNoDAC.GetTenantSerialNo();
            tenant.TenantName = tenantName;
            tenant.SuperTenantID = parentMerchant.TenantCode;
            tenant.CreateTime = DateTime.Now;
            tenant.ExpireTime = null;
            tenant.ContactName = string.Empty;
            tenant.PhoneNumber = phoneNumber;
            tenant.TenantType = EnumTenantType.EndCustomer;
            tenant.IsFreeze = false;
            tenant.QQ = string.Empty;
            tenant.Email = email;
            tenant.RegisterUserCode = DACFacade.Movo.IdentityNoDAC.GetUserSerialNo();
            tenant.RegisterUserName = userName;
            tenant.OperatorLevel = null;
            tenant.LogoUrl = null;

            // 构建UserGroup
            var userGroup = new EUserGroup()
            {
                UserGroupID = DACFacade.Movo.IdentityNoDAC.GetUserGroupID(),
                UserGroupName = "管理员",
                TenantCode = tenant.TenantCode,
                IsAdminGroup = true,
            };

            // 构建User
            var user = new EUser();
            user.UserCode = tenant.RegisterUserCode;
            user.UserName = userName;
            user.UserGroupID = userGroup.UserGroupID;
            user.TenantCode = tenant.TenantCode;
            if (!string.IsNullOrEmpty(password)) user.PassWord = password;
            user.RealName = userName;
            user.Mobile = string.Empty;
            user.IsRegisterUser = true;
            user.LastLoginTime = null;
            user.CreateTime = DateTime.Now;

            // 构建VehicleGroup
            var vehGroup = new EVehicleGroup()
            {
                GroupID = DACFacade.Movo.IdentityNoDAC.GetVehicleGroupID(),
                GroupName = userName,
                TenantCode = tenant.TenantCode,
            };

            using (var trans = DACFacade.Movo.TenantDAC.BeginTransaction())
            {
                try
                {
                    DACFacade.Movo.UserDAC.Insert(trans, user);
                    DACFacade.Movo.UserGroupDAC.Insert(trans, userGroup);
                    DACFacade.Movo.VehicleGroupDAC.Insert(trans, vehGroup);
                    DACFacade.Movo.TenantDAC.Insert(trans, tenant);
                    DACFacade.Movo.TenantDAC.CommitTransaction(trans);
                }
                catch
                {
                    DACFacade.Movo.TenantDAC.RollbackTransaction(trans);
                    throw;
                }
            }
        }