예제 #1
0
        /// <summary>
        /// 是否具有编辑附件的权限
        /// </summary>
        /// <returns></returns>
        public bool Attachment_Edit(Attachment attachment)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantType tenantType = tenantTypeService.Get(attachment.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsOwner(currentUser, attachment.UserId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, attachment.TenantTypeId, attachment.OwnerId))
            {
                return(true);
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 是否具有编辑标签的权限
        /// </summary>
        /// <returns></returns>
        public bool Tag_Edit(Tag tag)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(tag.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, tag.TenantTypeId, tag.OwnerId))
            {
                return(true);
            }
            return(false);
        }
예제 #3
0
        /// <summary>
        /// 是否具有管理推荐内容的权限
        /// </summary>
        /// <returns></returns>
        public bool RecommendItem_Manage(string tenantTypeId)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            TenantType tenantType = tenantTypeService.Get(tenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }

            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }

            if (currentUser.IsContentAdministrator())
            {
                return(true);
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        /// 重建缩略图
        /// </summary>
        /// <returns></returns>
        public ActionResult RebuildingThumbnails()
        {
            IEnumerable <TenantAttachmentSettings> tenantAttachmentSettings = TenantAttachmentSettings.GetAll();

            ViewData["TenantAttachmentSettings"] = tenantAttachmentSettings;
            ViewData["TenantLogoSettings"]       = TenantLogoSettings.GetAll();

            IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>();
            string         rootPath      = WebUtility.GetPhysicalFilePath("~");
            string         uploadsPath   = storeProvider.StoreRootPath;

            if (storeProvider.StoreRootPath.StartsWith(rootPath))
            {
                uploadsPath = uploadsPath.Replace(rootPath, "");
            }
            ViewData["uploadsPath"] = uploadsPath;
            Dictionary <string, string> ApplicationName = new Dictionary <string, string>();

            TenantTypeService        tenantTypeService = new TenantTypeService();
            IEnumerable <TenantType> tenantTypes       = tenantTypeService.Gets(null, null);

            foreach (var item in tenantTypes)
            {
                TenantType type = tenantTypeService.Get(item.TenantTypeId);
                ApplicationName[item.TenantTypeId] = type != null ? type.Name : item.Name;
            }

            ViewData["ApplicationName"] = ApplicationName;

            return(View());
        }
예제 #5
0
        private async Task UpdateAllTenantPermission(int tenantId, TenantType tenantType)
        {
            List <Role> rolesAdminHost = new List <Role>();

            if (tenantType == TenantType.Cruise)
            {
                rolesAdminHost = TenantManager.GetCurrentUserRoles().Where(x => x.Name == StaticRoleNames.Host.Cruise).ToList();
            }
            else if (tenantType == TenantType.Travel)
            {
                rolesAdminHost = TenantManager.GetCurrentUserRoles().Where(x => x.Name == StaticRoleNames.Host.Travel).ToList();
            }
            else if (tenantType == TenantType.Ship)
            {
                rolesAdminHost = TenantManager.GetCurrentUserRoles().Where(x => x.Name == StaticRoleNames.Host.Ship).ToList();
            }
            var grantedPHost = await TenantManager.GetGrantedPermssionByRole(rolesAdminHost.FirstOrDefault(), null);

            using (UnitOfWorkManager.Current.SetTenantId(tenantId))
            {
                var rolesAdmin = TenantManager.GetCurrentUserRoles().ToList();
                foreach (var item2 in rolesAdmin)
                {
                    var grantedPermissions = (await TenantManager.GetGrantedPermssionByRole(item2, tenantId)).Where(x => x.MultiTenancySides != Abp.MultiTenancy.MultiTenancySides.Host).ToArray();

                    var d = grantedPermissions.Where(x => grantedPHost.Any(z => z.Name == x.Name)).Select(x => x.Name).ToList();

                    await UpdateGrantedPermissionsAsync(item2, d);
                }
            }
            CurrentUnitOfWork.SaveChanges();
        }
예제 #6
0
        /// <summary>
        /// 是否具有编辑友情链接的权限
        /// </summary>
        /// <param name="link">链接实体</param>
        /// <returns></returns>
        public bool Link_Edit(LinkEntity link)
        {
            IUser      currentUser = UserContext.CurrentUser;
            TenantType tenantType  = tenantTypeService.Get(TenantTypeIds.Instance().Link());

            if (currentUser == null)
            {
                return(false);
            }
            if (AuthorizationService.IsSuperAdministrator(currentUser))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, tenantType.TenantTypeId, link.OwnerId))
            {
                return(true);
            }
            if (link.OwnerType == OwnerTypes.Instance().User())
            {
                if (AuthorizationService.IsOwner(currentUser, link.OwnerId))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #7
0
        /// <summary>
        /// 是否具有删除分类的权限
        /// </summary>
        /// <returns></returns>
        public bool Category_Delete(Category category)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(category.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, category.TenantTypeId, category.OwnerId))
            {
                return(true);
            }
            return(false);
        }
