当前位置: 首页>>代码示例>>C#>>正文


C# Role.Save方法代码示例

本文整理汇总了C#中Role.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Role.Save方法的具体用法?C# Role.Save怎么用?C# Role.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Role的用法示例。


在下文中一共展示了Role.Save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplicationStartup

        protected static void ApplicationStartup(object sender, ActiveEventArgs e)
        {
            // Checking to see if our default roles exists, and if not we create them...
            if (ActiveType<Role>.Count == 0)
            {
                // Creating default roles
                Role admin = new Role {Name = "Administrator"};
                admin.Save();

                Role user = new Role {Name = "User"};
                user.Save();

                Role view = new Role {Name = "View"};
                view.Save();

                Role blocked = new Role {Name = "Blocked"};
                blocked.Save();

                Role noRole = new Role {Name = "Everyone"};
                noRole.Save();
            }

            // Settings default language values for module...
            Language.Instance.SetDefaultValue("ButtonRoles", "Roles");
            Language.Instance.SetDefaultValue("ButtonViewAllRoles", "View All Roles");
            Language.Instance.SetDefaultValue("ButtonCreateRole", "Create Role");
            Language.Instance.SetDefaultValue("ButtonAccessControl", "Access Control");
        }
开发者ID:greaterwinner,项目名称:ra-brix,代码行数:28,代码来源:RoleController.cs

示例2: Create

 public ActionResult Create(Role model)
 {
     if (model == null)
         throw new ArgumentNullException("请检查输入!!");
     model.Save();
     TempData["HintMessage"] = new HintMessage { Content = string.Format("角色({0})添加成功", model.Name) };
     return RedirectToAction("Index");
 }
开发者ID:dalinhuang,项目名称:cq-police-photo-gallery,代码行数:8,代码来源:RoleController.cs

示例3: UpdateDatabaseAfterUpdateSchema

        public override void UpdateDatabaseAfterUpdateSchema()
        {
            base.UpdateDatabaseAfterUpdateSchema();
            Employee userAdmin = Session.FindObject<Employee>(new BinaryOperator("UserName", "Admin"));
            if (new XPCollection<Company>(Session).Count == 0)
            {
                using (Role administratorRole = new Role(Session) { Name = "Administrator role" })
                {
                    administratorRole.AddPermission(new EditModelPermission());
                    administratorRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.AllAccess));
                    administratorRole.Save();
                    using (Role userRole = new Role(Session) { Name = "User" })
                    {
                        userRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.Navigate));
                        userRole.AddPermission(new ObjectAccessPermission(typeof(object), ObjectAccess.Read));
                        userRole.Save();
                    }
                    userAdmin = new Employee(Session);
                    userAdmin.UserName = "Admin";
                    userAdmin.FirstName = "Admin";
                    userAdmin.LastName = "";
                    userAdmin.Roles.Add(administratorRole);
                    userAdmin.Save();
                    using (Branch branch1 = new Branch(Session) { Acronym = "WTPR", Branchname = "Roadmax Head Office" })
                    {
                        using (Company company1 = new Company(Session) { CompanyName = "Roadmax Marketing Inc.", Acronym = "WTPR" })
                        {
                            company1.Employees.Add(userAdmin);
                            company1.Branches.Add(branch1);
                            company1.Save();
                            ImportData(company1);
                        }
                    }
                }

                using (Currency curr = new Currency(Session) { CurrencyName = "Peso", CurrencyRate = 1 })
                {
                    curr.Save();
                }

                using (VatCategory vat = new VatCategory(Session) { Acronym = "VAT", Description = "Vatable", Rate = 12 })
                {
                    vat.Save();
                }

            }
            //importReport("SOHeaderPrintOut");
        }
开发者ID:ViniciusConsultor,项目名称:roadmaxweberp,代码行数:48,代码来源:Updater.cs

示例4: Role

        public void ActiveDifferenceObjectsRoles_Will_Be_All_ModelDifferenceObjectsObjects_that_are_OfRoleType_And_That_At_Leat_One_of_Their_Roles_Is_Current_User_Role()
        {
            Isolate.Fake.ISecurityComplex();
            var role = new Role(Session.DefaultSession);
            role.Save();
            ((User)SecuritySystem.CurrentUser).Roles.Add(role);
            XafTypesInfo.Instance.RegisterEntity(typeof(RoleModelDifferenceObject));
            RoleDifferenceObjectBuilder.CreateDynamicMembers(Isolate.Fake.Instance<ISecurityComplex>());
            new ModelDifferenceObject(Session.DefaultSession){PersistentApplication = new PersistentApplication(Session.DefaultSession)}.Save();
            var roleDifferenceObjectsObject1 = new RoleModelDifferenceObject(Session.DefaultSession) { PersistentApplication =new PersistentApplication(Session.DefaultSession) { UniqueName = "AppName" } };
            ((XPCollection)roleDifferenceObjectsObject1.GetMemberValue("Roles")).Add(role);
            roleDifferenceObjectsObject1.Save();
            var roleDifferenceObjectsObject2 = new RoleModelDifferenceObject(Session.DefaultSession) { PersistentApplication = new PersistentApplication(Session.DefaultSession) { UniqueName = "AppName" } };
            roleDifferenceObjectsObject2.Save();
            ((XPCollection)roleDifferenceObjectsObject2.GetMemberValue("Roles")).Add(role);
            new RoleModelDifferenceObject(Session.DefaultSession) { PersistentApplication = new PersistentApplication(Session.DefaultSession){ Name = "AppName" } }.Save();
            

            IQueryable<RoleModelDifferenceObject> queryable = new QueryRoleModelDifferenceObject(Session.DefaultSession).GetActiveModelDifferences("AppName");

            Assert.AreEqual(2, queryable.Count());
        }
