Beispiel #1
0
        public ActionResponseDto Edit(TenantInputDto dto)
        {
            var tenant = _tenantManager.Get(dto.Id) ?? new Tenant();

            Mapper.Map(dto, tenant);
            bool isNewTenant = tenant.Id == Guid.Empty;

            // 保存租户
            _tenantManager.Save(ref tenant);
            // 保存超级管理员
            using (UnitOfWork.DisableFilter(typeof(OwnerTenantFilter)))
            {
                var superAdmin = _userManager.Get(u =>
                                                  u.Username == dto.SuperAdminName &&
                                                  u.OwnerTenantId == tenant.Id) ?? new User();
                superAdmin.Type        = SuperAdminUserType.ConstType;
                superAdmin.Username    = dto.SuperAdminName;
                superAdmin.OwnerTenant = tenant;
                if (dto.SuperAdminPassword != dto.SuperAdminConfirmPassword)
                {
                    throw new BadRequestException("Confirm password not matched with password");
                }
                else if (!string.IsNullOrEmpty(dto.SuperAdminPassword))
                {
                    superAdmin.SetPassword(dto.SuperAdminPassword);
                }
                else if (superAdmin.Id == Guid.Empty)
                {
                    throw new BadRequestException("Please provider a password for new user");
                }
                _userManager.Save(ref superAdmin);
            }
            return(ActionResponseDto.CreateSuccess("Saved Successfully"));
        }
        public ActionResponseDto SaveWebsiteSettings(WebsiteSettingsDto dto)
        {
            var settings = Mapper.Map <WebsiteSettings>(dto);

            _configManager.PutData(settings);
            return(ActionResponseDto.CreateSuccess("Saved Successfully"));
        }
        public ActionResponseDto UploadAvatar(UserUploadAvatarInputDto dto)
        {
            var userId = _sessionManager.GetSession().UserId.Value;

            _userManager.SaveAvatar(userId, dto.Avatar.OpenReadStream());
            return(ActionResponseDto.CreateSuccess("Upload Avatar Successfully"));
        }
Beispiel #4
0
        public ActionResponseDto Edit(ExampleDataInputDto dto)
        {
            var data = _exampleDataManager.Get(dto.Id) ?? new ExampleData();

            Mapper.Map(dto, data);
            _exampleDataManager.Save(ref data);
            return(ActionResponseDto.CreateSuccess("Saved Successfully"));
        }
Beispiel #5
0
        public ActionResponseDto Edit(RoleInputDto dto)
        {
            var role = _roleManager.Get(dto.Id) ?? new Role();

            Mapper.Map(dto, role);
            _roleManager.Save(ref role);
            return(ActionResponseDto.CreateSuccess("Saved Successfully"));
        }
 public ActionResponseDto ClearCache()
 {
     foreach (var cleaner in _cacheCleaners)
     {
         cleaner.ClearCache();
     }
     GC.Collect();
     return(ActionResponseDto.CreateSuccess("Clear Cache Successfully"));
 }
Beispiel #7
0
 public ActionResponseDto Remove(Guid id)
 {
     if (_tenantManager.Count(x => x.Id == id && x.IsMaster) > 0)
     {
         throw new BadRequestException("You can't delete master tenant");
     }
     _tenantManager.Delete(id);
     return(ActionResponseDto.CreateSuccess("Deleted Successfully"));
 }
        public ActionResponseDto ChangePassword(UserChangePasswordInputDto dto)
        {
            if (dto.NewPassword != dto.ConfirmNewPassword)
            {
                throw new BadRequestException("Confirm password not matched with password");
            }
            var userId = _sessionManager.GetSession().UserId.Value;

            _userManager.ChangePassword(userId, dto.OldPassword, dto.NewPassword);
            return(ActionResponseDto.CreateSuccess("Change Password Successfully"));
        }
 public virtual ActionResponseDto LoginAdmin(UserLoginRequestDto request)
 {
     // 检查验证码
     if (!_captchaManager.Check("AdminLogin", request.Captcha))
     {
         throw new BadRequestException("Incorrect captcha");
     }
     // 登录用户
     _adminManager.Login(
         request.Tenant,
         request.Username,
         request.Password,
         request.RememberLogin ?? true);
     return(ActionResponseDto.CreateSuccess());
 }
        public ActionResponseDto Edit(UserInputDto dto)
        {
            var user = _userManager.Get(dto.Id) ?? new User();

            Mapper.Map(dto, user);
            // 设置用户密码
            if (!string.IsNullOrEmpty(dto.Password))
            {
                user.SetPassword(dto.Password);
            }
            else if (user.Id == Guid.Empty)
            {
                throw new BadRequestException("Please provider a password for new user");
            }
            // 保存用户
            _userManager.Save(ref user);
            // 设置角色列表
            if (dto.RoleIds != null)
            {
                _userManager.AssignRoles(user, dto.RoleIds);
            }
            return(ActionResponseDto.CreateSuccess("Saved Successfully"));
        }
 public ActionResponseDto Remove(Guid id)
 {
     _userManager.Delete(id);
     return(ActionResponseDto.CreateSuccess("Deleted Successfully"));
 }