internal static int Add(Form formEntity) { using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString)) { SqlCommand sqlCommand = new SqlCommand(SN_FORM_ADD, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter sqlParameter = null; sqlParameter = new SqlParameter(PN_FORM_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Output; sqlParameter.Value = 0; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_NAME, System.Data.SqlDbType.NVarChar); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formEntity.Name; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_DESCRIPTION, System.Data.SqlDbType.NVarChar); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formEntity.Description; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_URL, System.Data.SqlDbType.NVarChar); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formEntity.Url; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_CODE, System.Data.SqlDbType.NVarChar); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formEntity.Code; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_MODULE_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formEntity.ModuleID; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(PN_FORM_IS_DELETED, System.Data.SqlDbType.Bit); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = formEntity.IsDeleted; sqlCommand.Parameters.Add(sqlParameter); try { sqlCommand.Connection.Open(); sqlCommand.ExecuteNonQuery(); sqlCommand.Connection.Close(); formEntity.ID = Convert.ToInt32(sqlCommand.Parameters[PN_FORM_ID].Value); } catch (Exception ex) { throw ex; } } return formEntity.ID; }
public static int Add(Form form) { Form form2 = GetForm(form.Code); if (form2 != null) throw new Exception("There is another form has the same code, please choose another code"); return FormDataMapper.Add(form); }
public static void Update(Form form) { Form form2 = GetForm(form.Code); if (form2 != null && form2.ID != form.ID) throw new Exception("There is another form has the same e-mail, please choose another code"); FormDataMapper.Update(form); }
internal static void FillFromReader(Form form, SqlDataReader reader) { int colIndex = 0; colIndex = reader.GetOrdinal(CN_FORM_ID); if (!reader.IsDBNull(colIndex)) form.ID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_CODE); if (!reader.IsDBNull(colIndex)) form.Code = reader.GetString(colIndex); colIndex = reader.GetOrdinal(CN_FORM_DESCRIPTION); if (!reader.IsDBNull(colIndex)) form.Description = reader.GetString(colIndex); colIndex = reader.GetOrdinal(CN_FORM_IS_DELETED); if (!reader.IsDBNull(colIndex)) form.IsDeleted = reader.GetBoolean(colIndex); colIndex = reader.GetOrdinal(CN_FORM_MODULE_ID); if (!reader.IsDBNull(colIndex)) form.ModuleID = reader.GetInt32(colIndex); colIndex = reader.GetOrdinal(CN_FORM_NAME); if (!reader.IsDBNull(colIndex)) form.Name = reader.GetString(colIndex); colIndex = reader.GetOrdinal(CN_FORM_URL); if (!reader.IsDBNull(colIndex)) form.Url = reader.GetString(colIndex); }
internal static Form GetForm(List<Form> forms, SqlDataReader reader) { int colIndex = 0; colIndex = reader.GetOrdinal(CN_FORM_ID); int value = reader.GetInt32(colIndex); Form form = forms.Where(c => c.ID == value).FirstOrDefault(); if (form == null) { form = new Form(); forms.Add(form); } return form; }
internal static Form GetFormByFormCode(string FormCode) { Form form = null; using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString)) { SqlCommand sqlCommand = new SqlCommand(SN_FORM_GET_BY_CODE, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter parameter = new SqlParameter(PN_FORM_CODE, System.Data.SqlDbType.NVarChar); parameter.Direction = System.Data.ParameterDirection.Input; parameter.Value = FormCode; sqlCommand.Parameters.Add(parameter); sqlCommand.Connection.Open(); using (SqlDataReader reader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)) { while (reader.Read()) { if (form == null) form = new Form(); FillFromReader(form, reader); } reader.Close(); sqlCommand.Connection.Close(); } } return form; }