public int requestAccept(int userId, Int64 requestId) { int status = 0; DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString); SqlDataAdapter sda = new SqlDataAdapter("sp_requestInfo", sqlConn); sda.SelectCommand.CommandType = CommandType.StoredProcedure; sda.SelectCommand.Parameters.Add("@OwnerId", SqlDbType.Int).Value = userId; sda.SelectCommand.Parameters.Add("@RequestId", SqlDbType.BigInt).Value = requestId; try { sda.Fill(ds); dt = ds.Tables[0]; } catch (Exception ex) { } finally { sqlConn.Close(); sda.Dispose(); sqlConn.Dispose(); } if (dt.Rows.Count != 0)// request exists { int userId1 = Convert.ToInt32(dt.Rows[0]["UserId"].ToString()); Int64 eventId = Convert.ToInt64(dt.Rows[0]["EventId"].ToString()); SqlConnection sqlConn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString); SqlCommand sqlCmd1 = new SqlCommand("sp_requestAccept", sqlConn1); sqlCmd1.CommandType = CommandType.StoredProcedure; sqlCmd1.Parameters.Add("@OwnerId", SqlDbType.Int).Value = userId; sqlCmd1.Parameters.Add("@RequestId", SqlDbType.BigInt).Value = requestId; sqlCmd1.Parameters.Add("@EventId", SqlDbType.BigInt).Value = eventId; sqlCmd1.Parameters.Add("@UserId", SqlDbType.Int).Value = userId1; try { sqlConn1.Open(); sqlCmd1.ExecuteNonQuery(); } catch (Exception ex) { } finally { sqlConn1.Close(); sqlCmd1.Dispose(); sqlConn1.Dispose(); } // add notification Classes.Notifications n = new Classes.Notifications(); n.notificationAdd(userId1, 2, eventId); Classes.Events ev = new Classes.Events(); int remained = ev.eventParticipantsRemained(eventId); if (remained == 0) { n.notificationAdd(userId, 3, eventId); } status = 1; } else { status = -1; } return(status); }
public int requestAccept(int userId, Int64 requestId) { int status = 0; DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString); SqlDataAdapter sda = new SqlDataAdapter("sp_requestInfo", sqlConn); sda.SelectCommand.CommandType = CommandType.StoredProcedure; sda.SelectCommand.Parameters.Add("@OwnerId", SqlDbType.Int).Value = userId; sda.SelectCommand.Parameters.Add("@RequestId", SqlDbType.BigInt).Value = requestId; try { sda.Fill(ds); dt = ds.Tables[0]; } catch (Exception ex) { } finally { sqlConn.Close(); sda.Dispose(); sqlConn.Dispose(); } if (dt.Rows.Count != 0)// request exists { int userId1 = Convert.ToInt32(dt.Rows[0]["UserId"].ToString()); Int64 eventId = Convert.ToInt64(dt.Rows[0]["EventId"].ToString()); SqlConnection sqlConn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString); SqlCommand sqlCmd1 = new SqlCommand("sp_requestAccept", sqlConn1); sqlCmd1.CommandType = CommandType.StoredProcedure; sqlCmd1.Parameters.Add("@OwnerId", SqlDbType.Int).Value = userId; sqlCmd1.Parameters.Add("@RequestId", SqlDbType.BigInt).Value = requestId; sqlCmd1.Parameters.Add("@EventId", SqlDbType.BigInt).Value = eventId; sqlCmd1.Parameters.Add("@UserId", SqlDbType.Int).Value = userId1; try { sqlConn1.Open(); sqlCmd1.ExecuteNonQuery(); } catch (Exception ex) { } finally { sqlConn1.Close(); sqlCmd1.Dispose(); sqlConn1.Dispose(); } // add notification Classes.Notifications n = new Classes.Notifications(); n.notificationAdd(userId1, 2, eventId); Classes.Events ev = new Classes.Events(); int remained = ev.eventParticipantsRemained(eventId); if (remained == 0) { n.notificationAdd(userId, 3, eventId); } status = 1; } else { status = -1; } return status; }