/// <summary> /// Accepts Companies and SqlCommand objects, insert into Companies table /// /// return compID of newly inserted row(s) /// </summary> /// <param name="Companies">Companies object</param> /// <param name="sqlCmd">SqlCommand object</param> /// <returns>compID of newly inserted row(s)</returns> public static Int32 Insert(Companies objCompanies, SqlCommand sqlCmd) { // Validating provided SqlCommand if (sqlCmd.Connection == null || sqlCmd.Connection.State == ConnectionState.Closed) { throw new Exception("Error in provided Connection. Please set SqlCommand.Connection = new SqlConnection(string ConnectionString); or in other ways."); } if (sqlCmd.Transaction == null) { throw new Exception("Error in provided SqlTransaction. Please set sqlCmd.Transaction = sqlCmd.Connection.BeginTransaction(); or in other ways."); } objCompanies.Validate(SqlOperation.Insert); sqlCmd = AttachParameters(sqlCmd, objCompanies, SqlOperation.Insert); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = Companies_Insert; try { objCompanies.compID = (Int32)SqlHelper.ExecuteNonQuery(sqlCmd); /// Validating if any required field does not have initial value if (objCompanies.compID < 1) { throw new Exception("Could not insert Companies. Please check your Data Access block or Companies_Insert Stored Procedure."); } else { //Save objEmailConfigList data objCompanies.objEmailConfigList.SetProperty("compID", objCompanies.compID); EmailConfigContext.Insert(objCompanies.objEmailConfigList, sqlCmd); //Save objCompanySSOList data objCompanies.objCompanySSOList.SetProperty("compID", objCompanies.compID); CompanySSOContext.Insert(objCompanies.objCompanySSOList, sqlCmd); //Save objCompanySettingsList data objCompanies.objCompanySettingsList.SetProperty("compID", objCompanies.compID); CompanySettingsContext.Insert(objCompanies.objCompanySettingsList, sqlCmd); return(objCompanies.compID); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Saves the changes. /// </summary> public void SaveChanges() { EmailConfigContext.Save(emailConfiguration); }