Пример #1
0
        /// <summary>
        /// Ajout d'un utilisateur
        /// </summary>
        /// <param name="user">Utilisateur à ajouter</param>
        /// <returns>Vrai si tous c'est bien passé faux sinon</returns>
        public bool Add(User user)
        {
            if(user == null || mailExist(user.Email))
            {
                return false;
            }
            string query = "INSERT INTO user (first_name,last_name,gender,birth_date,email,phone,pwd,image,role) VALUES (@first_name,@last_name,@gender,@birth,@email,@phone,@pwd,@image,@role)";

            List<MySqlParameter> parms = new List<MySqlParameter>();
            parms.Add(new MySqlParameter("first_name", user.FirstName));
            parms.Add(new MySqlParameter("last_name", user.LastName));
            parms.Add(new MySqlParameter("gender", user.Gender));
            parms.Add(new MySqlParameter("birth", user.BirthDate));
            parms.Add(new MySqlParameter("email", user.Email));
            parms.Add(new MySqlParameter("phone", user.Phone));
            parms.Add(new MySqlParameter("pwd", CreateSHAHash(user.Password)));
            parms.Add(new MySqlParameter("image", user.Image));
            parms.Add(new MySqlParameter("role", user.Role));

            MySqlHelper.ExecuteNonQuery(connexion, query, parms.ToArray());

            Mail send = new Mail();
            send.SendSimpleMessage(user.Email,"Inscription","Vous êtes maintenant inscrit à dance coach");

            return true;
        }
Пример #2
0
        /// <summary>
        /// Ajoute un utilisateur à la lesson
        /// </summary>
        /// <param name="userId">Id utilisateur</param>
        /// <param name="lessonId">Id de la lesson</param>
        /// <returns>Vrai si tout c'est bien passer, fauw sinon</returns>
        public bool Book(int userId, int lessonId)
        {
            string email = null;
            UserRepository _repositoryUser = new UserRepository();
            if(_repositoryUser.GetPublic(userId).FirstName != "" && this.Get(lessonId).Title != "")
            {
                //We add the user in the lesson
                string query = "INSERT INTO booking (user_id,lesson_id) VALUES (@user,@lesson)";

                List<MySqlParameter> parms = new List<MySqlParameter>();
                parms.Add(new MySqlParameter("user", userId));
                parms.Add(new MySqlParameter("lesson", lessonId));

                MySqlHelper.ExecuteNonQuery(connexion, query, parms.ToArray());

                //We update the nb_free and nb_booked
                string queryIncrementeLesson = "UPDATE lesson SET nb_free-=1, nb_booked+=1 WHERE [email protected]";
                List<MySqlParameter> parmsIncre = new List<MySqlParameter>();
                parmsIncre.Add(new MySqlParameter("lessonid", lessonId));

                MySqlHelper.ExecuteNonQuery(connexion, queryIncrementeLesson, parmsIncre.ToArray());

                string queryUserForEmail = "SELECT email FROM user WHERE id ="+userId;

                using (MySqlDataReader reader = MySqlHelper.ExecuteReader(connexion, queryUserForEmail))
                {
                    // Check if the reader returned any rows
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            email = reader.GetString(0);
                        }
                    }
                }

                Mail send = new Mail();
                send.SendSimpleMessage(email, "Inscription à une leçon", "Vous êtes maintenant inscrit à une leçon");
                return true;
            }
            return false;
        }