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 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";
        }
Ejemplo n.º 3
0
        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 getAllNotificationsForUser(string id)
        {
            List<Notification> notifications = new List<Notification>();

            string query = "SELECT id_user, texte, already_read From notifications where id_user = '******'";

            using (MySqlDataReader reader = MySqlHelper.ExecuteReader(Connection, query))
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Notification notification = new Notification();
                        notification.UniqId = reader.GetString(0);
                        notification.Text = reader.GetString(1);
                        notification.Read = reader.GetBoolean(2);
                        notifications.Add(notification);
                    }
                    return Request.CreateResponse(HttpStatusCode.OK, notifications);
                }
            }
            return Request.CreateResponse(HttpStatusCode.InternalServerError, "Internal server error");
        }
        public void createNotification(Notification notif)
        {
            using (MySqlDataReader userChecker = MySqlHelper.ExecuteReader(Connection, "SELECT id From users WHERE uniq_id = '" + notif.UniqId + "'"))
            {
                if (userChecker.HasRows)
                {
                    userChecker.Read();
                    if (userChecker.GetBoolean(0))
                    {
                        string query = "INSERT INTO notifications (Id, id_user, texte, already_read) VALUES (NULL, @userId, @text, 0)";

                        DateTime localDate = DateTime.Now;

                        // Create the parameters
                        List<MySqlParameter> parms = new List<MySqlParameter>();
                        parms.Add(new MySqlParameter("userId", notif.UniqId));
                        parms.Add(new MySqlParameter("text", notif.Text));

                        MySqlHelper.ExecuteNonQuery(Connection, query, parms.ToArray());
                    }
                }
            }
        }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
        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");
        }