예제 #8
0
        public async Task <IActionResult> Edit(int id, [Bind("TenantTypeId,Name,Description,Status,CreationDate,ChangeDate,CreationUser,ChangeUser")] TenantType tenantType)
        {
            if (id != tenantType.TenantTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tenantType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TenantTypeExists(tenantType.TenantTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tenantType));
        }
 /// <summary>
 /// Validates if this test supports the current target tenant.
 /// Skips the current test if the target tenant is not supported.
 /// </summary>
 public static void ValidateIfTestSupportTargetTenant(TenantType supportedTenantTypes)
 {
     if ((supportedTenantTypes & TestBase.CurrentTenantType) == 0)
     {
         Assert.Inconclusive("This test is skipped because the target test tenant is {0}.", TestBase.CurrentTenantType);
     }
 }
 public BannerSliderAppService(
     IManagementUnitOfWork unitOfWork,
     IFileHelper fileHelper,
     TenantType tenantType = TenantType.WebService
     ) : base(unitOfWork, tenantType)
 {
     _fileHelper = fileHelper;
 }
예제 #11
0
 public TariffCategoryAppService(
     IManagementUnitOfWork unitOfWork,
     IFileHelper fileHelper,
     TenantType tenantType = TenantType.WebService
     ) : base(unitOfWork, tenantType)
 {
     _fileHelper = fileHelper;
 }
예제 #12
0
        public async Task <IActionResult> Create([Bind("TenantTypeId,Name,Description,Status,CreationDate,ChangeDate,CreationUser,ChangeUser")] TenantType tenantType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tenantType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tenantType));
        }
예제 #13
0
        /// <summary>
        /// 推荐积分处理
        /// </summary>
        /// <param name="sender">推荐实体</param>
        /// <param name="eventArgs">事件参数</param>
        void RecommendPointModule_After(RecommendItem sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().Create())
            {
                return;
            }
            string            pointItemKey      = string.Empty;
            PointService      pointService      = new PointService();
            string            description       = string.Empty;
            TenantTypeService tenantTypeService = new TenantTypeService();

            var urlGetter = RecommendUrlGetterFactory.Get(sender.TenantTypeId);

            NoticeService noticeService = new NoticeService();
            Notice        notice        = Notice.New();

            notice.TypeId = NoticeTypeIds.Instance().Hint();

            //notice.TemplateName = "FollowUser";
            notice.UserId             = sender.UserId;
            notice.LeadingActorUserId = sender.ReferrerId;
            notice.LeadingActor       = sender.ReferrerName;
            notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.ReferrerId));
            notice.RelativeObjectId   = sender.UserId;
            notice.RelativeObjectName = sender.ItemName;
            notice.RelativeObjectUrl  = sender.DetailUrl;

            if (sender.TenantTypeId == TenantTypeIds.Instance().User())
            {
                pointItemKey        = PointItemKeys.Instance().RecommendUser();
                description         = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendUser"));
                notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommendedUser();
            }
            else
            {
                pointItemKey = PointItemKeys.Instance().RecommendContent();
                TenantType tenantType = tenantTypeService.Get(sender.TenantTypeId);
                if (tenantType == null)
                {
                    return;
                }
                description         = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendContent"), tenantType.Name, sender.ItemName);
                notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommended();
            }

            noticeService.Create(notice);
            pointService.GenerateByRole(sender.UserId, pointItemKey, description);
        }
