コード例 #1
0
        public ActionResult Edit(Guid?id, SysEnterprise collection)
        {
            if (!ModelState.IsValid)
            {
                return(View(collection));
            }

            _sysEnterpriseService.Save(id, collection);

            if (!id.HasValue)
            {
                //添加企业的时候需要给该企业初始化 角色和管理员账户

                //新建角色

                var sysRoleSysControllerSysActions = new List <SysRoleSysControllerSysAction>();

                foreach (var aa in _sysControllerSysActionService.GetAllEnt().Where(a => a.SysController.SysArea.AreaName == "Platform"))
                {
                    sysRoleSysControllerSysActions.Add(new SysRoleSysControllerSysAction
                    {
                        EnterpriseId           = collection.Id,
                        SysControllerSysAction = aa
                    });
                }

                var role = new SysRole
                {
                    EnterpriseId = collection.Id,
                    RoleName     = "管理员",
                    SysRoleSysControllerSysActions = sysRoleSysControllerSysActions,
                };
                //新建管理员
                var user = new SysUser
                {
                    EnterpriseId    = collection.Id,
                    UserName        = "******",
                    Password        = "******",
                    OldPassword     = "******",
                    DisplayName     = "管理员",
                    SysRoleSysUsers = new List <SysRoleSysUser>
                    {
                        new SysRoleSysUser
                        {
                            EnterpriseId = collection.Id,
                            SysRole      = role,
                        }
                    }
                };

                _sysUserService.Add(user);
            }

            _unitOfWork.Commit();

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        //
        // GET: /Platform/SysEnterprise/Edit/5

        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> Edit(string id)
        {
            var item = new SysEnterprise();

            if (!string.IsNullOrEmpty(id))
            {
                item = _SysEnterpriseService.GetById(id);
            }
            return(View(item));
        }
コード例 #3
0
        //
        // GET: /Platform/SysEnterprise/Edit/5

        public ActionResult Edit(Guid?id)
        {
            var item = new SysEnterprise();

            if (id.HasValue)
            {
                item = _sysEnterpriseService.GetById(id.Value);
            }
            return(View(item));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(string id, SysEnterprise collection)
        {
            if (!ModelState.IsValid)
            {
                await Edit(id);

                return(View(collection));
            }
            //只能创建下级企业,ID自动分配
            if (string.IsNullOrEmpty(id))
            {
                var curEntId = _iUserInfo.EnterpriseId;
                collection.Id = curEntId + (_SysEnterpriseService.GetAll(DeletedDataType.All).Count(a => a.Id.StartsWith(curEntId) && a.Id.Length.Equals(curEntId.Length + 3)) + 1).ToString().PadLeft(3, '0');
            }
            _SysEnterpriseService.Save(id, collection);

            await _SysEnterpriseService.CommitAsync();

            return(new EditSuccessResult(id));
        }
コード例 #5
0
        public ActionResult Index(InitializeModel item)
        {
            if (applicationDbContext.SysEnterprises.Any(u => !u.Deleted && u.EnterpriseName == item.EnterpriseName))
            {
                ModelState.AddModelError("EnterpriseName", @"该企业名称已存在");
            }

            if (applicationDbContext.SysEnterprises.Any(u => !u.Deleted && u.EnterpriseShortName == item.EnterpriseShortName))
            {
                ModelState.AddModelError("EnterpriseShortName", @"该企业简称已存在");
            }

            if (!ModelState.IsValid)
            {
                return(View(item));
            }

            try
            {
                #region SysEnterprise

                var host = Spell.MakeSpellCode(item.EnterpriseShortName, SpellOptions.FirstLetterOnly);

                //检查Host是否已经被占用

                while (applicationDbContext.SysEnterprises.Any(a => a.Host == host))
                {
                    host = host + new Random().Next(11, 99);
                }

                host = host + ".wjw1.com";

                var sysEnterprise = new SysEnterprise {
                    EnterpriseName = item.EnterpriseName, EnterpriseShortName = item.EnterpriseShortName, Host = host
                };

                applicationDbContext.SysEnterprises.Add(sysEnterprise);

                #endregion

                //添加管理员权限栏位
                #region SysRole

                //var sysRole = new SysRole { RoleName = "管理员", EnterpriseId = sysEnterprise.Id };
                var sysRole = new SysRole()
                {
                    RoleName = "管理员"
                };

                applicationDbContext.SysRoles.Add(sysRole);

                #endregion

                //添加管理员账号
                #region Add Administrator User

                var sysUser = new SysUser
                {
                    //EnterpriseId = sysEnterprise.Id,
                    UserName    = item.UserName,
                    DisplayName = "系统管理员",
                    Email       = item.Email,
                    Password    = HashPassword.GetHashPassword(item.Password),
                    OldPassword = HashPassword.GetHashPassword(item.Password),
                };

                applicationDbContext.SysUsers.Add(sysUser);

                #endregion

                //对应管理员账号和管理员权限
                #region SysRoleSysUser

                var sysRoleSysUser = new SysRoleSysUser
                {
                    //EnterpriseId = sysEnterprise.Id,
                    SysUserId = sysUser.Id,
                    SysRoleId = sysRole.Id
                };

                applicationDbContext.SysRoleSysUsers.Add(sysRoleSysUser);

                #endregion

                //添加详细权限给予管理员角色
                #region SysRoleSysControllerSysAction

                var sysRoleSysControllerSysAction = new List <SysRoleSysControllerSysAction>();

                foreach (var sysControllerSysAction in applicationDbContext.SysControllerSysActions)
                {
                    sysRoleSysControllerSysAction.Add(new SysRoleSysControllerSysAction
                    {
                        //EnterpriseId = sysEnterprise.Id,
                        SysControllerSysActionId = sysControllerSysAction.Id,
                        SysRoleId = sysRole.Id
                    });
                }

                sysRoleSysControllerSysAction.ForEach(a => applicationDbContext.SysRoleSysControllerSysActions.Add(a));

                #endregion

                applicationDbContext.SaveChanges();

                TempData[Alerts.SUCCESS] = "注册成功!";

                return(RedirectToAction("Index", "Succes", new { Id = sysEnterprise.Id }));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(View(item));
            }
        }