public static bool Save(SqlConnection connection, Report_Request_Model model) { bool returnValue = false; StringBuilder sQuery = new StringBuilder(); sQuery.Append(@"INSERT INTO a_Report_Request (Request_Type ,DateFrom ,DateTo ,SendToEmail ,isFinished ,TimeStamp ,CreatedBy ) VALUES (@Request_Type ,@DateFrom ,@DateTo ,@SendToEmail ,@isFinished ,@TimeStamp ,@CreatedBy ) "); // SELECT SCOPE_IDENTITY() as 'ID' var GUID = SQL_Transact.GenerateGUID(); SQL_Transact.BeginTransaction(connection, GUID); using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = connection; cmd.CommandText = sQuery.ToString(); cmd.CommandType = CommandType.Text; SqlParameter parm2 = new SqlParameter { ParameterName = "@Request_Type", SqlDbType = SqlDbType.NVarChar, Value = model.Request_Type }; cmd.Parameters.Add(parm2); SqlParameter parm3 = new SqlParameter { ParameterName = "@DateFrom", SqlDbType = SqlDbType.DateTime, Value = model.DateFrom }; cmd.Parameters.Add(parm3); SqlParameter parm4 = new SqlParameter { ParameterName = "@DateTo", SqlDbType = SqlDbType.DateTime, Value = model.DateTo }; cmd.Parameters.Add(parm4); SqlParameter parm5 = new SqlParameter { ParameterName = "@SendToEmail", SqlDbType = SqlDbType.NVarChar, Value = model.SendToEmail }; cmd.Parameters.Add(parm5); SqlParameter parm6 = new SqlParameter { ParameterName = "@isFinished", SqlDbType = SqlDbType.NVarChar, Value = model.isFinished }; cmd.Parameters.Add(parm6); SqlParameter parm7 = new SqlParameter { ParameterName = "@TimeStamp", SqlDbType = SqlDbType.DateTime, Value = model.TimeStamp }; cmd.Parameters.Add(parm7); SqlParameter parm8 = new SqlParameter { ParameterName = "@CreatedBy", SqlDbType = SqlDbType.NVarChar, Value = model.CreatedBy }; cmd.Parameters.Add(parm8); // var oreader = cmd.ExecuteReader(); try { if (cmd.ExecuteNonQuery() >= 1) { returnValue = true; } else { returnValue = false; } //while (oreader.Read()) //{ // returnValue = Convert.ToInt32(oreader["ID"].ToString()); //} //oreader.Close(); cmd.Dispose(); cmd.Parameters.Clear(); SQL_Transact.CommitTransaction(connection, GUID); } catch { returnValue = false; // oreader.Close(); cmd.Dispose(); cmd.Parameters.Clear(); SQL_Transact.RollbackTransaction(connection, GUID); } } return(returnValue); }
public static bool Save(SqlConnection connection, Users_Model model) { bool returnValue = true; StringBuilder sQuery = new StringBuilder(); sQuery.Append(@"INSERT INTO a_Users (User_Name ,User_Email ,User_Access ,User_Domain ,User_Password) VALUES (@User_Name ,@User_Email ,@User_Access ,@User_Domain ,@User_Password)"); var GUID = SQL_Transact.GenerateGUID(); SQL_Transact.BeginTransaction(connection, GUID); using (SqlCommand cmd = new SqlCommand()) { try { cmd.Connection = connection; cmd.CommandText = sQuery.ToString(); cmd.CommandType = CommandType.Text; SqlParameter parm2 = new SqlParameter { ParameterName = "@User_Name", SqlDbType = SqlDbType.NVarChar, Value = model.User_Name }; cmd.Parameters.Add(parm2); SqlParameter parm3 = new SqlParameter { ParameterName = "@User_Email", SqlDbType = SqlDbType.NVarChar, Value = model.User_Email }; cmd.Parameters.Add(parm3); SqlParameter parm4 = new SqlParameter { ParameterName = "@User_Access", SqlDbType = SqlDbType.NVarChar, Value = model.User_Access }; cmd.Parameters.Add(parm4); SqlParameter parm5 = new SqlParameter { ParameterName = "@User_Domain", SqlDbType = SqlDbType.NVarChar, Value = model.User_Domain }; cmd.Parameters.Add(parm5); SqlParameter parm6 = new SqlParameter { ParameterName = "@User_Password", SqlDbType = SqlDbType.NVarChar, Value = model.User_Password }; cmd.Parameters.Add(parm6); if (cmd.ExecuteNonQuery() >= 1) { returnValue = true; cmd.Dispose(); cmd.Parameters.Clear(); SQL_Transact.CommitTransaction(connection, GUID); } } catch (Exception ex) { cmd.Dispose(); cmd.Parameters.Clear(); SQL_Transact.RollbackTransaction(connection, GUID); throw new ArgumentException(ex.Message); } } return(returnValue); }