예제 #14
0
        /// <summary>
        /// 是否有权限查看评论
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public bool Comment_Show(Comment comment)
        {
            if (!comment.IsPrivate)
            {
                return(true);
            }
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (comment.OwnerId == currentUser.UserId && comment.ParentId == 0)
            {
                return(true);
            }

            if (comment.ToUserId != 0 && comment.ToUserId == currentUser.UserId)
            {
                return(true);
            }
            if (comment.UserId == currentUser.UserId)
            {
                return(true);
            }
            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(comment.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, comment.TenantTypeId, comment.OwnerId))
            {
                return(true);
            }
            return(false);
        }
예제 #15
0
        /// <summary>
        /// 是否具有推荐评论的权限
        /// </summary>
        /// <returns></returns>
        public bool Comment_Recommend(Comment comment)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantType tenantType = tenantTypeService.Get(comment.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            return(false);
        }
예제 #16
0
        /// <summary>
        /// 上传文件控件
        /// </summary>
        /// <param name="html"></param>
        /// <param name="name"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static MvcHtmlString Upload(this HtmlHelper html, string name, TenantType tenantType, int itemId = 0, UploadOptions options = null)
        {
            TagBuilder builder = new TagBuilder("input");
            Dictionary <string, object> data      = new Dictionary <string, object>();
            Dictionary <string, object> result    = new Dictionary <string, object>();
            Dictionary <string, object> extradata = new Dictionary <string, object>();

            extradata.Add("tenantType", tenantType);
            extradata.Add("itemId", itemId);

            result.Add("uploadExtraData", Json.Encode(extradata));
            result.Add("uploadUrl", new UrlHelper(html.ViewContext.RequestContext).Action("Upload", "Api"));
            result.Add("language", "zh");

            if (options != null)
            {
                if (!string.IsNullOrEmpty(options.AllowedFileExtensions))
                {
                    result.Add("allowedFileExtensions", options.AllowedFileExtensions);
                }

                if (options.MaxFileCount > 0)
                {
                    data.Add("multiple", true);
                    result.Add("maxFileCount", options.MaxFileCount);
                }

                if (options.MaxFileSize > 0)
                {
                    result.Add("maxFileSize", options.MaxFileSize);
                }
            }
            data.Add("type", "file");
            data.Add("data", Json.Encode(result));
            builder.MergeAttributes(data);
            builder.MergeAttribute("id", name);

            return(MvcHtmlString.Create(builder.ToString()));
        }
예제 #17
0
        /// <summary>
        /// 资讯操作日志事件处理
        /// </summary>
        private void RecommendOperationLogEventModule_After(RecommendItem sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create() ||
                eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                TenantTypeService tenantTypeService = new TenantTypeService();
                TenantType        tenantType        = tenantTypeService.Get(sender.TenantTypeId);
                if (tenantType == null)
                {
                    return;
                }

                OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo);
                entry.ApplicationId       = tenantType.ApplicationId;
                entry.Source              = tenantType.Name;
                entry.OperationType       = eventArgs.EventOperationType;
                entry.OperationObjectName = sender.ItemName;
                entry.OperationObjectId   = sender.ItemId;
                entry.Description         = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType), tenantType.Name + "推荐", entry.OperationObjectName);

                OperationLogService logService = Tunynet.DIContainer.Resolve <OperationLogService>();
                logService.Create(entry);
            }
        }
