Example #1
0
        public async Task <PagedResultOutput <NameValueDto> > FindUsers(FindUsersInput input)
        {
            if (AbpSession.MultiTenancySide == MultiTenancySides.Host && input.TenantId.HasValue)
            {
                CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, input.TenantId.Value);
            }

            var query = UserManager.Users
                        .WhereIf(
                !input.Filter.IsNullOrWhiteSpace(),
                u =>
                u.Name.Contains(input.Filter) ||
                u.Surname.Contains(input.Filter) ||
                u.UserName.Contains(input.Filter) ||
                u.EmailAddress.Contains(input.Filter)
                );

            var userCount = await query.CountAsync();

            var users = await query
                        .OrderBy(u => u.Name)
                        .ThenBy(u => u.Surname)
                        .PageBy(input)
                        .ToListAsync();

            return(new PagedResultOutput <NameValueDto>(
                       userCount,
                       users.Select(u =>
                                    new NameValueDto(
                                        u.Name + " " + u.Surname + " (" + u.EmailAddress + ")",
                                        u.Id.ToString()
                                        )
                                    ).ToList()
                       ));
        }
        public async Task <PagedResultOutput <HomeOwerUserDto> > GetHomeOwerUsers(GetHomeOwerUsersInput input)
        {
            using (CurrentUnitOfWork.EnableFilter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name))
            {
                using (CurrentUnitOfWork.SetFilterParameter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name, AbpZeroTemplateConsts.AdminCommunityFilterClass.ParameterName, await GetAdminCommunityIdList()))
                {
                    var query = _manager.FindHomeOwerUserList(input.Sorting);
                    query.Include("HomeOwer");
                    var totalCount = await query.CountAsync();

                    var items = await query.OrderByDescending(h => h.CreationTime).PageBy(input).ToListAsync();

                    return(new PagedResultOutput <HomeOwerUserDto>(
                               totalCount,
                               items.Select(
                                   item =>
                    {
                        var dto = item.MapTo <HomeOwerUserDto>();
                        return dto;
                    }
                                   ).ToList()
                               ));
                }
            }
        }
Example #3
0
        public async Task <PagedResultOutput <AccessKeyDto> > GetAccessKeys(GetAccessKeysInput input)
        {
            using (CurrentUnitOfWork.EnableFilter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name))
            {
                using (CurrentUnitOfWork.SetFilterParameter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name, AbpZeroTemplateConsts.AdminCommunityFilterClass.ParameterName, await GetAdminCommunityIdList()))
                {
                    var query = _manager.FindAccessKeyList(input.Sorting);

                    var homeOwerDic = new Dictionary <long, string>();
                    var doorDic     = new Dictionary <long, string>();

                    var totalCount = await query.CountAsync();

                    var items = await query.PageBy(input).ToListAsync();

                    items.ForEach(i =>
                    {
                        if (!homeOwerDic.Keys.Contains(i.HomeOwer.Id))
                        {
                            homeOwerDic.Add(i.HomeOwer.Id, string.Empty);
                        }
                        if (!doorDic.Keys.Contains(i.Door.Id))
                        {
                            doorDic.Add(i.Door.Id, string.Empty);
                        }
                    });

                    var homeOwerNames = from h in _homeOwerManager.HomeOwerRepository.GetAll()
                                        where homeOwerDic.Keys.Contains(h.Id)
                                        select new { h.Id, h.Name };
                    await homeOwerNames.ForEachAsync(h =>
                    {
                        homeOwerDic[h.Id] = h.Name;
                    });

                    var doorNames = from d in _doorManager.DoorRepository.GetAll()
                                    where doorDic.Keys.Contains(d.Id)
                                    select new { d.Id, d.Name };
                    await doorNames.ForEachAsync(d =>
                    {
                        doorDic[d.Id] = d.Name;
                    });


                    return(new PagedResultOutput <AccessKeyDto>(
                               totalCount,
                               items.Select(
                                   item =>
                    {
                        var dto = item.MapTo <AccessKeyDto>();
                        dto.HomeOwerName = homeOwerDic[item.HomeOwer.Id];
                        dto.DoorName = doorDic[item.Door.Id];
                        return dto;
                    }
                                   ).ToList()
                               ));
                }
            }
        }
