// // GET: /Vote/ public IActionResult Index(int id) { //_logger.LogInformation("Index Vote:" + dal.ADejaVote(id, Request.Headers["User-Agent"].ToString())); if (dal.ADejaVote(id, User.Identity.Name)) { return(RedirectToAction("AfficheResultat", new { id = id })); } List <Resto> listeDesRestaurants = dal.ObtientTousLesRestaurants(); List <RestaurantCheckBoxViewModel> listRestoVm = new List <RestaurantCheckBoxViewModel>(); RestaurantVoteViewModel restoVoteVm = new RestaurantVoteViewModel(); foreach (Resto resto in listeDesRestaurants) { RestaurantCheckBoxViewModel vm = new RestaurantCheckBoxViewModel { Id = resto.Id, NomEtTelephone = resto.Nom + " - (" + resto.Telephone + ")", EstSelectionne = false }; listRestoVm.Add(vm); } restoVoteVm.ListeDesResto = listRestoVm; return(View(restoVoteVm)); }
public ActionResult AccederSondage(int?id) { if (id.HasValue) { var sondage = dal.ObtenirSondages().FirstOrDefault(Sond => Sond.Id == id); if (sondage == null) { return(View("Error")); } Votes vo = new Votes(); vo.IdSondage = sondage.Id; var pre = Request.Form["welcome.Prenom"]; vo.Utilisateur = ObtenirUtilisateurBis(pre); if (vo.Utilisateur == null) { List <Resto> listeDesRestaurants = dal.ObtientTousLesRestaurants(); var welcome = new WelcomeForm(); Welcome welc = new Welcome(); welc.Bdd = listeDesRestaurants; welc.Sondages = dal.ObtenirSondages(); welc.Prenom = pre; welcome.welcome = welc; welcome.sel = new SelectList(welc.Sondages, "Id", "Id"); return(View("Index", welcome)); } var Restos = dal.ObtientTousLesRestaurants(); vo.Restos = new List <RestaurantCheckBoxViewModel>(); foreach (var r in Restos) { var res = new RestaurantCheckBoxViewModel(); res.Rest = r; res.NomEtTelephone = r.Nom + " " + r.Telephone; res.Id = r.Id; vo.Restos.Add(res); } return(View("~/Views/Vote/Index.cshtml", vo)); } return(View("Error")); }
// GET: Vote public ActionResult Index2(List <RestaurantCheckBoxViewModel> restos, Utilisateur utilisateur, int?idSondage) { //var Query = Request.Form[""]; { //StringBuilder Str2 = new StringBuilder(); //foreach (var r in restos) { /*var Sel = Request.Form["Restos[" + Index + "].EstSelectionne"]; * var Ind = Request.Form["Restos[" + Index + "].Id"];*/ // //Str2.Append(r.EstSelectionne).Append(","); //Str2.Append(r.NomEtTelephone).Append(","); //Str2.Append(r.Id).Append("\n"); /*var RestoResult = RestList.FirstOrDefault(Rest => Rest.Id.ToString() == Ind); * if (RestoResult == null) * { * Index++; * continue; * } * Str.Append(RestoResult.Nom).Append(","); * * if (Ut != null) * { * Str.Append(Ut.Prenom).Append("\n"); * dal.AjouterVote(IdSon, RestoResult.Id, Ut.Id); * } * else * { * Str.Append(Ut).Append("\n"); * } * Index++; */ } //File(Encoding.ASCII.GetBytes(Str2.ToString()), "application/octet-stream", "MonFichier.txt"); } //Votes votes = new Votes(); var Ut = dal.ObtenirUtilisateur(utilisateur.Id); if (Ut == null) { return(View("Error")); } //votes.Utilisateur = Ut; //votes.Restos = restos; //var Co = votes.CreerVotes().Count; //var Restos = dal.ObtientTousLesRestaurants(); var Mod = new Votes(); //var SonId = Request.Form["IdSondage"]; if (!idSondage.HasValue) { return(View("Error")); } int IdSon = idSondage.Value; /*if (!int.TryParse(SonId, out IdSon)) * { * return View("Error"); * }*/ if (!dal.ADejaVoteBis(IdSon, Ut.Id.ToString())) { bool Voted = false; var Index = 0; var RestList = dal.ObtientTousLesRestaurants(); /*foreach (var r in votes.CreerVotes()) * { * var Sel = Request.Form["Restos[" + Index + "].EstSelectionne"]; * var Ind = Request.Form["Restos[" + Index + "].Id"]; * var RestoResult = RestList.FirstOrDefault(Rest => Rest.Id.ToString() == Ind); * if (RestoResult == null) * { * Index++; * continue; * } * if (Sel == "false") * { * Index++; * continue; * } * Voted = true; * dal.AjouterVote(IdSon, RestoResult.Id, Ut.Id); * Index++; * }*/ foreach (var r in restos) { var Sel = r.EstSelectionne; //r.NomEtTelephone == null var Ind = r.Id; var RestoResult = RestList.FirstOrDefault(Rest => Rest.Id == Ind); if (RestoResult == null) { Index++; continue; } if (!Sel) { Index++; continue; } Voted = true; dal.AjouterVote(IdSon, RestoResult.Id, Ut.Id); Index++; } if (!Voted) { Votes vo = new Votes(); vo.IdSondage = IdSon; vo.Utilisateur = Ut; var Restos = dal.ObtientTousLesRestaurants(); vo.Restos = new List <RestaurantCheckBoxViewModel>(); foreach (var r in Restos) { var res = new RestaurantCheckBoxViewModel(); res.Rest = r; res.NomEtTelephone = r.Nom + " " + r.Telephone; res.Id = r.Id; vo.Restos.Add(res); } vo.Error = true; return(View("~/Views/Vote/Index.cshtml", vo)); } } /*StringBuilder Str = new StringBuilder(); * Str.Append(IdSon).Append(",");*/ //var Index = 0; //var RestList = dal.ObtientTousLesRestaurants(); /*foreach (var r in votes.CreerVotes()) * { * var Sel = Request.Form["Restos[" + Index + "].EstSelectionne"]; * var Ind = Request.Form["Restos[" + Index + "].Id"]; * // * Str.Append(Sel).Append(","); * Str.Append(Ind).Append(","); * var RestoResult = RestList.FirstOrDefault(Rest => Rest.Id.ToString() == Ind); * if (RestoResult == null) * { * Index++; * continue; * } * Str.Append(RestoResult.Nom).Append(","); * * if (Ut != null) { * Str.Append(Ut.Prenom).Append("\n"); * dal.AjouterVote(IdSon, RestoResult.Id, Ut.Id); * } else * { * Str.Append(Ut).Append("\n"); * } * Index++; * * }*/ var welcome = new WelcomeForm(); var welcome2 = new Welcome(); List <Resto> listeDesRestaurants = dal.ObtientTousLesRestaurants(); welcome2.Bdd = listeDesRestaurants; welcome2.Sondages = dal.ObtenirSondages(); welcome.welcome = welcome2; welcome.sel = new SelectList(welcome2.Sondages, "Id", "Id"); //return File(Encoding.ASCII.GetBytes(Str.ToString()), "application/octet-stream", "MonFichier.txt"); return(View("~/Views/Restaurant/Index.cshtml", welcome)); //return View(Mod); }