예제 #18
0
        /// <summary>
        /// 是否具有编辑标签的权限
        /// </summary>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="tenantOwnerId">租户的OwnerId</param>
        /// <returns></returns>
        public bool Category_Create(string tenantTypeId, long tenantOwnerId)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantType tenantType = tenantTypeService.Get(tenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, tenantTypeId, tenantOwnerId))
            {
                return(true);
            }
            return(false);
        }
예제 #19
0
        public ActionResult _RecommendItem(string tenantTypeId, long itemId = 0, string itemName = null, string recommendItemTypeId = null, bool showLink = false, long recommendId = 0, bool showInList = true, long userId = 0)
        {
            RecommendItem recommendItem = null;

            if (recommendId > 0)
            {
                recommendItem = recommendService.Get(recommendId);
                if (recommendItem == null)
                {
                    return(HttpNotFound());
                }
                tenantTypeId                  = recommendItem.TenantTypeId;
                itemId                        = recommendItem.ItemId;
                recommendItemTypeId           = recommendItem.TypeId;
                ViewData["RecommendTypeName"] = recommendItem.RecommendItemType.Name;
                ViewData["RecommendTypeId"]   = recommendItem.TypeId;
            }
            if (!authorizer.RecommendItem_Manage(tenantTypeId))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有管理推荐内容的权限",
                    Title = "没有权限",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }
            IEnumerable <RecommendItemType> itemTypes      = recommendService.GetRecommendTypes(tenantTypeId);
            IEnumerable <RecommendItem>     recommendItems = recommendService.Gets(itemId, tenantTypeId);

            //已修改
            RecommendItemEditModel itemEditModel = new RecommendItemEditModel();

            ViewData["recommendItems"] = recommendItems;

            //已修改
            ViewData["TypeId"] = new SelectList(itemTypes, "TypeId", "Name", recommendItemTypeId);
            if (recommendId != 0)
            {
                itemEditModel = recommendItem.AsEditModel();
                ViewData["HasFeaturedImage"] = recommendItem.RecommendItemType.HasFeaturedImage;
            }
            else
            {
                if (itemTypes != null && itemTypes.Count() > 0 && string.IsNullOrEmpty(recommendItemTypeId))
                {
                    //已修改
                    recommendItemTypeId = itemTypes.First().TypeId;
                }
                if (!string.IsNullOrEmpty(recommendItemTypeId))
                {
                    recommendItem = recommendService.Get(itemId, recommendItemTypeId);
                    RecommendItemType recommendType = recommendService.GetRecommendType(recommendItemTypeId);
                    ViewData["HasFeaturedImage"]  = recommendType.HasFeaturedImage;
                    ViewData["RecommendTypeName"] = recommendType.Name;
                    ViewData["RecommendTypeId"]   = recommendType.TypeId;
                    if (recommendItem != null && !recommendItem.IsLink)
                    {
                        ViewData["ExpiredDate"] = recommendItem.ExpiredDate;
                        itemEditModel           = recommendItem.AsEditModel();
                    }
                    else
                    {
                        RecommendItem newItem = RecommendItem.New();
                        newItem.ItemName     = itemName;
                        newItem.ItemId       = itemId;
                        newItem.TenantTypeId = tenantTypeId;
                        newItem.ExpiredDate  = DateTime.UtcNow.AddMonths(1);
                        newItem.UserId       = userId;
                        itemEditModel        = newItem.AsEditModel();
                    }
                }

                else
                {
                    StatusMessageData message           = null;
                    TenantTypeService tenantTypeService = new TenantTypeService();
                    TenantType        tenantType        = tenantTypeService.Get(tenantTypeId);

                    if (tenantType == null)
                    {
                        message = new StatusMessageData(StatusMessageType.Hint, "没有推荐类别");
                    }
                    else
                    {
                        message = new StatusMessageData(StatusMessageType.Hint, tenantType.Name + "下没有推荐类别");
                    }
                    ViewData["statusMessageData"] = message;
                }
            }
            ViewData["showLink"]   = showLink || itemEditModel.IsLink;
            ViewData["showInList"] = showInList;
            return(View(itemEditModel));
        }