Example #4
0
        public async Task CreateTenant(CreateTenantInputDto inputDto)
        {
            if ((await _tenantManager.FindByTenancyNameAsync(inputDto.TenancyName)).IsNotNull())
            {
                throw new HozaruException(string.Format("Toko Id {0} tidak bisa digunakan. Silahkan gunakan Toko Id lain.", inputDto.TenancyName));
            }

            var district = _districtRepository.Get(inputDto.DistrictId);

            Validate.Found(district, "Kecamatan");

            var tenant         = new Tenant(inputDto.TenancyName, inputDto.Name, inputDto.WhatsappNumber, inputDto.Address, inputDto.Phone, district);
            var defaultEdition = await _editionManager.FindByNameAsync(EditionManager.DefaultEditionName);

            if (defaultEdition != null)
            {
                tenant.EditionId = defaultEdition.Id;
            }

            var createTenantResult = await _tenantManager.CreateAsync(tenant);

            createTenantResult.CheckErrors();
            await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id.

            CurrentUnitOfWork.DisableFilter(HozaruDataFilters.MayHaveTenant);
            CurrentUnitOfWork.DisableFilter(HozaruDataFilters.MustHaveTenant);
            CurrentUnitOfWork.EnableFilter(HozaruDataFilters.MayHaveTenant);
            using (CurrentUnitOfWork.SetFilterParameter(HozaruDataFilters.MayHaveTenant, HozaruDataFilters.Parameters.TenantId, tenant.Id))
            {
                IList <Role> createdRoles = await _roleAppService.CreateDefaultRoles(tenant.Id);

                foreach (var role in createdRoles)
                {
                    await _roleManager.GrantAllPermissionsAsync(role);
                }

                await CurrentUnitOfWork.SaveChangesAsync();

                //Create admin user for the tenant
                var adminUser        = User.CreateTenantAdminUser(tenant, inputDto.AdminEmailAddress, inputDto.Password, inputDto.FirstName, inputDto.LastName);
                var createUserResult = await _userManager.CreateAsync(adminUser);

                createUserResult.CheckErrors();
                await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id

                var adminRole = _roleManager.Roles.Single(r => r.Name == "Admin");
                //Assign admin user to role!
                var addRoleResult = await _userManager.AddToRoleAsync(adminUser.Id, adminRole.Name);

                addRoleResult.CheckErrors();

                //await _tenantConfigurationAppService.CreateNew(tenant);

                await CurrentUnitOfWork.SaveChangesAsync();
            }

            _apiKeyService.CreateApiKey(tenant.Id);
        }
Example #5
0
        [AbpAuthorize("CanCreateUsers")] //An example of permission checking
        public async Task CreateUser(CreateUserInput input)
        {
            if (AbpSession.MultiTenancySide == MultiTenancySides.Host)
            {
                CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, input.TenantId);

                await _userRepository.InsertAsync(new User(input.Name, input.UserName, input.Surname, input.EmailAddress, input.TenantId));
            }
        }
Example #6
0
        public async Task CreateTenant(CreateTenantInput input)
        {
            //Create tenant
            var tenant = new Tenant(input.TenancyName, input.Name)
            {
                IsActive = input.IsActive, EditionId = input.EditionId
            };

            CheckErrors(await TenantManager.CreateAsync(tenant));
            await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id.

            //We are working entities of new tenant, so changing tenant filter
            CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id);

            //Create static roles for new tenant
            CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));

            await CurrentUnitOfWork.SaveChangesAsync(); //To get static role ids

            //grant all permissions to admin role
            var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin);
            await _roleManager.GrantAllPermissionsAsync(adminRole);

            //User role should be default
            var userRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.User);

            userRole.IsDefault = true;
            CheckErrors(await _roleManager.UpdateAsync(userRole));

            //Create admin user for the tenant
            if (input.AdminPassword.IsNullOrEmpty())
            {
                input.AdminPassword = User.CreateRandomPassword();
            }

            var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, input.AdminPassword);

            adminUser.ShouldChangePasswordOnNextLogin = input.ShouldChangePasswordOnNextLogin;
            adminUser.IsActive = input.IsActive;

            CheckErrors(await UserManager.CreateAsync(adminUser));
            await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id

            //Assign admin user to role!
            CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));

            if (input.SendActivationEmail)
            {
                adminUser.SetNewEmailConfirmationCode();
                await _userEmailer.SendEmailActivationLinkAsync(adminUser, input.AdminPassword);
            }

            await CurrentUnitOfWork.SaveChangesAsync();

            //Changing back to original tenantId value.
            CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, AbpSession.TenantId);
        }
 public async Task <PagedResultOutput <DeliveryDto> > GetDeliverys(GetDeliverysInput input)
 {
     using (CurrentUnitOfWork.EnableFilter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name))
     {
         using (CurrentUnitOfWork.SetFilterParameter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name, AbpZeroTemplateConsts.AdminCommunityFilterClass.ParameterName, await GetAdminCommunityIdList()))
         {
             return(await ProcessGet(input));
         }
     }
 }
