コード例 #1
0
        public IHttpActionResult Create(GovernmentUnitModel governmentUnitModel)
        {
            var government = governmentUnitModel.ToEntity();

            if (ModelState.IsValid)
            {
                _governmentService.InsertGovernmentUnit(government);

                //activity log
                _accountUserActivityService.InsertActivity("AddNewGovernment", "新增名为 {0} 的单位", government.Name);

                //SuccessNotification(_localizationService.GetResource("Admin.Catalog.Categories.Added"));

                return(Ok(government.ToModel()));
            }
            else
            {
                return(BadRequest("类别模型数据错误"));
            }
        }
コード例 #2
0
        public IHttpActionResult SetRoles()
        {
            //  return BadRequest("角色配置 cloesd");
            #region 用户角色创建

            var crAdministrators = new AccountUserRole();
            var crRegistered     = new AccountUserRole();

            var roleNames = new List <string> {
                SystemAccountUserRoleNames.Administrators,
                SystemAccountUserRoleNames.DataReviewer,
                SystemAccountUserRoleNames.GovAuditor,
                SystemAccountUserRoleNames.StateOwnerAuditor,
                SystemAccountUserRoleNames.ParentGovernmentorAuditor,
                SystemAccountUserRoleNames.Registered
            };

            foreach (var roleName in roleNames)
            {
                var role = _accountUserService.GetAccountUserRoleBySystemName(roleName);
                if (role == null)
                {
                    role = new AccountUserRole
                    {
                        Name         = roleName,
                        Active       = true,
                        IsSystemRole = true,
                        SystemName   = roleName
                    };

                    _accountUserService.InsertAccountUserRole(role);
                }
                if (roleName == SystemAccountUserRoleNames.Administrators)
                {
                    crAdministrators = role;
                }
                if (roleName == SystemAccountUserRoleNames.Registered)
                {
                    crRegistered = role;
                }
            }
            #endregion
            #region 测试组织机构

            var cz = new GovernmentUnit
            {
                Name           = "县财政局",
                GovernmentType = GovernmentType.Government,
                Person         = "联系人",
                Tel            = "0570-5062456"
            };
            _governmentService.InsertGovernmentUnit(cz);

            #endregion

            #region 用户创建

            var user = new AccountUser()
            {
                UserName         = "******",
                AccountUserGuid  = Guid.NewGuid(),
                Active           = true,
                CreatedOn        = DateTime.Now,
                IsSystemAccount  = false,
                Password         = "******",
                PasswordFormat   = PasswordFormat.Clear,
                LastActivityDate = DateTime.Now,
                Deleted          = false,
                UpdatedOn        = DateTime.Now,
                Government       = cz
            };
            user.AccountUserRoles.Add(crAdministrators);
            user.AccountUserRoles.Add(crRegistered);
            _accountUserService.InsertAccountUser(user);

            user = new AccountUser()
            {
                UserName         = "******",
                AccountUserGuid  = Guid.NewGuid(),
                Active           = true,
                CreatedOn        = DateTime.Now,
                IsSystemAccount  = false,
                Password         = "******",
                PasswordFormat   = PasswordFormat.Clear,
                LastActivityDate = DateTime.Now,
                Deleted          = false,
                UpdatedOn        = DateTime.Now,
                Government       = cz
            };
            _accountUserService.InsertAccountUser(user);

            #endregion

            return(Ok("角色配置完成"));
        }