예제 #20
0
 public ProductAppService(
     IManagementUnitOfWork unitOfWork,
     IFileHelper fileHelper, IProductPropertyRepository productPropertyRepository, TenantType tenantType = TenantType.WebService
     ) : base(unitOfWork, tenantType)
 {
     _fileHelper = fileHelper;
     _productPropertyRepository = productPropertyRepository;
 }
예제 #21
0
        /// <summary>
        /// 获取参数列表
        /// </summary>
        /// <param name="html"></param>
        /// <param name="name"></param>
        /// <param name="parentId">父级节点Id</param>
        /// <returns></returns>
        public static MvcHtmlString GetParameterList(this HtmlHelper html, string name, TenantType tenantType, int parentId)
        {
            TagBuilder builder = new TagBuilder("select");
            Dictionary <string, object> data      = new Dictionary <string, object>();
            Dictionary <string, object> result    = new Dictionary <string, object>();
            Dictionary <string, object> extradata = new Dictionary <string, object>();


            data.Add("data", Json.Encode(result));
            builder.MergeAttributes(data);
            builder.MergeAttribute("name", name);
            builder.MergeAttribute("id", name);

            return(MvcHtmlString.Create(builder.ToString()));
        }
예제 #22
0
 public InsightAppService(IManagementUnitOfWork unitOfWork, TenantType tenantType = TenantType.WebService) : base(unitOfWork, tenantType)
 {
 }
예제 #23
0
 public ProductCategoryAppService(IManagementUnitOfWork unitOfWork,
                                  TenantType tenantType = TenantType.WebService) : base(unitOfWork, tenantType)
 {
 }
