private void Follow(object sender, EventArgs e, string project) { // need a timestamp for the notification, also needs some leeway as sending to the server may take a second // or more depending on connection. DateTime timestamp = DateTime.Now; string stringTime = timestamp.ToString("yyyy-MM-dd HH:mm:ss");; string toStringTime = timestamp.AddSeconds(5).ToString("yyyy-MM-dd HH:mm:ss"); // create a follow project object which will notify the project poster that a user wants access SqlFollow sq = new SqlFollow(); Connection.GetDbConn().CreateCommand(SqlFollow.FollowProject(UserObject.loggedUser.iduser, currentProject)); // has to create a notification with relevant deatils SqlNotifications notif = new SqlNotifications(); notif.InsertNotification(UserObject.loggedUser.iduser, project, "", "", "follow", "", timestamp); // have to get the new notif's id to make a toNotif object, have to use time here as its possible // that a user might make multiple requests or might follow, unfollow, then want back in DataSet getNotifId = Connection.GetDbConn().GetDataSet($"SELECT idnotification FROM notification" + $" WHERE usernotif = {UserObject.loggedUser.iduser} AND project = {project} AND timestamp BETWEEN '{stringTime}' AND '{toStringTime}' "); string newNotifId = getNotifId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString(); // need to get the project owner's id DataSet projectOwner = Connection.GetDbConn().GetDataSet($"SELECT user FROM project WHERE idproject = {project}"); string ownerId = projectOwner.Tables[0].Rows[0].ItemArray.GetValue(0).ToString(); notif.InsertToNotify(newNotifId, ownerId, "0"); MessageBox.Show("Followed"); //catch (Exception) //{ // MessageBox.Show("Request already sent"); //} }
private void RequestAccess(object sender, EventArgs e, ProjectObject project) { // create a follow project object which will notify the project poster that a user wants access try { // creates follow table row, as this is a private project (public projects are followed on bugsform) // sends a notification to the poster of the project to advise the user wants access. DateTime now = DateTime.Now; string timestamp = now.ToString("yyyy-MM-dd HH:mm:ss"); string timestampTo = now.AddSeconds(5).ToString("yyyy-MM-dd HH:mm:ss"); SqlProject sq = new SqlProject(); SqlNotifications notif = new SqlNotifications(); Connection.GetDbConn().CreateCommand(SqlFollow.FollowProject(UserObject.loggedUser.iduser, project.idproject)); notif.InsertNotification(UserObject.loggedUser.iduser, project.idproject, "", "", "request access", "", now); DataSet getNotifId = Connection.GetDbConn().GetDataSet($"SELECT idnotification FROM notification" + $" WHERE usernotif = {UserObject.loggedUser.iduser} AND project = {project.idproject} AND timestamp BETWEEN '{timestamp}' AND '{timestampTo}'"); string notifId = getNotifId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString(); DataSet getProjectOwner = Connection.GetDbConn().GetDataSet($"SELECT user FROM project WHERE idproject = { project.idproject}"); string projOwner = getProjectOwner.Tables[0].Rows[0].ItemArray.GetValue(0).ToString(); notif.InsertToNotify(notifId, projOwner, "0"); MessageBox.Show("Request sent to project creator"); } catch (Exception) { MessageBox.Show("Request already sent"); } }