public string validateInscription(Project project, string id) { string query = "UPDATE inscriptions SET Validated = true WHERE id_user = "******" AND id_project = " + project.Id; MySqlHelper.ExecuteNonQuery(Connection, query); deleteOtherApply(project, id); using (MySqlDataReader projectChecker = MySqlHelper.ExecuteReader(Connection, "SELECT id_user, title From projects WHERE id = '" + project.Id + "'")) { if (projectChecker.HasRows) { projectChecker.Read(); using (MySqlDataReader userChecker = MySqlHelper.ExecuteReader(Connection, "SELECT Email From users WHERE uniq_id = '" + projectChecker.GetString(0) + "'")) { if (userChecker.HasRows) { userChecker.Read(); string emailAddress = "*****@*****.**", password = "******"; var sender = new GmailDotComMail(emailAddress, password); sender.SendMail(userChecker.GetString(0), "Coding MarketPlace - inscription au projet", "Le projet : " + projectChecker.GetString(1) + " a bien été validé"); Notification notif = new Notification(); NotificationsController notifCtrl = new NotificationsController(); notif.Text = "Le projet : " + projectChecker.GetString(1) + "a bien été validé"; notif.UniqId = projectChecker.GetString(0); notifCtrl.createNotification(notif); } } } } return "ok"; }
public string createInscription(Project project, string id) { string query = "INSERT INTO inscriptions (Id, id_user, id_project, Validated) VALUES (NULL, " + id + ", " + project.Id + ", false)"; MySqlHelper.ExecuteNonQuery(Connection, query); using (MySqlDataReader projectChecker = MySqlHelper.ExecuteReader(Connection, "SELECT id_user, title From projects WHERE id = '" + project.Id + "'")) { if (projectChecker.HasRows) { projectChecker.Read(); using (MySqlDataReader userChecker = MySqlHelper.ExecuteReader(Connection, "SELECT Email From users WHERE uniq_id = '" + projectChecker.GetString(0) + "'")) { if (userChecker.HasRows) { userChecker.Read(); string emailAddress = "*****@*****.**", password = "******"; var sender = new GmailDotComMail(emailAddress, password); sender.SendMail(userChecker.GetString(0), "Coding MarketPlace - inscription au projet", "Un développeur s'est inscrit à votre projet : " + projectChecker.GetString(1)); Notification notif = new Notification(); NotificationsController notifCtrl = new NotificationsController(); notif.Text = "Un développeur s'est inscrit au projet : " + projectChecker.GetString(1); notif.UniqId = projectChecker.GetString(0); notifCtrl.createNotification(notif); } } } } return "ok"; }
public object ApplyToProject([FromBody] Project project, string id) { using (MySqlDataReader userChecker = MySqlHelper.ExecuteReader(Connection, "SELECT developper, Email From users WHERE uniq_id = '" + id + "'")) { if (userChecker.HasRows) { userChecker.Read(); if (userChecker.GetBoolean(0)) { InscriptionsController insc = new InscriptionsController(); if (insc.createInscription(project, id).Equals("ok")) { using (MySqlDataReader projectChecker = MySqlHelper.ExecuteReader(Connection, "SELECT title From projects WHERE id = '" + project.Id + "'")) { if (projectChecker.HasRows) { projectChecker.Read(); string emailAddress = "*****@*****.**", password = "******"; var sender = new GmailDotComMail(emailAddress, password); sender.SendMail(userChecker.GetString(1), "Coding MarketPlace - inscription", "Votre inscription au projet : " + projectChecker.GetString(0) + " a bien été prise en compte"); Notification notif = new Notification(); NotificationsController notifCtrl = new NotificationsController(); notif.Text = "Vous êtes bien inscrit au projet : " + projectChecker.GetString(0); notif.UniqId = id; notifCtrl.createNotification(notif); } } return Request.CreateResponse(HttpStatusCode.Created, "Inscription to project successful"); } else { return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error, inscription to project denied"); } } else { return Request.CreateResponse(HttpStatusCode.BadRequest, "You are not a developper"); } } } return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error, could not proceed to inscription"); }
public object Validate([FromBody] Project project, string id) { using (MySqlDataReader userChecker = MySqlHelper.ExecuteReader(Connection, "SELECT uniq_id, Email From users WHERE uniq_id = '" + id + "'")) { if (userChecker.HasRows) { userChecker.Read(); InscriptionsController insc = new InscriptionsController(); if (insc.validateInscription(project, id).Equals("ok")) { using (MySqlDataReader projectChecker = MySqlHelper.ExecuteReader(Connection, "SELECT title From projects WHERE id = '" + project.Id + "'")) { if (projectChecker.HasRows) { projectChecker.Read(); string emailAddress = "*****@*****.**", password = "******"; var sender = new GmailDotComMail(emailAddress, password); sender.SendMail(userChecker.GetString(1), "Coding MarketPlace - validation", "Vous avez été retenu pour travailler sur le projet : " + projectChecker.GetString(0) + ""); Notification notif = new Notification(); NotificationsController notifCtrl = new NotificationsController(); notif.Text = "Vous avez été retenu pour travailler sur le projet : " + projectChecker.GetString(0); notif.UniqId = project.IdUser; notifCtrl.createNotification(notif); string query = "UPDATE projects SET started = true WHERE id = '" + project.Id + "'"; MySqlHelper.ExecuteNonQuery(Connection, query); } } return Request.CreateResponse(HttpStatusCode.OK, "Project has been validated"); } else { return Request.CreateResponse(HttpStatusCode.BadRequest, "You are not the project owner"); } } } return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error, could not proceed to validation"); }
public object FinishProject([FromBody] Project project, string id) { using (MySqlDataReader userChecker = MySqlHelper.ExecuteReader(Connection, "SELECT id, Email From users WHERE uniq_id = '" + id + "'")) { if (userChecker.HasRows) { userChecker.Read(); string query = "UPDATE projects SET over = true WHERE id = '" + project.Id + "'"; MySqlHelper.ExecuteNonQuery(Connection, query); using (MySqlDataReader projectChecker = MySqlHelper.ExecuteReader(Connection, "SELECT title From projects WHERE id = '" + project.Id + "'")) { if (projectChecker.HasRows) { projectChecker.Read(); string emailAddress = "*****@*****.**", password = "******"; var sender = new GmailDotComMail(emailAddress, password); sender.SendMail(userChecker.GetString(1), "Coding MarketPlace - Fin", "Le projet : " + projectChecker.GetString(0) + " est terminé"); Notification notif = new Notification(); NotificationsController notifCtrl = new NotificationsController(); notif.Text = "Le projet : " + projectChecker.GetString(0) + "est terminé"; notif.UniqId = id; notifCtrl.createNotification(notif); } } using (MySqlDataReader projectChecker = MySqlHelper.ExecuteReader(Connection, "SELECT id_user, title From projects WHERE id = '" + project.Id + "'")) { if (projectChecker.HasRows) { projectChecker.Read(); using (MySqlDataReader finalUserChecker = MySqlHelper.ExecuteReader(Connection, "SELECT Email From users WHERE uniq_id = '" + projectChecker.GetString(0) + "'")) { if (finalUserChecker.HasRows) { finalUserChecker.Read(); string emailAddress = "*****@*****.**", password = "******"; var sender = new GmailDotComMail(emailAddress, password); sender.SendMail(finalUserChecker.GetString(0), "Coding MarketPlace - Fin", "Le projet : " + projectChecker.GetString(1) + " est terminé"); Notification notif = new Notification(); NotificationsController notifCtrl = new NotificationsController(); notif.Text = "Le projet : " + projectChecker.GetString(1) + "est terminé"; notif.UniqId = projectChecker.GetString(0); notifCtrl.createNotification(notif); } } } } return Request.CreateResponse(HttpStatusCode.OK); } } return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error"); }