开发者ID:akingunes,项目名称:eXpand,代码行数:22,代码来源:Quering_RoleDifferenceObjectsObjects.cs

示例5: CreateRole

        public override void CreateRole(string roleName)
        {
            // Make sure we are not attempting to insert an existing role.
            if (RoleExists(roleName))
            {
                throw new ProviderException("Role already exists.");
            }

            try
            {
                Role role = new Role();
                role.RoleName = roleName;
                role.Application = Application;

                role.Save();
                UnitOfWork.CurrentSession.Flush();
            }
            catch (Exception ex)
            {
                throw new ProviderException("Unable to create role.", ex);
            }
        }
开发者ID:brendankowitz,项目名称:systembusinessobjects,代码行数:22,代码来源:RoleProvider.cs

示例6: CreatePermission

        public static void CreatePermission(Session sess)
        {
            Role roleBasic = sess.FindObject<Role>(new BinaryOperator("Name", "基本"));

            if (roleBasic == null)
            {
                roleBasic = new Role(sess);
                roleBasic.Name = "基本";
                roleBasic.AddPermission(new ObjectAccessPermission(typeof(Barcode), ObjectAccess.Read));
                roleBasic.AddPermission(new ObjectAccessPermission(typeof(FileDataEx), ObjectAccess.AllAccess));
                roleBasic.AddPermission(new ObjectAccessPermission(typeof(SystemSetting), ObjectAccess.Read));
                roleBasic.AddPermission(new ObjectAccessPermission(typeof(Unit), ObjectAccess.Read & ObjectAccess.Navigate));
                roleBasic.AddPermission(new ObjectAccessPermission(typeof(UnitConvert), ObjectAccess.Read & ObjectAccess.Navigate));
                roleBasic.Save();
            }

            Role roleItem = sess.FindObject<Role>(new BinaryOperator("Name", "产品-只读"));
            if (roleItem == null)
            {
                roleItem = new Role(sess);
                roleItem.Name = "产品-只读";
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Item), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(BomLine), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemCategory), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemSetting), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemType), ObjectAccess.Read & ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Lot), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Material), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(PriceCategory), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(RouteLine), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(WorkCenter), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(WorkOper), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.Save();
            }

            roleItem = sess.FindObject<Role>(new BinaryOperator("Name", "产品-修改"));
            if (roleItem == null)
            {
                roleItem = new Role(sess);
                roleItem.Name = "产品-修改";
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Item), ObjectAccess.AllAccess));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(BomLine), ObjectAccess.AllAccess));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(RouteLine), ObjectAccess.AllAccess));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Lot), ObjectAccess.AllAccess));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(PriceCategory), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemCategory), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemSetting), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemType), ObjectAccess.Read & ObjectAccess.Navigate));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Material), ObjectAccess.Read ^ ObjectAccess.Navigate));
                roleItem.Save();
            }

            roleItem = sess.FindObject<Role>(new BinaryOperator("Name", "产品-设定"));
            if (roleItem == null)
            {
                roleItem = new Role(sess);
                roleItem.Name = "产品-设定";
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemCategory), ObjectAccess.AllAccess));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemSetting), ObjectAccess.AllAccess));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(ItemType), ObjectAccess.AllAccess ));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Lot), ObjectAccess.AllAccess ));
                roleItem.AddPermission(new ObjectAccessPermission(typeof(Material), ObjectAccess.AllAccess ));
                roleItem.Save();
            }
        }
开发者ID:kamchung322,项目名称:Namwah,代码行数:65,代码来源:Updater.cs

