public static int Add(FormRole formRole) { List<FormRole> formsRoles2 = GetFormsRoles(formRole.FormID, formRole.RoleID); if (formsRoles2 != null && formsRoles2.Count > 0) throw new Exception("This role already exists, please choose another role"); return FormRoleDataMapper.Add(formRole); }
public static void Update(FormRole formRole) { List<FormRole> formsRoles2 = GetFormsRoles(formRole.FormID, formRole.RoleID); if (formsRoles2 != null && formsRoles2.Count > 0 && formsRoles2[0].ID != formRole.ID) throw new Exception("This role already exists, please choose another role"); FormRoleDataMapper.Update(formRole); }
internal static int Add(FormRole formRole) { using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString)) { SqlCommand sqlCommand = new SqlCommand(SN_FORM_ROLE_ADD, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter sqlParameter = null; sqlParameter = new SqlParameter(PN_FORM_ROLE_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Output; sqlParameter.Value = 0; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_ROLE_FORM_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formRole.FormID; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_ROLE_ROLE_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formRole.RoleID; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_ROLE_ACCESS_TYPE, System.Data.SqlDbType.Bit); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = (int)formRole.AccessType; sqlCommand.Parameters.Add(sqlParameter); try { sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); sqlCommand.Connection.Close(); formRole.ID = Convert.ToInt32(sqlCommand.Parameters[PN_FORM_ROLE_ID].Value); } catch (Exception ex) { throw ex; } } return formRole.ID; }
void btnPermissionRoleSave_Click(object sender, EventArgs e) { if (ViewState[CMSViewStateManager.FormID] != null) { try { CMS.Core.Entities.FormRole formRole = new FormRole(); formRole.AccessType = (CMSEnums.AccessType)Convert.ToInt32(rblAccessTypeRole.SelectedValue); formRole.FormID = Convert.ToInt32(ViewState[CMSViewStateManager.FormID]); formRole.ID = 0; formRole.RoleID = Convert.ToInt32(cddRoles.SelectedValue); FormRoleManager.Add(formRole); FillRoles(-1); } catch (Exception ex) { dvProblemRole.Visible = true; dvProblemRole.InnerText = ex.Message; } } }
internal static void FillFromReader(FormRole formRole, SqlDataReader reader) { int colIndex = 0; colIndex = reader.GetOrdinal(CN_FORM_ROLE_ID); if (!reader.IsDBNull(colIndex)) formRole.ID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_ROLE_ACCESS_TYPE); if (!reader.IsDBNull(colIndex)) formRole.AccessType = (CMSEnums.AccessType)reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_ROLE_FORM_ID); if (!reader.IsDBNull(colIndex)) formRole.FormID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_ROLE_ROLE_ID); if (!reader.IsDBNull(colIndex)) formRole.RoleID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(RoleDataMapper.CN_ROLE_NAME); if (!reader.IsDBNull(colIndex)) formRole.RoleName = reader.GetString(colIndex); colIndex = reader.GetOrdinal(FormDataMapper.CN_FORM_CODE); if (!reader.IsDBNull(colIndex)) formRole.FormCode = reader.GetString(colIndex); }
internal static FormRole GetFormRole(List<FormRole> formsRoles, SqlDataReader reader) { int colIndex = 0; colIndex = reader.GetOrdinal(CN_FORM_ROLE_ID); int value = reader.GetInt32(colIndex); FormRole formRole = formsRoles.Where(c => c.ID == value).FirstOrDefault(); if (formRole == null) { formRole = new FormRole(); formsRoles.Add(formRole); } return formRole; }
internal static FormRole GetFormRoleById(int ID) { FormRole formRole = null; using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString)) { SqlCommand sqlCommand = new SqlCommand(SN_FORM_ROLE_GET_BY_ID, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter parameter = new SqlParameter(PN_FORM_ROLE_ID, System.Data.SqlDbType.Int); parameter.Direction = System.Data.ParameterDirection.Input; parameter.Value = ID; sqlCommand.Parameters.Add(parameter); sqlCommand.Connection.Open(); using (SqlDataReader reader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)) { while (reader.Read()) { if (formRole == null) formRole = new FormRole(); FillFromReader(formRole, reader); } reader.Close(); sqlCommand.Connection.Close(); } } return formRole; }