コード例 #1
0
        public IHttpActionResult SetPropertyConut()
        {
            var goverments = _governmentService.GetAllGovernmentUnits();
            var role       = _accountUserService.GetAccountUserRoleBySystemName(SystemAccountUserRoleNames.ParentGovernmentorAuditor);

            foreach (var g in goverments)
            {
                g.PropertyConut = g.Properties.Count;
                if (g.ParentGovernmentId != 0)
                {
                    var parent = _governmentService.GetGovernmentUnitById(g.ParentGovernmentId);

                    g.ParentName = parent.Name;
                }

                _governmentService.UpdateGovernmentUnit(g);

                var users = g.Users;
                foreach (var user in users)
                {
                    if (g.ParentGovernmentId == 0)
                    {
                        if (user.AccountUserRoles.Where(ur => ur.Name == SystemAccountUserRoleNames.ParentGovernmentorAuditor).Count() == 0)
                        {
                            user.AccountUserRoles.Add(role);
                            _accountUserService.UpdateAccountUser(user);
                        }
                    }
                }
            }


            return(Ok("赋值完成"));
        }
コード例 #2
0
        public IHttpActionResult Create(AccountUserModel accountModel)
        {
            var account = accountModel.ToEntity();

            //问题: An entity object cannot be referenced by multiple instances of IEntityChangeTracker
            //状态:Fixed
            //原因:不明,但是应该和缓存机制有关
            var government = _governmentService.GetGovernmentUnitById(accountModel.GovernmentId);

            if (government == null)
            {
                return(BadRequest("用户所属单位不存在"));
            }
            account.Government = government;

            var registerRole = _accountService.GetAccountUserRoleBySystemName(SystemAccountUserRoleNames.Registered);
            var adminRole    = _accountService.GetAccountUserRoleBySystemName(SystemAccountUserRoleNames.Administrators);

            account.Password = "******";  //设置初始密码

            var role = _accountService.GetAccountUserRoleBySystemName(accountModel.RoleName);

            if (role != null && accountModel.RoleName != SystemAccountUserRoleNames.Registered)
            {
                account.AccountUserRoles.Add(role);
            }

            var registrationRequest = new AccountUserRegistrationRequest(account, account.UserName,
                                                                         account.Password, _accountUserSettings.DefaultPasswordFormat, accountModel.Active);

            var registrationResult = _accountUserRegistrationService.RegisterAccountUser(registrationRequest);

            if (registrationResult.Success)
            {
                //保存用户
                _accountService.InsertAccountUser(account);

                //activity log
                _accountUserActivityService.InsertActivity("AddNewAccount", "增加 名为 {0} 的用户", account.UserName);

                return(Ok(account.ToModel()));
            }
            else
            {
                return(BadRequest("添加用户失败"));
            }
        }
コード例 #3
0
ファイル: AccountUserValidator.cs プロジェクト: YuweiDai/CS
        public AccountUserValidator(IAccountUserService accountUserService, IGovernmentService governmentService)
        {
            _accountUserService = accountUserService;
            _governmentService  = governmentService;

            RuleFor(s => s.UserName).NotEmpty().WithMessage("用户名不能为空").Must(BeUniqueName).WithMessage("名称 {0} 已存在", s => s.UserName);

            RuleFor(s => s.GovernmentId).Must(governmentId =>
            {
                var accountUserGovernment = governmentService.GetGovernmentUnitById(governmentId);
                return(accountUserGovernment != null && !accountUserGovernment.Deleted);
            }).WithMessage(string.Format("单位不存在"));
        }
コード例 #4
0
        public IHttpActionResult Get(int governmentId)
        {
            var government = _governmentService.GetGovernmentUnitById(governmentId);

            if (government == null || government.Deleted)
            {
                return(NotFound());
            }

            var model = government.ToModel();

            var parentGovernemnt = _governmentService.GetGovernmentUnitById(model.ParentGovernmentId);

            if (parentGovernemnt != null)
            {
                model.ParentGovernment = parentGovernemnt.Name;
            }

            var childrenGovernments = _governmentService.GetAllGovernmentsByParentGovernmentId(model.Id);

            if (childrenGovernments != null)
            {
                model.ChildrenGorvernments = childrenGovernments.Select(g =>
                {
                    return(new SimpleGovernmentUnitModel
                    {
                        Id = g.Id,
                        Name = g.Name
                    });
                }).ToList();
            }


            //activity log
            _accountUserActivityService.InsertActivity("GetGovernemntInfo", "获取 名为 {0} 的单位信息", government.Name);

            return(Ok(model));
        }