コード例 #1
0
        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";
        }
コード例 #2
0
        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";
        }
コード例 #3
0
 public string deleteOtherApply(Project project, string id)
 {
     string query = "DELETE FROM inscriptions WHERE id_project = " + project.Id + " AND id_user != " + project.IdUser;
     MySqlHelper.ExecuteNonQuery(Connection, query);
     return "ok";
 }
コード例 #4
0
 public object GetUserProjects(string id)
 {
     using (MySqlDataReader projectGetter = MySqlHelper.ExecuteReader(Connection, "SELECT id_project From inscriptions WHERE id_user = "******"SELECT title, description, duration, budget, id_user, image_url, creation_date, over, id From projects WHERE id = " + theId))
                 {
                     if (reader.HasRows)
                     {
                         while (reader.Read())
                         {
                             Project project = new Project();
                             project.Title = reader.GetString(0);
                             project.Description = reader.GetString(1);
                             project.Duration = reader.GetInt32(2);
                             project.Budget = reader.GetInt32(3);
                             project.IdUser = reader.GetString(4);
                             project.ImageUrl = reader.GetString(5);
                             project.CreationDate = reader.GetDateTime(6);
                             project.over = reader.GetBoolean(7);
                             project.Id = reader.GetInt32(8);
                             projects.Add(project);
                         }
                     }
                 }
             }
             return Request.CreateResponse(HttpStatusCode.OK, projects);
         }
         return Request.CreateResponse(HttpStatusCode.BadRequest, "wrong id");
     }
 }
コード例 #5
0
 public object GetUserCreatedProjects(string id)
 {
     using (MySqlDataReader userGetter = MySqlHelper.ExecuteReader(Connection, "SELECT project_creator From users WHERE uniq_id = '" + id + "'"))
     {
         if (userGetter.HasRows)
         {
             userGetter.Read();
             if (userGetter.GetBoolean(0) == true)
             {
                 List<Project> projects = new List<Project>();
                 using (MySqlDataReader reader = MySqlHelper.ExecuteReader(Connection, "SELECT title, description, duration, budget, image_url, creation_date, over, id From projects WHERE id_user = '******'"))
                 {
                     if (reader.HasRows)
                     {
                         while (reader.Read())
                         {
                             Project project = new Project();
                             project.Title = reader.GetString(0);
                             project.Description = reader.GetString(1);
                             project.Duration = reader.GetInt32(2);
                             project.Budget = reader.GetInt32(3);
                             project.ImageUrl = reader.GetString(4);
                             project.CreationDate = reader.GetDateTime(5);
                             project.over = reader.GetBoolean(6);
                             project.Id = reader.GetInt32(7);
                             projects.Add(project);
                         }
                     }
                 }
                 return Request.CreateResponse(HttpStatusCode.OK, projects);
             }
             else
             {
                 return Request.CreateResponse(HttpStatusCode.BadRequest, "You are not a project creator");
             }
         }
         return Request.CreateResponse(HttpStatusCode.InternalServerError, "An Error occured");
     }
 }
コード例 #6
0
 public object GetProjectDetail(string id)
 {
     Project response = new Project();
     using (MySqlDataReader reader = MySqlHelper.ExecuteReader(Connection, "SELECT title, description, duration, budget, id_user, image_url, creation_date, over, started From projects WHERE id = " + id))
     {
         if (reader.HasRows)
         {
             reader.Read();
             response.Title = reader.GetString(0);
             response.Description = reader.GetString(1);
             response.Duration = reader.GetInt32(2);
             response.Budget = reader.GetInt32(3);
             response.IdUser = reader.GetString(4);
             response.ImageUrl = reader.GetString(5);
             response.CreationDate = reader.GetDateTime(6);
             response.Id = Int32.Parse(id);
             response.over = reader.GetBoolean(7);
             response.started = reader.GetBoolean(8);
             return Request.CreateResponse(HttpStatusCode.OK, response);
         }
         else
         {
             return Request.CreateResponse(HttpStatusCode.BadRequest, "wrong id");
         }
     }
 }
コード例 #7
0
        public object getAllProjectsForUser(string id)
        {
            List<Project> projects = new List<Project>();

            using (MySqlDataReader inscChecker = MySqlHelper.ExecuteReader(Connection, "SELECT id_project FROM inscriptions WHERE id_user = '******'"))
            {
                if (inscChecker.HasRows)
                {
                    while (inscChecker.Read())
                    {
                        int theId = inscChecker.GetInt32(0);
                        string query = "SELECT title, description, duration, budget, id_user, image_url, creation_date, id, over, started From projects where id = " + theId + "";

                        using (MySqlDataReader reader = MySqlHelper.ExecuteReader(Connection, query))
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();
                                Project project = new Project();
                                project.Title = reader.GetString(0);
                                project.Description = reader.GetString(1);
                                project.Duration = reader.GetInt32(2);
                                project.Budget = reader.GetInt32(3);
                                project.IdUser = reader.GetString(4);
                                project.ImageUrl = reader.GetString(5);
                                project.CreationDate = reader.GetDateTime(6);
                                project.Id = reader.GetInt32(7);
                                project.over = reader.GetBoolean(8);
                                project.started = reader.GetBoolean(9);
                                projects.Add(project);
                            }
                        }
                    }
                    return Request.CreateResponse(HttpStatusCode.OK, projects);
                }
            }
            return Request.CreateResponse(HttpStatusCode.InternalServerError, "Internal server error");
        }