Example #8
0
 public IEnumerable <Caja> GetAllList(int AgenciaId)
 {
     if (!CurrentUnitOfWork.IsFilterEnabled(DataFilters.MustHaveAgency))
     {
         CurrentUnitOfWork.EnableFilter(DataFilters.MustHaveAgency);
     }
     using (CurrentUnitOfWork.SetFilterParameter(DataFilters.MustHaveAgency,
                                                 DataFilters.MustHaveAgencyParam, AgenciaId)) {
         return(_Repository.GetAll());
     }
 }
Example #9
0
        public async Task BuildForAsync(Tenant tenant)
        {
            if (IsInDemoMode)
            {
                using (CurrentUnitOfWork.SetFilterParameter("MayHaveTenant", "tenantId", tenant.Id))
                {
                    await BuildForInternalAsync(tenant);

                    await CurrentUnitOfWork.SaveChangesAsync();
                }
            }
        }
Example #10
0
        public async Task CreateTenant(CreateTenantInput input)
        {
            Tenant tenant = new Tenant(input.TenancyName, input.Name)
            {
                IsActive  = input.IsActive,
                EditionId = input.EditionId
            };
            Tenant tenant1 = tenant;

            this.CheckErrors(await this.TenantManager.CreateAsync(tenant1));
            await this.CurrentUnitOfWork.SaveChangesAsync();

            using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, "tenantId", tenant1.Id))
            {
                IdentityResult identityResult = await this._roleManager.CreateStaticRoles(tenant1.Id);

                this.CheckErrors(identityResult);
                await this.CurrentUnitOfWork.SaveChangesAsync();

                IQueryable <Role> roles = this._roleManager.Roles;
                Role role = roles.Single <Role>((Role r) => r.Name == "Admin");
                await this._roleManager.GrantAllPermissionsAsync(role);

                IQueryable <Role> roles1 = this._roleManager.Roles;
                Role role1 = roles1.Single <Role>((Role r) => r.Name == "User");
                role1.IsDefault = true;
                this.CheckErrors(await this._roleManager.UpdateAsync(role1));
                if (input.AdminPassword.IsNullOrEmpty())
                {
                    input.AdminPassword = User.CreateRandomPassword();
                }
                User shouldChangePasswordOnNextLogin = User.CreateTenantAdminUser(tenant1.Id, input.AdminEmailAddress, input.AdminPassword);
                shouldChangePasswordOnNextLogin.ShouldChangePasswordOnNextLogin = input.ShouldChangePasswordOnNextLogin;
                shouldChangePasswordOnNextLogin.IsActive = input.IsActive;
                this.CheckErrors(await this.UserManager.CreateAsync(shouldChangePasswordOnNextLogin));
                await this.CurrentUnitOfWork.SaveChangesAsync();

                IdentityResult roleAsync = await this.UserManager.AddToRoleAsync(shouldChangePasswordOnNextLogin.Id, role.Name);

                this.CheckErrors(roleAsync);
                if (input.SendActivationEmail)
                {
                    shouldChangePasswordOnNextLogin.SetNewEmailConfirmationCode();
                    await this._userEmailer.SendEmailActivationLinkAsync(shouldChangePasswordOnNextLogin, input.AdminPassword);
                }
                await this.CurrentUnitOfWork.SaveChangesAsync();

                await this._demoDataBuilder.BuildForAsync(tenant1);

                role = null;
                shouldChangePasswordOnNextLogin = null;
            }
        }
