public string GetAllUser() { IUserRepository user = new UserRepository(); var result = user.GetAll(); var json = new JavaScriptSerializer().Serialize(result); return json; }
/// <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 id=@lessonid"; 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; }
public HttpResponseMessage PostUserUpdate([FromBody] User user ) { IUserRepository manageUser = new UserRepository(); var result = manageUser.Update(user); return Request.CreateResponse(HttpStatusCode.OK, result); }
public HttpResponseMessage PostUserConnect([FromBody] User user ) { IUserRepository manageUser = new UserRepository(); var result = manageUser.GetId(user.Email, user.Password); return Request.CreateResponse(HttpStatusCode.OK, result); }
public string GetUserPrivate(int id) { IUserRepository user = new UserRepository(); var result = user.GetPrivate(id); var json = new JavaScriptSerializer().Serialize(result); return json; }
public string GetUserByMail([FromBody] User user) { IUserRepository manageUser = new UserRepository(); var result = manageUser.GetUserByMail(user.Email); var json = new JavaScriptSerializer().Serialize(result); return json; }
/// <summary> /// Récupère toutes les lessons à venir d'un utilisateur /// </summary> /// <param name="userId">l'id de l'utilisateur</param> /// <returns>Les lessons à venir de l'utilisateur</returns> public IEnumerable<Lesson> GetLessonByUserInFewTime(int userId) { UserRepository _repositoryUser = new UserRepository(); List<Lesson> lessons = new List<Lesson>(); if (_repositoryUser.GetPublic(userId).FirstName != "") { string query = "SELECT id,description,price,title,c.name,start_date,end_date,u.id as userid,first_name,last_name,image FROM lesson as l JOIN category as c ON c.id = l.category_id JOIN user as u ON u.id = l.user_id WHERE user_id=" + userId+" start_date>="+DateTime.Now; using (MySqlDataReader reader = MySqlHelper.ExecuteReader(connexion, query)) { // Check if the reader returned any rows if (reader.HasRows) { while (reader.Read()) { Lesson lesson = new Lesson(); User author = new User(); Categorie cat = new Categorie(); lesson.LessonId = reader.GetInt16(0); lesson.description = reader.GetString(1); lesson.Price = reader.GetFloat(2); lesson.Title = reader.GetString(3); cat.Name = reader.GetString(4); lesson.DateStart = reader.GetDateTime(5).ToString("MM/dd/yyyy HH:mm"); lesson.DateEnd = reader.GetDateTime(6).ToString("MM/dd/yyyy HH:mm"); author.UserId = reader.GetInt16(7); author.FirstName = reader.GetString(8); author.LastName = reader.GetString(9); author.Image = reader.GetValue(10).ToString(); lesson.Author = author; lesson.Categorie = cat; lessons.Add(lesson); } } } } return lessons; }