示例7: SaveRole

        public JsonResult SaveRole(RoleInfo Info)
        {
            RequestResultModel _model = new RequestResultModel();

            if (Info.Name == null || Info.Name.Trim().Length == 0)
            {
                _model = new RequestResultModel();
                _model.Title = "Warning";
                _model.Message = "Name is empty. Please, enter role name.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                }, JsonRequestBehavior.AllowGet);
            }

            if (!AppSession.IsColor(Info.Color))
            {
                _model = new RequestResultModel();
                _model.Title = "Warning";
                _model.Message = "Wrong color value or format, please check.";
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                return Json(new
                {
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                }, JsonRequestBehavior.AllowGet);
            }

            if (Info.RoleID > 0)
            {
                Role role = Web.Admin.Logic.Collections.Roles.GetBy(Info.RoleID);
                Role roleExists = Web.Admin.Logic.Collections.Roles.GetBy(Info.Name);

                // The role has been deleted.
                if (role.RoleID <= 0)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Role '{0}' doesn't exist. Please, refresh role list and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                    }, JsonRequestBehavior.AllowGet);
                }

                // The role already esists.
                if (roleExists.RoleID > 0 && Info.RoleID != roleExists.RoleID)
                {
                    _model.Title = "Warning";
                    _model.Message = String.Format("Role '{0}' already exists. Please, change role name and try again.", roleExists.Name);
                    AuditEvent.AppEventWarning(Profile.Member.Email, _model.Message);

                    return Json(new
                    {
                        NotifyType = NotifyType.DialogInline,
                        Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                    }, JsonRequestBehavior.AllowGet);
                }

                if (!role.IsBuiltIn)
                {
                    role.Name = Info.Name;
                    role.IsBuiltIn = false;
                }
                else
                {
                    role.IsBuiltIn = true;
                }

                role.Settings = Info.Settings;
                role.BackColor = Info.Color != null ? Info.Color.Replace("#", "") : "FFFFFF";
                role.ForeColor = Role.ContrastColor(role.BackColor.Replace("#", ""));
                role.Save();

                _model = new RequestResultModel();
                _model.Message = String.Format("Role \"{0}\"has been updated.",role.Name);
                _model.HideInSeconds = 4000;
                AuditEvent.AppEventSuccess(Profile.Member.Email, _model.Message);

                return Json(new
                {
                    NotifyType = NotifyType.PageInline,
                    Html = this.RenderPartialView(@"_RequestResultPageInLine", _model)

                }, JsonRequestBehavior.AllowGet);

            }
            else
//.........这里部分代码省略.........
开发者ID:ManigandanS,项目名称:Disaster-Management-Communication-System,代码行数:101,代码来源:RolesController.cs

示例8: SaveToDb

 //数据持久化
 internal static void SaveToDb(RoleInfo pRoleInfo, Role  pRole,bool pIsNew)
 {
     pRole.RoleId = pRoleInfo.roleId;
      		pRole.RoleName = pRoleInfo.roleName;
     pRole.IsNew=pIsNew;
     string UserName = SubsonicHelper.GetUserName();
     try
     {
         pRole.Save(UserName);
     }
     catch(Exception ex)
     {
         LogManager.getInstance().getLogger(typeof(RoleInfo)).Error(ex);
         if(ex.Message.Contains("插入重复键"))//违反了唯一键
         {
             throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
         }
         throw new AppException("保存失败");
     }
     pRoleInfo.roleId = pRole.RoleId;
     //如果缓存存在,更新缓存
     if (CachedEntityCommander.IsTypeRegistered(typeof(RoleInfo)))
     {
         ResetCache();
     }
 }
开发者ID:xingfudaiyan,项目名称:OA,代码行数:27,代码来源:RoleInfo.cs

示例9: Create

        public ActionResult Create(RoleEditModel model)
        {
            if (ModelState.IsValid)
            {
                if (Role.AsQueryable().Where(x => x.Name == model.Name).Count() > 0)
                {
                    ModelState.AddModelError("Name", "The role name is already in use.");
                }
                else
                {
                    Role role = new Role();
                    role.Name = model.Name;
                    role.Description = model.Description;
                    role.Save();

                    return RedirectToAction("Index");
                }
            }
            return View();
        }
开发者ID:theBraindonor,项目名称:BrainDonor.Mongo,代码行数:20,代码来源:RoleController.cs

示例10: CreateRole

        /// <summary>
        /// Adds a new role to the data source for the configured application name.
        /// </summary>
        /// <param name="roleName">the name of the role to create.</param>
        public override void CreateRole(string roleName)
        {
            using (var session = Database.Context.CurrentSession)
            {
                // Make sure we are not attempting to insert an existing role.
                if (RoleExists(roleName))
                {
                    throw new ProviderException("Role already Exists");
                }

                try
                {
                    using (var tx = session.BeginTransaction())
                    {
                        Role role = new Role();
                        role.Name = roleName;
                        role.Applications.Add(ApplicationLogic.GetApplication(session, _applicationName));
                        role.Save(session, tx);
                    }
                }
                catch (Exception ex)
                {
                    throw new ProviderException("Unable to create role.", ex);
                }
            }
        }
开发者ID:Azerothian,项目名称:Lifelike,代码行数:30,代码来源:nHibernateRoleProvider.cs

示例11: CreateNewRole

        protected void CreateNewRole(object sender, ActiveEventArgs e)
        {
            string roleName = e.Params["RoleName"].Get<string>();
            Role role = new Role {Name = roleName};
            role.Save();

            ActiveEvents.Instance.RaiseClearControls("dynPopup");
            ActiveEvents.Instance.RaiseActiveEvent(
                this, 
                "Menu-ViewAllRoles");
        }
开发者ID:greaterwinner,项目名称:ra-brix,代码行数:11,代码来源:RoleController.cs


注:本文中的Role.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。