Example #11
0
        [AbpAuthorize("CanEditUsers")] //An example of permission checking
        public async Task EditUser(EditUserInput input)
        {
            if (AbpSession.MultiTenancySide == MultiTenancySides.Host)
            {
                CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, input.TenantId);
                var user = _userRepository.Get(input.Id);
                Mapper.CreateMap <EditUserInput, User>();
                input.MapTo <EditUserInput, User>(user);

                await _userRepository.UpdateAsync(user);
            }
        }
Example #12
0
        public async Task BuildForAsync(Tenant tenant)
        {
            if (!IsInDemoMode)
            {
                return;
            }

            using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id))
            {
                await BuildForInternalAsync(tenant);

                await CurrentUnitOfWork.SaveChangesAsync();
            }
        }
Example #13
0
        public async Task <PagedResultOutput <DoorDto> > GetDoors(GetDoorsInput input)
        {
            using (CurrentUnitOfWork.EnableFilter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name))
            {
                using (CurrentUnitOfWork.SetFilterParameter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name, AbpZeroTemplateConsts.AdminCommunityFilterClass.ParameterName, await GetAdminCommunityIdList()))
                {
                    var query = _manager.FindDoorList(input.Sorting);

                    if (input.CommunityId.HasValue)
                    {
                        query = query.Where(d => d.CommunityId == input.CommunityId.Value);
                    }

                    if (input.HomeOwerId.HasValue)
                    {
                        var homeOwer = await _homeOwerManager.HomeOwerRepository.FirstOrDefaultAsync(input.HomeOwerId.Value);

                        var ds   = homeOwer.Doors.ToList();
                        var dIds = new List <long>();
                        ds.ForEach(d =>
                        {
                            dIds.Add(d.Id);
                        });

                        query = from d in query
                                where dIds.Contains(d.Id)
                                select d;
                    }

                    var totalCount = await query.CountAsync();

                    var items = await query.OrderByDescending(d => d.CreationTime).PageBy(input).ToListAsync();

                    return(new PagedResultOutput <DoorDto>(
                               totalCount,
                               items.Select(
                                   item =>
                    {
                        var dto = item.MapTo <DoorDto>();
                        return dto;
                    }
                                   ).ToList()
                               ));
                }
            }
        }
Example #14
0
        public async Task CreateTenantAsync(CreateTenantInput input)
        {
            var tenant = input.Tenant.MapTo <Tenant>();

            if (!tenant.EditionId.HasValue)
            {
                var defaultEdition = await _editionManager.FindByNameAsync(EditionManager.DefaultEditionName);

                if (defaultEdition != null)
                {
                    tenant.EditionId = defaultEdition.Id;
                }
            }

            //添加租户
            CheckErrors(await TenantManager.CreateAsync(tenant));
            CurrentUnitOfWork.SaveChanges();
            using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id))
            {
                //添加租户静态角色(管理员角色 普通用户角色)
                CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));
                await CurrentUnitOfWork.SaveChangesAsync();

                //把租户的部分权限赋予  管理员角色
                var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin);
                await _roleManager.GrantAllAdminPermissionsAsync(adminRole);

                //把租户的部分权限赋予 普通用户角色
                var userRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.User);
                //设置新添加客户时默认添加的角色
                userRole.IsDefault = true;
                await _roleManager.GrantAllUserPermissionsAsync(userRole);

                //管理员账户
                var adminUser = User.CreateTenantAdminUser(tenant.Id, input.Tenant.TenancyName, input.Tenant.EmailAddress, SpartanConsts.DefaultPassword);
                CheckErrors(await UserManager.CreateAsync(adminUser));
                await CurrentUnitOfWork.SaveChangesAsync();

                //给管理员赋予管理员角色
                CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
                await CurrentUnitOfWork.SaveChangesAsync();
            }
        }
Example #15
0
        [AbpAuthorize("CanDeleteUsers")] //An example of permission checking
        public async Task DeleteUser(GetUserInput input)
        {
            using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
            {
                var user =
                    _userRepository
                    .GetAll()
                    .Include(q => q.CreatorUser)
                    .FirstOrDefault(q => q.Id == input.Id);

                if (user == null)
                {
                    throw new UserFriendlyException("There is no such a user. Maybe it's deleted.");
                }
                CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, user.TenantId);
                //await _userRepository.DeleteAsync(input.Id);
                await _userManager.DeleteAsync(user);
            }
        }
