public static void Update(FormUser formUser) { List<FormUser> formsUsers2 = GetFormsUsers(formUser.FormID, formUser.UserID); if (formsUsers2 != null && formsUsers2.Count > 0 && formsUsers2[0].ID != formUser.ID) throw new Exception("This user already exists, please choose another user"); FormUserDataMapper.Update(formUser); }
public static int Add(FormUser formUser) { List<FormUser> formsUsers2 = GetFormsUsers(formUser.FormID, formUser.UserID); if (formsUsers2 != null && formsUsers2.Count > 0) throw new Exception("This user already exists, please choose another user"); return FormUserDataMapper.Add(formUser); }
internal static int Add(FormUser formUser) { using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString)) { SqlCommand sqlCommand = new SqlCommand(SN_FORM_USER_ADD, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter sqlParameter = null; sqlParameter = new SqlParameter(PN_FORM_USER_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Output; sqlParameter.Value = 0; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_USER_FORM_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formUser.FormID; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_USER_USER_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formUser.UserID; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_USER_ACCESS_TYPE, System.Data.SqlDbType.Bit); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = (int)formUser.AccessType; sqlCommand.Parameters.Add(sqlParameter); try { sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); sqlCommand.Connection.Close(); formUser.ID = Convert.ToInt32(sqlCommand.Parameters[PN_FORM_USER_ID].Value); } catch (Exception ex) { throw ex; } } return formUser.ID; }
void btnPermissionUserSave_Click(object sender, EventArgs e) { if (ViewState[CMSViewStateManager.FormID] != null) { try { CMS.Core.Entities.FormUser formUser = new FormUser(); formUser.AccessType = (CMSEnums.AccessType)Convert.ToInt32(rblAccessTypeUser.SelectedValue); formUser.FormID = Convert.ToInt32(ViewState[CMSViewStateManager.FormID]); formUser.ID = 0; formUser.UserID = Convert.ToInt32(cddUsers.SelectedValue); FormUserManager.Add(formUser); FillUsers(-1); } catch (Exception ex) { dvProblemUser.Visible = true; dvProblemUser.InnerText = ex.Message; } } }
internal static void FillFromReader(FormUser formUser, SqlDataReader reader) { int colIndex = 0; colIndex = reader.GetOrdinal(CN_FORM_USER_ID); if (!reader.IsDBNull(colIndex)) formUser.ID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_USER_ACCESS_TYPE); if (!reader.IsDBNull(colIndex)) formUser.AccessType = (CMSEnums.AccessType)reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_USER_FORM_ID); if (!reader.IsDBNull(colIndex)) formUser.FormID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_USER_USER_ID); if (!reader.IsDBNull(colIndex)) formUser.UserID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(UserDataMapper.CN_USER_NAME); if (!reader.IsDBNull(colIndex)) formUser.UserName = reader.GetString(colIndex); colIndex = reader.GetOrdinal(FormDataMapper.CN_FORM_CODE); if (!reader.IsDBNull(colIndex)) formUser.FormCode = reader.GetString(colIndex); }
internal static FormUser GetFormUser(List<FormUser> formsUsers, SqlDataReader reader) { int colIndex = 0; colIndex = reader.GetOrdinal(CN_FORM_USER_ID); int value = reader.GetInt32(colIndex); FormUser formUser = formsUsers.Where(c => c.ID == value).FirstOrDefault(); if (formUser == null) { formUser = new FormUser(); formsUsers.Add(formUser); } return formUser; }
internal static FormUser GetFormUserById(int ID) { FormUser formUser = null; using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString)) { SqlCommand sqlCommand = new SqlCommand(SN_FORM_USER_GET_BY_ID, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter parameter = new SqlParameter(PN_FORM_USER_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 (formUser == null) formUser = new FormUser(); FillFromReader(formUser, reader); } reader.Close(); sqlCommand.Connection.Close(); } } return formUser; }