Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
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");
        }