Example #16
0
        public async Task CreateTenant(CreateTenantDto input)
        {
            var tenant = new TenantEntity(input.TenancyName, input.DisplayName)
            {
                IsActive = input.IsActive
            };

            if (await _repository.FirstOrDefaultAsync(x => x.TenancyName == tenant.TenancyName) != null)
            {
                throw new UserFriendlyException(string.Format(L("TenancyNameIsAlreadyTaken"), tenant.TenancyName));
            }

            await _repository.InsertAsync(tenant);


            await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id.

            //We are working entities of new tenant, so changing tenant filter
            CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id);
        }
        public async Task <PagedResultOutput <GetDealRecordListDto> > GetDealRecordListPagedAsync(GetDealRecordListPagedInput input)
        {
            if (input.TenantId.HasValue)
            {
                CurrentUnitOfWork.EnableFilter(AbpDataFilters.MustHaveTenant);
                CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MustHaveTenant, AbpDataFilters.Parameters.TenantId, input.TenantId);
            }

            var query = _dealRecordRepository.GetAll()
                        .Include(p => p.Tenant)
                        .WhereIf(!input.SearchText.IsNullOrEmpty(), p => p.Name.Contains(input.SearchText) || p.No.Contains(input.SearchText) || p.OutNo.Contains(input.SearchText))
                        .WhereIf(input.Type.HasValue, p => p.Type == input.Type.Value)
                        .WhereIfDynamic(input.StartTime.HasValue, input.SearchTime + ">", input.StartTime)
                        .WhereIfDynamic(input.EndTime.HasValue, input.SearchTime + "<", input.EndTime);
            var count = await query.CountAsync();

            var list = await query.OrderBy(input).PageBy(input).ToListAsync();

            return(new PagedResultOutput <GetDealRecordListDto>(count, list.MapTo <List <GetDealRecordListDto> >()));
        }
        public override void Execute(SendPrivateEmailJobArgs args)
        {
            //if (RandomHelper.GetRandom(0, 100) <= 50)
            //{
            //    throw new Exception("random test exception");
            //}

            using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, args.TargetTenantId))
            {
                var user = _userRepository.FirstOrDefault(args.TargetUserId);
                if (user == null)
                {
                    Logger.WarnFormat("Unknown userId: {0}. Can not execute job!", args.TargetUserId);
                    return;
                }

                //Here, we should actually send the email! We can inject and use IEmailSender for example.
                Logger.Info("Sending email to " + user.EmailAddress + " in background job -> " + args.Subject);
                Logger.Info(args.Body);
            }
        }
Example #19
0
        /// <summary>
        /// The create tenant.
        /// </summary>
        /// <param name="input">
        /// The input.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task CreateTenant(CreateTenantInput input)
        {
            //Create tenant
            var tenant         = new Tenant(input.TenancyName, input.Name);
            var defaultEdition = await _editionManager.FindByNameAsync(EditionManager.DefaultEditionName);

            if (defaultEdition != null)
            {
                tenant.EditionId = defaultEdition.Id;
            }

            await TenantManager.CreateAsync(tenant);

            await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id.

            //We are working entities of new tenant, so changing tenant filter
            using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id))
            {
                //Create static roles for new tenant
                CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));

                await CurrentUnitOfWork.SaveChangesAsync(); //To get static role ids

                //grant all permissions to admin role
                var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin);
                await _roleManager.GrantAllPermissionsAsync(adminRole);

                //Create admin user for the tenant
                var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, User.DefaultPassword);
                CheckErrors(await UserManager.CreateAsync(adminUser));
                await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id

                //Assign admin user to role!
                CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
                await CurrentUnitOfWork.SaveChangesAsync();
            }
        }
