Exemplo n.º 1
0
        public virtual ActionResult CreateOrUpdate(RoleModel roleModel)//List<ControllerDescription> controllers,
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { IsError = true, Message = "ورودی نامعتبر!" }));
            }

            var userAuthenticationType = (AuthenticationType)Enum.Parse(typeof(AuthenticationType), User.AuthenType(), true);

            if (roleModel.Id == null || roleModel.Id == 0)
            {
                switch (userAuthenticationType)
                {
                case AuthenticationType.AdminCentral:
                    roleModel.CentralOrganizationId = Convert.ToInt64(User.LevelId());
                    break;

                case AuthenticationType.AdminBranch:
                    roleModel.BranchProvinceId = Convert.ToInt64(User.LevelId());
                    break;

                default:
                    roleModel.UniversityId = Convert.ToInt64(User.LevelId());
                    break;
                }
                roleModel.RoleType = RoleType.None;
            }
            var result = _roleManagementService.AddOrUpdateRole(roleModel, roleModel.Id != null && roleModel.Id > 0 ? StateOperation.ویرایش : StateOperation.درج);

            return(Json(new { IsError = !result.Item1, Message = result.Item2 }));
        }
        private void ImportPlatformEntriesInternal(Package package, PlatformExportManifest manifest, Action <ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo();

            var platformEntriesPart = package.GetPart(_platformEntriesPartUri);

            if (platformEntriesPart != null)
            {
                PlatformExportEntries platformEntries;
                using (var stream = platformEntriesPart.GetStream())
                {
                    platformEntries = stream.DeserializeJson <PlatformExportEntries>(GetJsonSerializer());
                }

                //Import security objects
                if (manifest.HandleSecurity)
                {
                    progressInfo.Description = String.Format("Import {0} users with roles...", platformEntries.Users.Count());
                    progressCallback(progressInfo);

                    //First need import roles
                    foreach (var role in platformEntries.Roles)
                    {
                        _roleManagementService.AddOrUpdateRole(role);
                    }
                    //Next create or update users
                    foreach (var user in platformEntries.Users)
                    {
                        if (_securityService.FindByIdAsync(user.Id, UserDetails.Reduced).Result != null)
                        {
                            var dummy = _securityService.UpdateAsync(user).Result;
                        }
                        else
                        {
                            var dummy = _securityService.CreateAsync(user).Result;
                        }
                    }
                }

                //Import modules settings
                if (manifest.HandleSettings)
                {
                    //Import dynamic properties
                    _dynamicPropertyService.SaveProperties(platformEntries.DynamicProperties.ToArray());
                    foreach (var propDicGroup in platformEntries.DynamicPropertyDictionaryItems.GroupBy(x => x.PropertyId))
                    {
                        _dynamicPropertyService.SaveDictionaryItems(propDicGroup.Key, propDicGroup.ToArray());
                    }

                    foreach (var module in manifest.Modules)
                    {
                        _settingsManager.SaveSettings(platformEntries.Settings.Where(x => x.ModuleId == module.Id).ToArray());
                    }
                }
            }
        }
        private void InitializeRole(IRoleManagementService roleManagementService, string name, string description, IEnumerable <Permission> permissions)
        {
            // Corporate administrator
            var role = roleManagementService.SearchRoles(new RoleSearchRequest {
                Keyword = name
            }).Roles.FirstOrDefault() ?? new Role {
                Name = name, Description = description
            };

            // Add security:call_api permissions, because B2B users is customers (and have no access to admin site), but must have access to platform api
            var callApiPermission = PredefinedPermissions.Permissions.Where(p => p.Id == PredefinedPermissions.SecurityCallApi).ToArray();

            // Corporate administrator: security:call_api + permissions
            role.Permissions = callApiPermission.Concat(permissions ?? Enumerable.Empty <Permission>()).ToArray();

            roleManagementService.AddOrUpdateRole(role);
        }
Exemplo n.º 4
0
        private void ImportPlatformEntriesInternal(Package package, PlatformExportManifest manifest, Action <ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo();

            var platformEntriesPart = package.GetPart(_platformEntriesPartUri);

            if (platformEntriesPart != null)
            {
                PlatformExportEntries platformEntries;
                using (var stream = platformEntriesPart.GetStream())
                {
                    platformEntries = stream.DeserializeJson <PlatformExportEntries>(GetJsonSerializer());
                }

                //Import security objects
                if (manifest.HandleSecurity)
                {
                    progressInfo.Description = $"Import {platformEntries.Users.Count()} users with roles...";
                    progressCallback(progressInfo);

                    //First need import roles
                    foreach (var role in platformEntries.Roles)
                    {
                        _roleManagementService.AddOrUpdateRole(role);
                    }
                    //Next create or update users
                    foreach (var user in platformEntries.Users)
                    {
                        if (_securityService.FindByIdAsync(user.Id, UserDetails.Reduced).Result != null)
                        {
                            var dummy = _securityService.UpdateAsync(user).Result;
                        }
                        else
                        {
                            var dummy = _securityService.CreateAsync(user).Result;
                        }
                    }
                }

                //Import modules settings
                if (manifest.HandleSettings)
                {
                    //Import dynamic properties
                    _dynamicPropertyService.SaveProperties(platformEntries.DynamicProperties.ToArray());
                    foreach (var propDicGroup in platformEntries.DynamicPropertyDictionaryItems.GroupBy(x => x.PropertyId))
                    {
                        _dynamicPropertyService.SaveDictionaryItems(propDicGroup.Key, propDicGroup.ToArray());
                    }

                    foreach (var module in manifest.Modules)
                    {
                        _settingsManager.SaveSettings(platformEntries.Settings.Where(x => x.ModuleId == module.Id).ToArray());
                    }
                }

                //Import notification templates
                if (!platformEntries.NotificationTemplates.IsNullOrEmpty())
                {
                    _notificationTemplateService.Update(platformEntries.NotificationTemplates.ToArray());
                }

                //Import asset entires
                if (!platformEntries.AssetEntries.IsNullOrEmpty())
                {
                    var       totalAssetsEntriesCount = platformEntries.AssetEntries.Count();
                    const int batchSize = 50;
                    for (var i = 0; i <= totalAssetsEntriesCount; i += batchSize)
                    {
                        progressInfo.Description = $"Asset: {Math.Min(totalAssetsEntriesCount, i + batchSize) } of {totalAssetsEntriesCount} asset entries have been imported...";
                        progressCallback(progressInfo);
                        _assetEntryService.SaveChanges(platformEntries.AssetEntries.Skip(i).Take(batchSize));
                    }
                }
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult UpdateRole(Role role)
        {
            var result = _roleService.AddOrUpdateRole(role);

            return(Ok(result));
        }