protected override Role <DataActions> RoleContractToRole(RoleContract roleContract) { DataActions dataActions = roleContract.DataActions.Aggregate(default(DataActions), (acc, a) => acc | ToEnum(a)); DataActions notDataActions = roleContract.NotDataActions.Aggregate(default(DataActions), (acc, a) => acc | ToEnum(a)); return(new Role <DataActions>(roleContract.Name, dataActions & ~notDataActions, roleContract.Scopes.Single())); }
/// <summary> /// Insert by providing a populated data row container /// </summary> /// <param name="row">The table row data to use</param> /// <returns>1, if insert was successful</returns> public int Insert(RoleContract row) { int?result = null; VotingInfoDb.ConnectThen(x => { using ( var cmd = new SqlCommand("[Auth].[Role_Insert]", x) { CommandType = CommandType.StoredProcedure, CommandTimeout = DefaultCommandTimeout }) { cmd.Parameters.AddRange(new[] { new SqlParameter("@Title", row.Title) , new SqlParameter("@Description", row.Description) , new SqlParameter("@IsActive", row.IsActive) , new SqlParameter("@ApplyToAnon", row.ApplyToAnon) , new SqlParameter("@ApplyToAllUsers", row.ApplyToAllUsers) , new SqlParameter("@PreventAddingUsers", row.PreventAddingUsers) , new SqlParameter("@WINSID", row.WINSID) }); result = (int?)cmd.ExecuteScalar(); row.RoleId = result; } }); return(result != null ? 1 : 0); }
/// <summary> /// Update by providing a populated data contract /// </summary> /// <param name="row">The table row data to use</param> /// <param name="connection">The SqlConnection to use</param> /// <param name="transaction">The SqlTransaction to use</param> /// <returns>The number of rows affected.</returns> public virtual int Update(RoleContract row, SqlConnection connection, SqlTransaction transaction) { var rowCount = 0; using ( var cmd = new SqlCommand("[Auth].[Role_Update]", connection) { CommandType = CommandType.StoredProcedure, Transaction = transaction }) { cmd.Parameters.AddRange(new[] { new SqlParameter("@RoleId", row.RoleId) , new SqlParameter("@Title", row.Title) , new SqlParameter("@Description", row.Description) , new SqlParameter("@IsActive", row.IsActive) , new SqlParameter("@ApplyToAnon", row.ApplyToAnon) , new SqlParameter("@ApplyToAllUsers", row.ApplyToAllUsers) , new SqlParameter("@PreventAddingUsers", row.PreventAddingUsers) , new SqlParameter("@WINSID", row.WINSID) }); rowCount = cmd.ExecuteNonQuery(); } return(rowCount); }
public IActionResult CreateRole(RoleViewModel roleViewModel) { roleViewModel.SuccessfulUpdate = false; if (ModelState.IsValid) { try { var roleContract = new RoleContract { Id = roleViewModel.Id, Name = roleViewModel.Name, Description = roleViewModel.Description }; var client = GetRoleClient(); client.CreateRole(roleContract); roleViewModel.SuccessfulUpdate = true; } catch (HttpErrorCodeException e) { AddErrors(e); } catch (MainServiceException e) { AddErrors(e); } } return(PartialView("_CreateRole", roleViewModel)); }
private Role RoleContractToRole(RoleContract roleContract) { DataActions dataActions = roleContract.DataActions.Aggregate(default(DataActions), (acc, a) => acc | a); DataActions notDataActions = roleContract.NotDataActions.Aggregate(default(DataActions), (acc, a) => acc | a); return(new Role(roleContract.Name, dataActions & ~notDataActions, roleContract.Scopes.Single())); }
/// <summary> /// Insert by providing a populated data contract /// </summary> /// <param name="row">The table row data to use</param> /// <param name="connection">The SqlConnection to use</param> /// <param name="transaction">The SqlTransaction to use</param> /// <returns>1, if insert was successful</returns> public int Insert(RoleContract row, SqlConnection connection, SqlTransaction transaction) { int?result = null; using ( var cmd = new SqlCommand("[Auth].[Role_Insert]", connection) { CommandType = CommandType.StoredProcedure, Transaction = transaction }) { cmd.Parameters.AddRange(new[] { new SqlParameter("@Title", row.Title) , new SqlParameter("@Description", row.Description) , new SqlParameter("@IsActive", row.IsActive) , new SqlParameter("@ApplyToAnon", row.ApplyToAnon) , new SqlParameter("@ApplyToAllUsers", row.ApplyToAllUsers) , new SqlParameter("@PreventAddingUsers", row.PreventAddingUsers) , new SqlParameter("@WINSID", row.WINSID) }); result = (int?)cmd.ExecuteScalar(); row.RoleId = result; } return(result != null ? 1 : 0); }
/// <summary> /// Gets the role contract for the specified role id and assigns /// allowed document actions respectively operations to the contract. /// /// Invokes the UpdateRole method on an instance of the InfoShareService.CommonClient /// class and passes the connection id of the administrator, and the role /// contract as arguments. /// </summary> /// <param name="connAdminUserID">the connection id of the administrator</param> /// <param name="roleID">the role id</param> /// <param name="accessOperationCategoryName">the access operation category name</param> /// <param name="schemaCulture">the schema culture</param> public void AssignAllowedDocumentActionsToRole(string connAdminUserID, string roleID, string accessOperationCategoryName, string schemaCulture) { RoleContract roleContract = this.GetRoleContract(roleID); if (roleContract != null) { string accessOperationCategoryID = GetAccessOperationCategoryID(accessOperationCategoryName, schemaCulture); if (accessOperationCategoryID != null) { AccessOperationContract[] array = this.SecurityStore.AccessOperations; ArrayList allowedActionIds = new ArrayList(); // Loops through all access operation contracts and, if it belongs to the specified access operation category, // adds it to the arrayList foreach (AccessOperationContract accessOperation in this.SecurityStore.AccessOperations) { if (accessOperation.CategoryId == accessOperationCategoryID) { allowedActionIds.Add(accessOperation.Id); } } roleContract.AllowedActionIds = (string[])allowedActionIds.ToArray(typeof(string)); CommonClient.UpdateRole(connAdminUserID, roleContract); } } this.RefreshSecurityStore(connAdminUserID); }
protected override Role <DataActions> RoleContractToRole(RoleContract roleContract) { EnsureArg.IsNotNull(roleContract, nameof(roleContract)); DataActions dataActions = roleContract.DataActions.Aggregate(DataActions.None, (acc, a) => acc | ToEnum(a)); DataActions notDataActions = roleContract.NotDataActions.Aggregate(DataActions.None, (acc, a) => acc | ToEnum(a)); return(new Role <DataActions>(roleContract.Name, dataActions & ~notDataActions, roleContract.Scopes.Single())); }
public ActionResult Create() { var item = new RoleContract() { Id = Guid.NewGuid(), ApplicationId = Guid.Parse(ConfigurationManager.AppSettings["ApplicationId"]) }; return(View(new RoleViewModel(item))); }
/// <summary> /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value). /// </summary> /// <param name="row">The data to save</param> /// <returns>The number of rows affected.</returns> public static int SaveNow(RoleContract row) { if (row.RoleId == null) { return(InsertNow(row)); } else { return(UpdateNow(row)); } }
/// <summary> /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value). /// </summary> /// <param name="row">The data to save</param> /// <param name="connection">The SqlConnection to use</param> /// <param name="transaction">The SqlTransaction to use</param> /// <returns>The number of rows affected.</returns> public static int SaveNow(RoleContract row, SqlConnection connection, SqlTransaction transaction) { if (row.RoleId == null) { return(InsertNow(row, connection, transaction)); } else { return(UpdateNow(row, connection, transaction)); } }
public static RoleDto ToDto(this RoleContract contract) { if (contract == null) { return(null); } return(new RoleDto() { Id = contract.Id, Name = contract.Name }); }
/// <summary> /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value). /// </summary> /// <param name="row">The data to save</param> /// <returns>The number of rows affected.</returns> public virtual int Save(RoleContract row) { if (row == null) { return(0); } if (row.RoleId != null) { return(Update(row)); } return(Insert(row)); }
/// <summary> /// Gets the role contract for the specified role id and assigns the group ids /// passed as argument to the contract. /// <p> /// Calls the UpdateRole method on an instance of the InfoShareService.CommonClient /// class and passes the connection id of the administrator, and the role /// contract as arguments. /// </summary> /// <param name="connAdminUserID">the connection id of the administrator</param> /// <param name="groupIDs">an array of group ids</param> /// <param name="roleID">the role id</param> public void AssignGroupsToRole(string connAdminUserID, string[] groupIDs, string roleID) { RoleContract roleContract = this.GetRoleContract(roleID); if (roleContract != null) { roleContract.GroupIds = groupIDs; this.CommonClient.UpdateRole(connAdminUserID, roleContract); } this.RefreshSecurityStore(connAdminUserID); }
/// <summary> /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value). /// </summary> /// <param name="row">The data to save</param> /// <param name="connection">The SqlConnection to use</param> /// <param name="transaction">The SqlTransaction to use</param> /// <returns>The number of rows affected.</returns> public virtual int Save(RoleContract row, SqlConnection connection, SqlTransaction transaction) { if (row == null) { return(0); } if (row.RoleId != null) { return(Update(row, connection, transaction)); } return(Insert(row, connection, transaction)); }
public static Role ConvertToRoleEntity(RoleContract role) { if (role == null) { return(null); } Role entityRole = new Role() { RoleID = role.RoleID, RoleName = role.RoleName, }; return(entityRole); }
public static RoleContract ConvertToRoleContract(Role role) { if (role == null) { return(null); } RoleContract contractRole = new RoleContract() { RoleID = role.RoleID, RoleName = role.RoleName, }; return(contractRole); }
/// <summary> /// Creates a role contract and sets mandatory and optional fields on the contract. /// /// The name of the role contract is passed as an argument. /// Calls the cCeateRole method on an instance of the InfoShareService.CommonClient /// class and passes the connection id of the administrator, and the role /// contract as arguments. /// </summary> /// <param name="connAdminUserID">the connection id of the administrator</param> /// <param name="roleName">the role name</param> /// <returns>the id of the created role</returns> public string CreateRole(string connAdminUserID, string roleName) { RoleContract roleContract = new RoleContract { // Sets mandatory field Name = roleName }; string roleID = CommonClient.CreateRole(connAdminUserID, roleContract); this.RefreshSecurityStore(connAdminUserID); return(roleID); }
public void UpdateRole(int groupId, RoleContract data) { try { m_client.Put <object>($"role/{groupId}", data); } catch (HttpRequestException e) { if (m_logger.IsErrorEnabled()) { m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e); } throw; } }
public int CreateRole(RoleContract request) { try { var result = m_client.Post <int>("role", request); return(result); } catch (HttpRequestException e) { if (m_logger.IsErrorEnabled()) { m_logger.LogError("{0} failed with {1}", m_client.GetCurrentMethod(), e); } throw; } }
public static BASE_ROLE_INFO ToEntity(this RoleContract source) { if (source == null) { throw new InvalidOperationException("source is null"); } return(new BASE_ROLE_INFO { ROLE_INFO_ID = source.Id, ROLE_INFO_NAME = source.Name, ROLE_INFO_CREATEDDATE = source.CreatedDate, GLOBAL_TYPE_ID = source.ApplicationId, ROLE_INFO_REMARK = source.Remark, ROLE_INFO_TYPE = source.Type, CREATEDBY = source.Createby, IsDel = source.IsDel }); }
/// <summary> /// Delete by providing a populated data contract /// </summary> /// <param name="row">The table row data to use</param> /// <param name="connection">The SqlConnection to use</param> /// <param name="transaction">The SqlTransaction to use</param> /// <returns>The number of rows affected.</returns> public virtual int Delete(RoleContract row, SqlConnection connection, SqlTransaction transaction) { var rowCount = 0; using ( var cmd = new SqlCommand("[Auth].[Role_Delete]", connection) { CommandType = CommandType.StoredProcedure, Transaction = transaction }) { cmd.Parameters.AddRange(new[] { new SqlParameter("@RoleId", row.RoleId) }); rowCount = cmd.ExecuteNonQuery(); } return(rowCount); }
/// <summary> /// Gets the role contract for the specified role id. /// /// Gets an array of role contracts from the security store contract that /// is passed as an argument and searches for the role contract with /// the specified role id. Returns the role contract, if it finds the /// contract. /// </summary> /// <param name="roleID">the role id</param> /// <returns>the role contract</returns> private RoleContract GetRoleContract(string roleID) { RoleContract roleContract = null; // Searches for the role contract with the specified role id foreach (RoleContract role in this.SecurityStore.Roles) { if (role.Id == roleID) // Gets group ID { // Contract found roleContract = role; break; } } if (roleContract == null) { throw new NotFoundException("No role contract found for role ID <" + roleID + ">."); } return(roleContract); }
/// <summary> /// Update by providing a populated data row container /// </summary> /// <param name="row">The table row data to use</param> /// <returns>The number of rows affected.</returns> public virtual int Update(RoleContract row) { var rowCount = 0; VotingInfoDb.ConnectThen(x => { using ( var cmd = new SqlCommand("[Auth].[Role_Update]", x) { CommandType = CommandType.StoredProcedure, CommandTimeout = DefaultCommandTimeout }) { cmd.Parameters.AddRange(new[] { new SqlParameter("@RoleId", row.RoleId) , new SqlParameter("@Title", row.Title) , new SqlParameter("@Description", row.Description) , new SqlParameter("@IsActive", row.IsActive) , new SqlParameter("@ApplyToAnon", row.ApplyToAnon) , new SqlParameter("@ApplyToAllUsers", row.ApplyToAllUsers) , new SqlParameter("@PreventAddingUsers", row.PreventAddingUsers) , new SqlParameter("@WINSID", row.WINSID) }); rowCount = cmd.ExecuteNonQuery(); } }); return(rowCount); }
/// <summary> /// Delete by providing a populated data row container /// </summary> /// <param name="row">The table row data to use</param> /// <returns>The number of rows affected.</returns> public virtual int Delete(RoleContract row) { var rowCount = 0; VotingInfoDb.ConnectThen(x => { using ( var cmd = new SqlCommand("[Auth].[Role_Delete]", x) { CommandType = CommandType.StoredProcedure, CommandTimeout = DefaultCommandTimeout }) { cmd.Parameters.AddRange(new[] { new SqlParameter("@RoleId", row.RoleId) }); rowCount = cmd.ExecuteNonQuery(); } }); return(rowCount); }
public int CreateRole([FromBody] RoleContract data) { var resultId = m_roleManager.CreateRole(data.Name, data.Description); return(resultId); }
/// <summary> /// Insert by providing a populated data contract /// </summary> /// <param name="row">The table row data to use</param> /// <param name="connection">The SqlConnection to use</param> /// <param name="transaction">The SqlTransaction to use</param> /// <returns>The number of rows affected.</returns> public static int InsertNow(RoleContract row, SqlConnection connection, SqlTransaction transaction) { return((new RoleLogic()).Insert(row, connection, transaction)); }
public void UpdateRole(RoleContract data) { new UpdateRoleWork(m_permissionRepository, m_defaultUserProvider, m_communicationProvider, data).Execute(); }
public IActionResult UpdateRole(int groupId, [FromBody] RoleContract data) { data.Id = groupId; m_roleManager.UpdateRole(data); return(Ok()); }
public RoleViewModel(RoleContract contract) { RoleContract = contract; }