Example #20
0
        /// <summary>
        /// 查询业主
        /// ===============================
        /// 1. 查询条件:CommunityId, CommunityName, BuildingId, BuildingName, HomeOwerName, FlatNo, UserGroup, Status
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <PagedResultOutput <HomeOwerDto> > GetHomeOwers(GetHomeOwersInput input)
        {
            using (CurrentUnitOfWork.EnableFilter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name))
            {
                using (CurrentUnitOfWork.SetFilterParameter(AbpZeroTemplateConsts.AdminCommunityFilterClass.Name, AbpZeroTemplateConsts.AdminCommunityFilterClass.ParameterName, await GetAdminCommunityIdList()))
                {
                    // var query = _manager.FindHomeOwerList(input.Sorting);

                    var query = from h in _manager.HomeOwerRepository.GetAll()
                                from f in h.FlatNumbers.DefaultIfEmpty()
                                where h.IsLock == false && h.CommunityId == input.CommunityId
                                select new
                    {
                        h.Id,
                        h.CommunityName,
                        h.CommunityId,
                        f.Building.BuildingName,
                        BuildingId = f.BuildingId,
                        FlatNoId   = f.Id,
                        f.FlatNo,
                        HomeOwerName = h.Name,
                        h.Forename,
                        h.Surname,
                        h.Status,
                        h.Phone,
                        h.Email,
                        h.Title,
                        h.CreationTime,
                        h.UserGroup,
                        AccessStatus    = h.Status == EHomeOwerStatusType.Done ? "Active" : "N/A",
                        CreationTimeStr = h.CreationTime.ToString()
                    };


                    //业主状态
                    if (input.Status.HasValue)
                    {
                        query = query.Where(h => h.Status == input.Status.Value);
                    }
                    //单元楼
                    if (input.BuildingId.HasValue)
                    {
                        query = query.Where(h => h.BuildingId == input.BuildingId.Value);
                    }
                    //小区,单元楼,门牌号,业主名称
                    if (!string.IsNullOrEmpty(input.Keywords))
                    {
                        query = query.Where(h =>
                                            h.CommunityName.Contains(input.Keywords) ||
                                            h.Forename.Contains(input.Keywords) ||
                                            h.Surname.Contains(input.Keywords) ||
                                            h.BuildingName.Contains(input.Keywords) ||
                                            h.FlatNo.Contains(input.Keywords));
                    }
                    //业主类型
                    if (!string.IsNullOrEmpty(input.UserGroup))
                    {
                        query = query.Where(h => h.UserGroup.ToString() == input.UserGroup);
                    }

                    var totalCount = await query.CountAsync();

                    var items = await query.OrderByDescending(h => h.CreationTime).PageBy(input).ToListAsync();

                    return(new PagedResultOutput <HomeOwerDto>(
                               totalCount,
                               items.Select(
                                   item =>
                    {
                        return Mapper.DynamicMap <HomeOwerDto>(item);
                        //var dto = item.MapTo<HomeOwerDto>();
                        //return dto;
                    }
                                   ).ToList()
                               ));
                }
            }
        }
Example #21
0
        public async Task CreateTenant(CreateTenantInput input)
        {
            int  newTenantId;
            long newAdminId;

            using (var uow = UnitOfWorkManager.Begin())
            {
                //Create tenant
                var tenant = new Tenant(input.TenancyName, input.Name)
                {
                    IsActive = input.IsActive, EditionId = input.EditionId
                };
                CheckErrors(await TenantManager.CreateAsync(tenant));
                await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id.

                //We are working entities of new tenant, so changing tenant filter
                using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id))
                {
                    //Create static roles for new tenant
                    CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));
                    await CurrentUnitOfWork.SaveChangesAsync(); //To get static role ids

                    //grant all permissions to admin role
                    var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin);
                    await _roleManager.GrantAllPermissionsAsync(adminRole);

                    //User role should be default
                    var userRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.User);
                    userRole.IsDefault = true;
                    CheckErrors(await _roleManager.UpdateAsync(userRole));

                    //Create admin user for the tenant
                    if (input.AdminPassword.IsNullOrEmpty())
                    {
                        input.AdminPassword = User.CreateRandomPassword();
                    }

                    var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, input.AdminPassword);
                    adminUser.ShouldChangePasswordOnNextLogin = input.ShouldChangePasswordOnNextLogin;
                    adminUser.IsActive = input.IsActive;

                    CheckErrors(await UserManager.CreateAsync(adminUser));
                    await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id

                    //Assign admin user to admin role!
                    CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));

                    //Notifications
                    await _appNotifier.WelcomeToTheApplicationAsync(adminUser);

                    //Send activation email
                    if (input.SendActivationEmail)
                    {
                        adminUser.SetNewEmailConfirmationCode();
                        await _userEmailer.SendEmailActivationLinkAsync(adminUser, input.AdminPassword);
                    }

                    await CurrentUnitOfWork.SaveChangesAsync();

                    await _demoDataBuilder.BuildForAsync(tenant);

                    newTenantId = tenant.Id;
                    newAdminId  = adminUser.Id;
                }

                await uow.CompleteAsync();
            }

            //Used a second UOW since UOW above sets some permissions and _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync needs these permissions to be saved.
            using (var uow = UnitOfWorkManager.Begin())
            {
                using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, newTenantId))
                {
                    await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(newTenantId, newAdminId);

                    await CurrentUnitOfWork.SaveChangesAsync();
                }

                await uow.CompleteAsync();
            }
        }
