public void GetNbRetardsExcusesTest() { Etudiant et1 = new Etudiant(1, "Enzo"); Etudiant et2 = new Etudiant(2, "Noa"); Motif motif1 = new Motif(1, "Malade grippe"); Motif motif2 = new Motif(2, "Pas envie"); Retard retard1 = new Retard(1, DateTime.Now.ToShortDateString(), motif1, false); Retard retard2 = new Retard(2, DateTime.Now.ToShortDateString(), motif2, true); Retard retard3 = new Retard(3, DateTime.Now.ToShortDateString(), motif2, true); Retard retard4 = new Retard(4, DateTime.Now.ToShortDateString(), motif2, true); Retard retard5 = new Retard(5, DateTime.Now.ToShortDateString(), motif2, true); et1.AjouterRetard(retard1); et1.AjouterRetard(retard2); et1.AjouterRetard(retard3); et1.AjouterRetard(retard4); et1.AjouterRetard(retard5); Assert.AreEqual(4, et1.GetNbRetardsExcuses()); }
/// <summary> /// Méthode permettant la création d'un retard. /// </summary> /// <param name="retard">Eleve que l'on souhaite créer dans la base.</param> public static void Create(Retard retard) { string query = "INSERT INTO Retard (id, titre, description, file, idEleve) VALUES (null, @titre, @description, @file, @idEleve)"; // Open connection databaseConnexion connection = new databaseConnexion(); if (connection.OpenConnection() == true) { // Create Command using (MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection())) { // shield sql injection cmd.Parameters.AddWithValue("@titre", retard.titre); cmd.Parameters.AddWithValue("@description", retard.description); cmd.Parameters.AddWithValue("@file", retard.file); cmd.Parameters.AddWithValue("idEleve", retard.eleve.id); // close Connection int result = cmd.ExecuteNonQuery(); connection.CloseConnection(); } } }
public ActionResult DeleteConfirmed(long id) { Retard retard = db.Retard.Find(id); db.Retard.Remove(retard); db.SaveChanges(); return(RedirectToAction("Index")); }
private void Window_Loaded(object sender, RoutedEventArgs e) { mesClasses = new List <Classe>(); mesEtudiants = new List <Etudiant>(); Classe sio1 = new Classe(1, "SIO1"); Classe sio2 = new Classe(2, "SIO2"); Etudiant et1 = new Etudiant(1, "Enzo"); Etudiant et2 = new Etudiant(2, "Noa"); Etudiant et3 = new Etudiant(3, "Lilou"); Etudiant et4 = new Etudiant(4, "Milo"); Motif motif1 = new Motif(1, "Malade grippe"); Motif motif2 = new Motif(2, "Pas envie"); Motif motif3 = new Motif(3, "Problème transport"); Motif motif4 = new Motif(4, "RER A"); Motif motif5 = new Motif(5, "Mariage de mon frère"); Retard retard1 = new Retard(1, DateTime.Now.ToShortDateString(), motif1, false); Retard retard2 = new Retard(2, DateTime.Now.ToShortDateString(), motif2, true); Retard retard3 = new Retard(3, DateTime.Now.ToShortDateString(), motif3, true); Retard retard4 = new Retard(4, DateTime.Now.ToShortDateString(), motif2, true); Retard retard5 = new Retard(5, DateTime.Now.ToShortDateString(), motif3, false); Retard retard6 = new Retard(6, DateTime.Now.ToShortDateString(), motif3, false); Retard retard7 = new Retard(7, DateTime.Now.ToShortDateString(), motif3, false); Retard retard8 = new Retard(8, DateTime.Now.ToShortDateString(), motif4, false); Retard retard9 = new Retard(9, DateTime.Now.ToShortDateString(), motif5, true); Retard retard10 = new Retard(10, DateTime.Now.ToShortDateString(), motif4, false); Retard retard11 = new Retard(11, DateTime.Now.ToShortDateString(), motif5, false); Retard retard12 = new Retard(12, DateTime.Now.ToShortDateString(), motif4, false); Retard retard13 = new Retard(13, DateTime.Now.ToShortDateString(), motif4, false); Retard retard14 = new Retard(14, DateTime.Now.ToShortDateString(), motif5, false); Retard retard15 = new Retard(15, DateTime.Now.ToShortDateString(), motif2, true); et1.AjouterRetard(retard1); et1.AjouterRetard(retard2); et1.AjouterRetard(retard3); et2.AjouterRetard(retard4); et2.AjouterRetard(retard5); et3.AjouterRetard(retard6); et3.AjouterRetard(retard7); et3.AjouterRetard(retard8); et3.AjouterRetard(retard9); et4.AjouterRetard(retard10); et4.AjouterRetard(retard11); et4.AjouterRetard(retard12); et4.AjouterRetard(retard13); et4.AjouterRetard(retard14); et4.AjouterRetard(retard15); sio1.AjouterEtudiant(et1); sio1.AjouterEtudiant(et2); sio2.AjouterEtudiant(et3); sio2.AjouterEtudiant(et4); mesClasses.Add(sio1); mesClasses.Add(sio2); mesEtudiants.Add(et1); mesEtudiants.Add(et2); mesEtudiants.Add(et3); mesEtudiants.Add(et4); lvClasses.ItemsSource = mesClasses; lvEtudiants.ItemsSource = mesEtudiants; }
public ActionResult Edit([Bind(Include = "id,titre,description,idEleve,pj")] Retard retard) { if (ModelState.IsValid) { db.Entry(retard).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idEleve = new SelectList(db.Eleve, "id", "pseudo", retard.idEleve); return(View(retard)); }
public ActionResult GetRetardsByTags(int nbRetard) { List <TopXRetard> listTop100Retard = RetardRequest.GetTopX(Convert.ToInt32(User.Identity.Name), 100); ObservableCollection <Retard> listRetard = new ObservableCollection <Retard>(); foreach (TopXRetard element in listTop100Retard) { Retard retard = new Retard(element.id, element.titre, element.description, element.file, Convert.ToInt32(element.eleve.id), Convert.ToInt32(User.Identity.Name)); listRetard.Add(retard); } return(Json(listRetard, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(Retard retard) { if (ModelState.IsValid) { retard.file = Request["fileEnvoie"]; retard.eleve = EleveRequest.GetEleveById(Convert.ToInt64(Request["Eleve"])); RetardRequest.Update(retard); return(RedirectToAction("Index", "Home")); } ViewBag.Retards_Tags = new SelectList(TagsRequest.GetTags(), "id", "libelle"); //ViewBag.Eleve = new SelectList(EleveRequest.GetEleves(), "id", "pseudo"); return(View()); }
// GET: Retards/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Retard retard = db.Retard.Find(id); if (retard == null) { return(HttpNotFound()); } return(View(retard)); }
// GET: Retards/Edit/5 public ActionResult Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Retard retard = db.Retard.Find(id); if (retard == null) { return(HttpNotFound()); } ViewBag.idEleve = new SelectList(db.Eleve, "id", "pseudo", retard.idEleve); return(View(retard)); }
public ActionResult CreateRetard(HttpPostedFileBase file) { if (Request.HttpMethod == "POST") { Retard retard = new Retard(); User user = ((List <User>)Session["users"]).First(); DateTime date = DateTime.Today; string motif = Request.Form.Get("motif"); if (file != null && file.ContentLength > 0) { try { string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName)); file.SaveAs(path); ViewBag.Message = "File uploaded successfully"; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } else { ViewBag.Message = "You have not specified a file."; } string photo = file.FileName; retard.Date = date; retard.User = user; retard.Motif = motif; retard.Photo = "/Images/" + photo; List <Retard> listRetards = (List <Retard>)Session["Retards"]; if (listRetards == null) { listRetards = new List <Retard>(); } listRetards.Add(retard); Session["Retards"] = listRetards; } return(View()); }
/// <summary> /// Méthode permettant de recuperer un retard. /// </summary> /// <param name="idRetard">Id du retard que l'on souhaite recuperer.</param> /// <returns>Retourne un retard.</returns> public static List <Retard> getRetardByEleve(int idEleve) { List <Retard> retards = new List <Retard>(); string query = "SELECT * FROM retard where idEleve=@idEleve;"; // Open connection databaseConnexion connection = new databaseConnexion(); if (connection.OpenConnection() == true) { // Create Command using (MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection())) { // shield sql injection cmd.Parameters.AddWithValue("@idEleve", idEleve); // Create a data reader and Execute the command using (MySqlDataReader dataReader = cmd.ExecuteReader()) { // Read the data and store them in the list while (dataReader.Read()) { Retard retard = new Retard(dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetString(2), dataReader.GetString(3), dataReader.GetInt32(4)); retards.Add(retard); } // close Data Reader dataReader.Close(); } // close Connection connection.CloseConnection(); } // return list to be displayed } return(retards); }
public void Create([Bind(Include = "id,titre,description,Retards_Tags,pj")] Retard retard) { if (ModelState.IsValid) { retard.Retards_Tags.Add(new Retards_Tags { Id_Retard = retard.id, Id_Tags = Int32.Parse(Request["Retards_Tags"]) }); retard.idEleve = Convert.ToInt64(User.Identity.Name); db.Retard.Add(retard); //db.Retards_Tags.Add() db.SaveChanges(); Response.Redirect("/Home"); } else { } ViewBag.idEleve = new SelectList(db.Eleve, "id", "pseudo", retard.idEleve); }
/// <summary> /// Méthode permettant de recuperer un retard. /// </summary> /// <param name="idRetard">Id du retard que l'on souhaite recuperer.</param> /// <returns>Retourne un retard.</returns> public static Retard getLastRetard(Retard retardrecup) { Retard retard = null; string query = "SELECT * FROM `retard` WHERE titre = @titre and description = @description order BY titre DESC LIMIT 1 ;"; // Open connection databaseConnexion connection = new databaseConnexion(); if (connection.OpenConnection() == true) { // Create Command using (MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection())) { // shield sql injection cmd.Parameters.AddWithValue("@titre", retardrecup.titre); cmd.Parameters.AddWithValue("@description", retardrecup.description); // Create a data reader and Execute the command using (MySqlDataReader dataReader = cmd.ExecuteReader()) { // Read the data and store them in the list while (dataReader.Read()) { retard = new Retard(dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetString(2), dataReader.GetString(3), dataReader.GetInt32(4)); } // close Data Reader dataReader.Close(); } // close Connection connection.CloseConnection(); } // return list to be displayed } return(retard); }
public ActionResult Create([Bind(Include = "id,titre,description,Retards_Tags,pj")] Retard retard) { if (ModelState.IsValid) { retard.file = Request["fileEnvoie"]; retard.eleve = EleveRequest.GetEleveById(Int32.Parse(User.Identity.Name)); RetardRequest.Create(retard); retard = RetardRequest.getLastRetard(retard); Retards_Tags rt = new Retards_Tags { Id_Retard = retard.id, Id_Tags = Int32.Parse(Request["Retards_Tags"]) }; Tags_RetardRequest.Create(rt); return(RedirectToAction("Index", "Home")); } ViewBag.Retards_Tags = new SelectList(TagsRequest.GetTags(), "id", "libelle"); //ViewBag.Eleve = new SelectList(EleveRequest.GetEleves(), "id", "pseudo"); return(View()); }
/// <summary> /// Méthode permettant la mise a jour d'un retard. /// </summary> /// <param name="retard">Retard que l'on souhaite mettre a jour.</param> public static void Update(Retard retard) { string query = "Update retard set titre = @titre , description = @description , file = @file WHERE id = @id"; // Open connection databaseConnexion connection = new databaseConnexion(); if (connection.OpenConnection() == true) { // Create Command using (MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection())) { // shield sql injection cmd.Parameters.AddWithValue("@id", retard.id); cmd.Parameters.AddWithValue("@titre", retard.titre); cmd.Parameters.AddWithValue("@description", retard.description); cmd.Parameters.AddWithValue("@file", retard.file); // close Connection int result = cmd.ExecuteNonQuery(); connection.CloseConnection(); } } }
// GET: Home/updatevote/{idretard}/{isupvote} public ActionResult Updatevote(long id, int value) { Retard retard = db.Retard.Find(id); long idUserConnected = Int64.Parse(User.Identity.Name); // Query for all blogs with names starting with B var vote_Eleves = db.Vote_Eleve .Where(v => v.idEleve == idUserConnected && v.idRetard == id) .FirstOrDefault(); string messageRetour = ""; if (vote_Eleves != null) { vote_Eleves.dateVote = DateTime.Now; if (value > 0) { if (vote_Eleves.valeur == true) { db.Vote_Eleve.Remove(vote_Eleves); messageRetour = "Vote supprimé"; } else { vote_Eleves.valeur = true; messageRetour = "Vote modifié"; } } else { if (vote_Eleves.valeur == false) { db.Vote_Eleve.Remove(vote_Eleves); messageRetour = "Vote supprimé"; } else { vote_Eleves.valeur = false; messageRetour = "Vote modifié"; } } db.SaveChanges(); return(Json(new { success = true, message = messageRetour, nbNewVotes = retard.getNbVotes() }, JsonRequestBehavior.AllowGet)); } else if (value > 0) { Vote_Eleve newVote_Eleves = new Vote_Eleve() { idEleve = idUserConnected, idRetard = id, dateVote = DateTime.Now, valeur = true }; db.Vote_Eleve.Add(newVote_Eleves); messageRetour = "Up vote"; } else { Vote_Eleve newVote_Eleves = new Vote_Eleve() { idEleve = idUserConnected, idRetard = id, dateVote = DateTime.Now, valeur = false }; db.Vote_Eleve.Add(newVote_Eleves); messageRetour = "Down vote"; } db.SaveChanges(); return(Json(new { success = true, message = messageRetour, nbNewVotes = retard.getNbVotes() }, JsonRequestBehavior.AllowGet)); }
public ActionResult Afficher(FormCollection collection) { bool trouve = false; String uneLigne; Retard nouvRetard = new Retard(); String[] unAttribut; Char unDelimiteur = ','; var listeEnRetard = new List <Retard> { }; var tousLesRetards = new List <Retard> { }; if (System.IO.File.Exists(Server.MapPath(@"~/App_Data/prets.txt"))) { StreamReader fichierRetards = new StreamReader(Server.MapPath(@"~/App_Data/prets.txt")); while ((uneLigne = fichierRetards.ReadLine()) != null) { unAttribut = uneLigne.Split(unDelimiteur); nouvRetard = new Retard() { Code = unAttribut[0], Prenom = unAttribut[1], Courriel = unAttribut[2], Livre1 = unAttribut[3], Livre2 = unAttribut[4], Livre3 = unAttribut[5], DateEmprunt = unAttribut[6], DateRetour = unAttribut[7], }; listeEnRetard.Add(nouvRetard); } } var aujourdhui = DateTime.Now.ToString("d"); DateTime maintenant = DateTime.ParseExact(aujourdhui, "d", null); foreach (var retard in listeEnRetard) { DateTime emprunt = DateTime.ParseExact(retard.DateEmprunt.Trim(), "d", null); if ((maintenant - emprunt).TotalDays > 7) { try { string line = " "; using (StreamWriter retards = new StreamWriter( Server.MapPath(@"~/App_Data/retards.txt"), true)) { line += retard.Code + ","; line += retard.Prenom + ","; line += retard.Courriel + ","; line += retard.Livre1 + ","; line += retard.Livre2 + ","; line += retard.Livre3 + ","; line += retard.DateEmprunt + ","; bool isMatch = false; string[] lines = System.IO.File.ReadAllLines( Server.MapPath(@"~/App_Data/retards.txt")); // as you are not using it here for (int x = 0; x < lines.Length; x++) { Console.WriteLine(lines[x]); if (lines[x].Contains(retard.Code.Trim()) & lines[x].Contains(retard.Prenom.Trim()) & lines[x].Contains(retard.Courriel.Trim()) & lines[x].Contains(retard.Livre1.Trim()) & lines[x].Contains(retard.Livre2.Trim()) & lines[x].Contains(retard.Livre3.Trim()) & lines[x].Contains(retard.DateEmprunt.Trim())) { Console.WriteLine(retard.Code.Trim()); Console.WriteLine("there is a match"); isMatch = true; break; // exit loop if found } } if (isMatch == false) { retards.WriteLine(line); Console.WriteLine(retard.Code.Trim()); Console.WriteLine("there is no match"); } tousLesRetards.Add(retard); } } catch { return(Content("ERREUR")); } } } return(View(tousLesRetards)); }
/// <summary> /// Recupere tout les retards présent dans la base de donnée. /// </summary> /// <returns>Retourne une liste de retard.</returns> public static ObservableCollection <Retard> GetRetards(int idUserConnecte, List <int> tags) { if (tags != null) { ObservableCollection <Retard> retards = new ObservableCollection <Retard>(); StringBuilder sb = new StringBuilder(); sb.Append("SELECT DISTINCT re.id,re.titre,re.description,re.file, re.idEleve FROM retard re JOIN tags_retard tg_re on re.id=tg_re.idRetard WHERE tg_re.idTags in ("); foreach (var element in tags) { sb.Append(Convert.ToString(element)); sb.Append(","); } sb = sb.Remove(sb.Length - 1, 1); sb.Append(")"); string query = Convert.ToString(sb); //string query = "SELECT DISTINCT re.id,re.titre,re.description,re.file, re.idEleve FROM retard re JOIN tags_retard tg_re on re.id=tg_re.idRetard WHERE tg_re.idTags in (@params)"; // Open connection databaseConnexion connection = new databaseConnexion(); if (connection.OpenConnection() == true) { // Create Command using (MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection())) { //cmd.Parameters.AddWithValue("@params", Convert.ToString(parametres)); // Create a data reader and Execute the command using (MySqlDataReader dataReader = cmd.ExecuteReader()) { // Read the data and store them in the list while (dataReader.Read()) { Retard retard = new Retard(dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetString(2), dataReader.GetString(3), dataReader.GetInt32(4), idUserConnecte); retards.Add(retard); } // close Data Reader dataReader.Close(); } // close Connection connection.CloseConnection(); } // return list to be displayed } return(retards); } else { ObservableCollection <Retard> retards = new ObservableCollection <Retard>(); string query = "SELECT * from retard order by id desc"; // Open connection databaseConnexion connection = new databaseConnexion(); if (connection.OpenConnection() == true) { // Create Command using (MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection())) { // Create a data reader and Execute the command using (MySqlDataReader dataReader = cmd.ExecuteReader()) { // Read the data and store them in the list while (dataReader.Read()) { Retard retard = new Retard(dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetString(2), dataReader.GetString(3), dataReader.GetInt32(4), idUserConnecte); retards.Add(retard); } // close Data Reader dataReader.Close(); } // close Connection connection.CloseConnection(); } // return list to be displayed } return(retards); } }
// ça non plus mdr public ActionResult Down(Retard retard) { retard.Note--; return(View(retard.Note)); }
//TODO ça marche pas ptdr public ActionResult Up(Retard retard) { retard.Note++; return(View(retard.Note)); }