public ActionResult Index() { List <RaceModel> result = MgtRace.GetInstance().GetAllItemsWithParticipants().ToModels(true); result = result.Where(x => x.DateEnd >= DateTime.Today).ToList(); int idUser = 0; if (WebSecurity.IsAuthenticated) { if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("SqlAdoCs", "UserTable", "Id", "Name", autoCreateTables: true); } idUser = WebSecurity.CurrentUserId; } if (idUser > 0) { Personne user = MgtPersonne.GetInstance().GetPersonneByIdUserTable(idUser); for (int i = 0; i < result.Count; i++) { bool inscrit = MgtParticipant.GetInstance().isIncrit(result.ElementAt(i).Id, user.Id); result.ElementAt(i).Inscrit = inscrit; } } return(View(result.OrderByDescending(x => x.DateStart).ToList())); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Tentative d'inscription de l'utilisateur try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); int id = WebSecurity.GetUserId(model.UserName); PersonneModel personModel = new PersonneModel() { Nom = model.Nom, Prenom = model.Prenom, Email = model.Email, Phone = model.Telephone, DateNaissance = model.Naissance }; Personne personne = personModel.ToBo(); personne.UserTable = id; MgtPersonne.GetInstance().AddPersonne(personne); WebSecurity.Login(model.UserName, model.Password); return(RedirectToAction("Index", "Home")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // Si nous sommes arrivés là, quelque chose a échoué, réafficher le formulaire return(View(model)); }
public ActionResult Index() { if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("SqlAdoCs", "UserTable", "Id", "Name", autoCreateTables: true); } //Récupération de la personne par son id UserTable int idUser = WebSecurity.CurrentUserId; var personne = MgtPersonne.GetInstance().GetPersonneByIdUserTable(idUser).ToModel(); int idPersonne = personne.Id; //Récupération de la liste des inscriptions de la personne par son id var inscriptions = MgtParticipant.GetInstance().GetAllById(idPersonne).ToModels(); //Réupérations des informations de chaque course auquel la personne est inscrite //On génère une liste des courses auxquelles la personne est inscrite, avec tous les détails les concernant List <RaceModel> coursesInscrit = new List <RaceModel>(); foreach (var ins in inscriptions) { var course = MgtRace.GetInstance().GetRace(ins.CourseId).ToModel(); coursesInscrit.Add(course); } //On retourne la vue corespondante avec la liste des inscriptions en paramètre return(View(coursesInscrit)); }
public ActionResult Index(int?page = 1) { int pageSize = 50; int pageNumber = (page ?? 1); var result = MgtPersonne.GetInstance().GetAllItems().ToModels(); var valRet = result.ToPagedList(pageNumber, pageSize); return(View(valRet)); }
public ActionResult List(int page = 1) { PersonneView view = new PersonneView(); Pager pager = new Pager(MgtPersonne.GetInstance().Count(), page, 16); int skip = (pager.CurrentPage - 1) * pager.PageSize; view.personnes = MgtPersonne.GetInstance().GetAllItemsByLimit(skip, pager.PageSize).ToModels(); view.Pager = pager; return(View(view)); }
// // GET: /Account/Manage public ActionResult ManageInfos(ManageMessageId?message) { if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("SqlAdoCs", "UserTable", "Id", "Name", autoCreateTables: true); } int idUser = WebSecurity.CurrentUserId; Personne user = MgtPersonne.GetInstance().GetPersonneByIdUserTable(idUser); return(View(user.ToModel())); }
public ActionResult Delete(FormCollection collection) { if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("SqlAdoCs", "UserTable", "Id", "Name", autoCreateTables: true); } int idUser = WebSecurity.CurrentUserId; MgtPersonne.GetInstance().RemovePersonne(idUser); return(LogOff()); }
public ActionResult ManageInfos(PersonneModel model) { Personne user = MgtPersonne.GetInstance().GetPersonneById(model.Id); if (!user.Equals(model.ToBo())) { MgtPersonne.GetInstance().UpdatePersonne(model.ToBo()); } // Si nous sommes arrivés là, quelque chose a échoué, réafficher le formulaire return(View(model)); }
public ActionResult Import(int?page = 1) { PersonneModel personne = (PersonneModel)Session.Contents["user"]; List <ResultatModel> modelsResult = new List <ResultatModel>(); HttpPostedFileBase fichier = Request.Files["FileResult"]; if (fichier != null) { StreamReader stream = new StreamReader(fichier.InputStream); string chaine = stream.ReadToEnd(); String[] lignes = chaine.Split('\r', '\n'); foreach (var ligne in lignes) { if (String.IsNullOrEmpty(ligne)) { continue; } ResultatModel model = new ResultatModel(); string[] champs = ligne.Split(';'); model.Race = MgtRace.GetInstance().GetRace(int.Parse(champs[1])).ToModel(); model.Personne = MgtPersonne.GetInstance().GetPersonneByID(int.Parse(champs[0])).ToModel(); model.Classement = int.Parse(champs[2]); model.TempsDeCourse = TimeSpan.Parse(champs[3]); model.HeureDebut = TimeSpan.Parse(champs[4]); model.HeureArrivee = TimeSpan.Parse(champs[5]); modelsResult.Add(model); } } bool res = MgtResultat.GetInstance().Save(modelsResult.Select(x => x.ToBo()).ToList()); if (res) { return(RedirectToAction("Index", "Admin")); //return View(valRet); } else { return(View("Importresult")); } }
public ActionResult Unsubscribe(int idRace = 0) { if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("SqlAdoCs", "UserTable", "Id", "Name", autoCreateTables: true); } //Récupération de la personne par son id UserTable int idUser = WebSecurity.CurrentUserId; var personne = MgtPersonne.GetInstance().GetPersonneByIdUserTable(idUser).ToModel(); int idPersonne = personne.Id; //Suppression en base de l'inscription avec id de la personne et id de la course en paramètres MgtParticipant.GetInstance().RemoveParticipant(idPersonne, idRace); return(RedirectToAction("Index", "Participant")); }
public ActionResult InscritsToPDF(int id) { InscritsView view = new InscritsView(); List <Participant> partipants = MgtParticipant.GetInstance().GetAllByIdCourse(id); List <PersonneModel> personnes = new List <PersonneModel>(); foreach (Participant part in partipants) { PersonneModel model = MgtPersonne.GetInstance().GetPersonneById(part.IdPersonne).ToModel(); model.participant = part.ToModel(); personnes.Add(model); } view.Course = MgtRace.GetInstance().GetRace(id).ToModel(); view.personnes = personnes; view.nbInscrits = personnes.Count; view.inscriptions = initInscriptions(partipants); Document doc = new Document(PageSize.LETTER, 50, 50, 50, 50); string html = RenderRazorViewToString("~/Views/Race/InscritsToPDF.cshtml", view); TextReader reader = new StringReader(html); using (MemoryStream output = new MemoryStream()) { PdfWriter wri = PdfWriter.GetInstance(doc, output); // step 3: we create a worker parse the document HTMLWorker worker = new HTMLWorker(doc); doc.Open(); worker.StartDocument(); // step 5: parse the html into the document worker.Parse(reader); // step 6: close the document and the worker worker.EndDocument(); worker.Close(); doc.Close(); return(File(output.ToArray(), "application/pdf", "Inscriptions" + view.Course.Title + ".pdf")); } }
public ActionResult Details(int id) { RaceModel result = MgtRace.GetInstance().GetRace(id).ToModel(); int idUser = 0; //On récupère l'ID de l'utilisateur courant if (WebSecurity.IsAuthenticated) { if (!WebSecurity.Initialized) { WebSecurity.InitializeDatabaseConnection("SqlAdoCs", "UserTable", "Id", "Name", autoCreateTables: true); } idUser = WebSecurity.CurrentUserId; } //On récupère l'utisateur //On personnalise la vue en f(x) du paramètrage du compte if (idUser > 0) { Personne user = MgtPersonne.GetInstance().GetPersonneByIdUserTable(idUser); if (user.kms) { result.KmOrMiles = "Km"; } else if (user.miles) { result.KmOrMiles = "Miles"; } else { result.KmOrMiles = "Km"; } } if (result == null) { return(HttpNotFound()); } return(View(result)); }
private ArrayList statByAge() { ArrayList nbByAge = new ArrayList(); //Total Personne var nbPersonne = MgtPersonne.GetInstance().GetAllItems().Count(); //18-29 DateTime currentDate = DateTime.Now; DateTime date1 = new DateTime(currentDate.Year - 18, 1, 1); DateTime date2 = new DateTime(currentDate.Year - 29, 1, 1); var totalTranche1 = MgtPersonne.GetInstance().getByTrancheDate(date1, date2).Count(); // 30 - 39 date1 = new DateTime(currentDate.Year - 30, 1, 1); date2 = new DateTime(currentDate.Year - 39, 1, 1); var totalTranche2 = MgtPersonne.GetInstance().getByTrancheDate(date1, date2).Count(); // 40 - 49 date1 = new DateTime(currentDate.Year - 40, 1, 1); date2 = new DateTime(currentDate.Year - 49, 1, 1); var totalTranche3 = MgtPersonne.GetInstance().getByTrancheDate(date1, date2).Count(); // +50 date1 = new DateTime(currentDate.Year - 50, 1, 1); var totalTranche4 = MgtPersonne.GetInstance().getByTrancheDate(null, date1).Count(); //Calcul %age double pourcent1 = Math.Round((double)totalTranche1 / (double)nbPersonne, 2) * 100; double pourcent2 = Math.Round((double)totalTranche2 / (double)nbPersonne, 2) * 100; double pourcent3 = Math.Round((double)totalTranche3 / (double)nbPersonne, 2) * 100; double pourcent4 = Math.Round((double)totalTranche4 / (double)nbPersonne, 2) * 100; //Ajout dans ArrayList nbByAge.Add(pourcent1); nbByAge.Add(pourcent2); nbByAge.Add(pourcent3); nbByAge.Add(pourcent4); return(nbByAge); }
public ActionResult Inscrits(int id = 0, int page = 1) { InscritsView view = new InscritsView(); List <Participant> partipants = MgtParticipant.GetInstance().GetAllByIdCourse(id); List <PersonneModel> personnes = new List <PersonneModel>(); foreach (Participant part in partipants) { PersonneModel model = MgtPersonne.GetInstance().GetPersonneById(part.IdPersonne).ToModel(); model.participant = part.ToModel(); personnes.Add(model); } Pager pager = new Pager(personnes.Count, page, 15); view.Course = MgtRace.GetInstance().GetRace(id).ToModel(); view.personnes = personnes.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize).ToList(); view.nbInscrits = personnes.Count; view.inscriptions = initInscriptions(partipants); view.Pager = pager; return(View(view)); }
public ActionResult InscriptionAge(int id = 0) { InscritsView view = new InscritsView(); List <Participant> partipants = MgtParticipant.GetInstance().GetAllByIdCourse(id); List <PersonneModel> personnes = new List <PersonneModel>(); int Nb20 = 0; int Nb21_30 = 0; int Nb31_40 = 0; int Nb41_50 = 0; int Nb51_60 = 0; int Nb61 = 0; foreach (Participant part in partipants) { PersonneModel model = MgtPersonne.GetInstance().GetPersonneById(part.IdPersonne).ToModel(); if (model.DateNaissance != null) { int age = DateTime.Now.Year - model.DateNaissance.Value.Year; if (age <= 20) { Nb20++; } else if (age <= 30) { Nb21_30++; } else if (age <= 40) { Nb31_40++; } else if (age <= 50) { Nb41_50++; } else if (age <= 60) { Nb51_60++; } else { Nb61++; } } personnes.Add(model); } view.Course = MgtRace.GetInstance().GetRace(id).ToModel(); view.personnes = personnes; view.nbInscrits = personnes.Count; view.TA20 = Nb20; view.TA21_30 = Nb21_30; view.TA31_40 = Nb31_40; view.TA41_50 = Nb41_50; view.TA51_60 = Nb51_60; view.TA61 = Nb61; return(View(view)); }