Example #22
0
        public virtual async Task <ActionResult> Register(TenantRegistrationViewModel model)
        {
            try
            {
                CheckTenantRegistrationIsEnabled();

                CheckModelState();

                if (UseCaptchaOnRegistration())
                {
                    var recaptchaHelper = this.GetRecaptchaVerificationHelper();
                    if (recaptchaHelper.Response.IsNullOrEmpty())
                    {
                        throw new UserFriendlyException(L("CaptchaCanNotBeEmpty"));
                    }

                    if (recaptchaHelper.VerifyRecaptchaResponse() != RecaptchaVerificationResult.Success)
                    {
                        throw new UserFriendlyException(L("IncorrectCaptchaAnswer"));
                    }
                }

                //Getting host-specific settings
                var isNewRegisteredTenantActiveByDefault = await SettingManager.GetSettingValueForApplicationAsync <bool>(AppSettings.TenantManagement.IsNewRegisteredTenantActiveByDefault);

                var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueForApplicationAsync <bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin);

                var defaultEditionIdValue = await SettingManager.GetSettingValueForApplicationAsync(AppSettings.TenantManagement.DefaultEdition);

                int?defaultEditionId = null;

                if (!string.IsNullOrEmpty(defaultEditionIdValue) && (await _editionManager.FindByIdAsync(Convert.ToInt32(defaultEditionIdValue)) != null))
                {
                    defaultEditionId = Convert.ToInt32(defaultEditionIdValue);
                }

                var tenantId = await _tenantManager.CreateWithAdminUserAsync(
                    model.TenancyName,
                    model.Name,
                    model.AdminPassword,
                    model.AdminEmailAddress,
                    isNewRegisteredTenantActiveByDefault,
                    defaultEditionId,
                    false,
                    isEmailConfirmationRequiredForLogin);

                ViewBag.UseCaptcha = UseCaptchaOnRegistration();

                var tenant = await _tenantManager.GetByIdAsync(tenantId);

                await _appNotifier.NewTenantRegisteredAsync(tenant);

                CurrentUnitOfWork.EnableFilter(AbpDataFilters.MayHaveTenant);
                CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id);

                var user = await _userManager.FindByNameAsync(Authorization.Users.User.AdminUserName);

                //Directly login if possible
                if (user.IsActive && (user.IsEmailConfirmed || !isEmailConfirmationRequiredForLogin))
                {
                    var loginResult = await GetLoginResultAsync(user.UserName, model.AdminPassword, tenant.TenancyName);

                    if (loginResult.Result == AbpLoginResultType.Success)
                    {
                        await SignInAsync(loginResult.User, loginResult.Identity);

                        return(Redirect(Url.Action("Index", "Application")));
                    }

                    Logger.Warn("New registered user could not be login. This should not be normally. login result: " + loginResult.Result);
                }

                return(View("RegisterResult", new TenantRegisterResultViewModel
                {
                    TenancyName = model.TenancyName,
                    Name = model.Name,
                    UserName = Authorization.Users.User.AdminUserName,
                    EmailAddress = model.AdminEmailAddress,
                    IsActive = isNewRegisteredTenantActiveByDefault,
                    IsEmailConfirmationRequired = isEmailConfirmationRequiredForLogin
                }));
            }
            catch (UserFriendlyException ex)
            {
                ViewBag.UseCaptcha   = UseCaptchaOnRegistration();
                ViewBag.ErrorMessage = ex.Message;

                return(View("Index", model));
            }
        }
Example #23
0
 public void UseFamilyDataFilter()
 {
     CurrentUnitOfWork.SetFilterParameter(ChimaDataFilter.FamillyDataFilter, ChimaDataFilter.FamillyPara, Family);
     EnableFamilyDataFilter();
 }