예제 #24
0
        // This method must be thread-safe since it is called by the thread-safe OnCacheAuthorization() method.
        protected virtual bool AuthorizeCore(AuthorizationContext filterContext)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (CheckCookie)
            {
                HttpCookie adminCookie = filterContext.HttpContext.Request.Cookies["SpacebuilderAdminCookie" + currentUser.UserId];
                if (adminCookie != null)
                {
                    bool isLoginMarked = false;
                    try
                    {
                        bool.TryParse(Utility.DecryptTokenForAdminCookie(adminCookie.Value), out isLoginMarked);
                    }
                    catch { }

                    if (!isLoginMarked)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            RoleService roleService = new RoleService();

            if (RequireSystemAdministrator)
            {
                if (roleService.IsUserInRoles(currentUser.UserId, RoleNames.Instance().SuperAdministrator()))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (roleService.IsUserInRoles(currentUser.UserId, RoleNames.Instance().SuperAdministrator(), RoleNames.Instance().ContentAdministrator()))
                {
                    return(true);
                }
            }

            if (checkApplication)
            {
                //是否为管理员
                string applicationKey = GetAreaName(filterContext.RouteData);
                var    application    = DIContainer.Resolve <ApplicationService>().Get(applicationKey);
                var    authorizer     = DIContainer.Resolve <Authorizer>();
                if (application != null && authorizer.IsAdministrator(application.ApplicationId))
                {
                    return(true);
                }
                string tenantTypeId = filterContext.RequestContext.GetParameterFromRouteDataOrQueryString("tenantTypeId");
                if (!string.IsNullOrEmpty(tenantTypeId))
                {
                    TenantType tenantType = DIContainer.Resolve <TenantTypeService>().Get(tenantTypeId);
                    if (tenantType != null)
                    {
                        if (authorizer.IsAdministrator(tenantType.ApplicationId))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                return(currentUser.IsAllowEntryControlPannel());
            }
            return(false);
        }
예제 #25
0
 public SearchInControlPanelAppService(IManagementUnitOfWork unitOfWork, TenantType tenantType = TenantType.WebService) : base(unitOfWork, tenantType)
 {
 }
예제 #26
0
        public async Task <int> CreateWithAdminUserAsync(
            string tenancyName,
            string name,
            string adminPassword,
            string adminEmailAddress,
            string connectionString,
            bool isActive,
            int?editionId,
            bool shouldChangePasswordOnNextLogin,
            bool sendActivationEmail,
            DateTime?subscriptionEndDate,
            bool isInTrialPeriod,
            string emailActivationLink,
            TenantType tenantType = 0
            )
        {
            int  newTenantId;
            long newAdminId;

            await CheckEditionAsync(editionId, isInTrialPeriod);

            if (isInTrialPeriod && !subscriptionEndDate.HasValue)
            {
                throw new UserFriendlyException(LocalizationManager.GetString(CruisePMSConsts.LocalizationSourceName, "TrialWithoutEndDateErrorMessage"));
            }

            using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
            {
                //Create tenant
                var tenant = new Tenant(tenancyName, name)
                {
                    TenantType             = tenantType,
                    IsActive               = isActive,
                    EditionId              = editionId,
                    SubscriptionEndDateUtc = subscriptionEndDate?.ToUniversalTime(),
                    IsInTrialPeriod        = isInTrialPeriod,
                    ConnectionString       = connectionString.IsNullOrWhiteSpace() ? null : SimpleStringCipher.Instance.Encrypt(connectionString)
                };

                await CreateAsync(tenant);

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

                //Create tenant database
                _abpZeroDbMigrator.CreateOrMigrateForTenant(tenant);

                //We are working entities of new tenant, so changing tenant filter
                using (_unitOfWorkManager.Current.SetTenantId(tenant.Id))
                {
                    //Create static roles for new tenant
                    CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));
                    await _unitOfWorkManager.Current.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
                    var adminUser = User.CreateTenantAdminUser(tenant.Id, adminEmailAddress);
                    adminUser.ShouldChangePasswordOnNextLogin = shouldChangePasswordOnNextLogin;
                    adminUser.IsActive = true;

                    if (adminPassword.IsNullOrEmpty())
                    {
                        adminPassword = await _userManager.CreateRandomPassword();
                    }
                    else
                    {
                        await _userManager.InitializeOptionsAsync(AbpSession.TenantId);

                        foreach (var validator in _userManager.PasswordValidators)
                        {
                            CheckErrors(await validator.ValidateAsync(_userManager, adminUser, adminPassword));
                        }
                    }

                    adminUser.Password = _passwordHasher.HashPassword(adminUser, adminPassword);

                    CheckErrors(await _userManager.CreateAsync(adminUser));
                    await _unitOfWorkManager.Current.SaveChangesAsync(); //To get admin user's id

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

                    //Notifications
                    await _appNotifier.WelcomeToTheApplicationAsync(adminUser);

                    //Send activation email
                    if (sendActivationEmail)
                    {
                        adminUser.SetNewEmailConfirmationCode();
                        await _userEmailer.SendEmailActivationLinkAsync(adminUser, emailActivationLink, adminPassword);
                    }

                    await _unitOfWorkManager.Current.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(TransactionScopeOption.RequiresNew))
            {
                using (_unitOfWorkManager.Current.SetTenantId(newTenantId))
                {
                    await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(new UserIdentifier(newTenantId, newAdminId));

                    await _unitOfWorkManager.Current.SaveChangesAsync();

                    await uow.CompleteAsync();
                }
            }

            return(newTenantId);
        }
예제 #27
0
 public ApplicationSettingsAppService(IManagementUnitOfWork unitOfWork, TenantType tenantType = TenantType.WebService) : base(unitOfWork, tenantType)
 {
 }
예제 #28
0
 public ManagementSystemService(IManagementUnitOfWork unitOfWork, TenantType tenantType = TenantType.WebService)
 {
     UnitOfWork = unitOfWork;
 }
예제 #29
0
 public SearchInWebsiteAppService(IManagementUnitOfWork unitOfWork,
                                  TenantType tenantType = TenantType.WebService) : base(unitOfWork, tenantType)
 {
 }