/// <summary> /// regarde si les véhicule sont toujours réservé, et repasse leur état à LIBRE s'ils ne le sont pas /// </summary> public void checkReservation(string idStation) { var db = new AutolibContext(); var bornes = db.Bornes.Where(x => x.Station == Int32.Parse(idStation)).ToList(); foreach (var borne in bornes) { if (borne.IdVehicule != null) { var vehicule = db.Vehicules.FirstOrDefault(v => v.IdVehicule == borne.IdVehicule); if (vehicule.Disponibilite != "LIBRE") { var reser = db.Reservations.Where(r => r.Vehicule == vehicule.IdVehicule).OrderByDescending(v => v.DateEcheance).FirstOrDefault(); if (reser != null) { if (reser.DateEcheance < DateTime.Now) { vehicule.Disponibilite = "LIBRE"; db.SaveChanges(); } } } } } }
public ActionResult Login(string nom, string prenom) { var db = new AutolibContext(); var user = db.Clients.FirstOrDefault(x => x.Nom == nom && x.Prenom == prenom); if (user != null) {//connection var claims = new List <Claim>() { //new Claim(ClaimTypes.Name,user.Nom), //new Claim("Prenom",user.Prenom), new Claim("IdClient", user.IdClient.ToString()), }; if (user.IdClient == 102) { claims.Add(new Claim("Role", "Admin")); } else { claims.Add(new Claim("Role", "Client")); } var identity = new ClaimsIdentity(claims, "Identity"); var userPrincipal = new ClaimsPrincipal(new[] { identity }); HttpContext.SignInAsync(userPrincipal); HttpContext.Session.SetObject("CurrentUser", user); var listStations = db.Stations.ToList(); HttpContext.Session.SetObject("ListStations", listStations); } return(RedirectToAction("Index", "Home")); }
// GET public IActionResult Index() { AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; List <Station> lesStations = context.getLesStations(); return(View(lesStations)); }
/// <summary> /// affiche les réservations du client /// </summary> /// <returns></returns> public ActionResult MesReservations() { var db = new AutolibContext(); var idClient = User.Claims.FirstOrDefault(c => c.Type == "IdClient").Value; var reser = db.Reservations.Where(c => c.Client == Int32.Parse(idClient)).ToList(); var dt = new DataTable(); dt.Columns.Add("Vehicule", typeof(int)); //dt.Columns.Add("CatVehicule", typeof(int)); dt.Columns.Add("Date de reservation", typeof(DateTime)); dt.Columns.Add("Date echeance", typeof(DateTime)); reser.OrderByDescending(r => r.DateEcheance); foreach (var r in reser) { var row = dt.NewRow(); row["Vehicule"] = r.Vehicule; row["Date de reservation"] = r.DateReservation; row["Date echeance"] = r.DateEcheance; dt.Rows.Add(row); } return(View(dt)); }
/// <summary> /// Affichages des utilisations des véhicules /// </summary> /// <returns></returns> public ActionResult MesCommandes() { var db = new AutolibContext(); var idClient = User.Claims.FirstOrDefault(c => c.Type == "IdClient").Value; var util = db.Utilises.Where(c => c.Client == Int32.Parse(idClient)).ToList(); var dt = new DataTable(); dt.Columns.Add("Vehicule", typeof(int)); dt.Columns.Add("Date", typeof(DateTime)); dt.Columns.Add("Borne de départ", typeof(string)); dt.Columns.Add("Borne d'arrivée", typeof(string)); util.OrderByDescending(r => r.Date); foreach (var r in util) { var idStationDep = db.Bornes.FirstOrDefault(b => b.IdBorne == r.BorneDepart).Station; var stationDepart = db.Stations.FirstOrDefault(s => s.IdStation == idStationDep); var idStationFin = db.Bornes.FirstOrDefault(b => b.IdBorne == r.BorneArrivee).Station; var stationFin = db.Stations.FirstOrDefault(s => s.IdStation == idStationFin); var row = dt.NewRow(); row["Vehicule"] = r.Vehicule; row["Date"] = r.Date; row["Borne de départ"] = stationDepart.Numero + " " + stationDepart.Adresse; row["Borne d'arrivée"] = stationFin.Numero + " " + stationFin.Adresse; dt.Rows.Add(row); } return(View(dt)); }
public IActionResult Reserver(string idStation, string idBorne) { //faire la réservation //ajouter à ka table réservation la ligne //changer le statut du véhicule var db = new AutolibContext(); //var station = db.Stations.FirstOrDefault(s => s.IdStation.ToString() == idStation); var borne = db.Bornes.FirstOrDefault(b => b.IdBorne.ToString() == idBorne); //checkReservation(idStation); var idVehicule = borne.IdVehicule; var vehicule = db.Vehicules.FirstOrDefault(v => v.IdVehicule == idVehicule); vehicule.Disponibilite = "Reserve"; var idClient = User.Claims.FirstOrDefault(c => c.Type == "IdClient").Value; var time = DateTime.Now; var reservation = new Reservation() { Client = Int32.Parse(idClient), DateReservation = time, DateEcheance = time.AddMinutes(90), Vehicule = (int)idVehicule }; db.Reservations.Add(reservation); //mettre le véhicule à réserver db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult ChoixBorneArrivee(int idVehicule, int idStationArrivee) { var db = new AutolibContext(); var idBorneDepart = db.Bornes.Where(b => b.IdVehicule == idVehicule).FirstOrDefault().IdBorne; var idClient = User.Claims.FirstOrDefault(c => c.Type == "IdClient").Value; var borneArrive = db.Bornes.Where(b => b.Station == idStationArrivee && b.IdVehicule == null).FirstOrDefault(); var util = new Utilise() { Client = Int32.Parse(idClient), Vehicule = idVehicule, BorneArrivee = borneArrive.IdBorne, Date = DateTime.Now, BorneDepart = idBorneDepart }; var borneDepart = db.Bornes.FirstOrDefault(v => v.IdBorne == idBorneDepart && v.IdVehicule == idVehicule); borneDepart.IdVehicule = null; borneArrive.IdVehicule = idVehicule; db.Utilises.Add(util); var reser = db.Reservations.FirstOrDefault(r => r.Vehicule == idVehicule && r.Client == Int32.Parse(idClient)); db.Reservations.Remove(reser); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
// GET public IActionResult Index(int id) { AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; List <Vehicule> lesVehicules = context.getLesVehiculesByIdStation(id); return(View(lesVehicules)); }
public IActionResult inscription(FormModifDetailsClient form) { string mdpHash = CreateMD5(form.mdpClient); AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; context.insertClient(form.nomClient, form.prenomClient, form.naissanceClient, mdpHash); return(RedirectToAction("Index")); }
public IActionResult updateInfo(FormModifDetailsClient form) { string idSession = HttpContext.Session.GetString("idSession"); AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; context.updateInfoClient(Convert.ToInt32(idSession), form.nomClient, form.prenomClient); return(RedirectToAction("Details")); }
public IActionResult DetailsReservation() { string idSession = HttpContext.Session.GetString("idSession"); AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; List <Reservation> lesReservations = context.GetReservationByUser(Convert.ToInt32(idSession)); return(View(lesReservations)); }
public ActionResult DeleteAccount(int id) { var db = new AutolibContext(); var c = db.Clients.FirstOrDefault(c => c.IdClient == id); db.Clients.Remove(c); db.SaveChanges(); return(RedirectToAction("ManageAccount", "Account")); }
public ActionResult Index(int id) { var db = new AutolibContext(); var user = db.Clients.FirstOrDefault(c => c.IdClient == id); //var client = Controller.CurrentClient; return(View(user)); }
public ActionResult ChoixBorneArrivee() { var db = new AutolibContext(); var stations = db.Stations.Where(s => s.Bornes.Any(b => b.IdVehicule == null)).ToList(); ViewBag.Stations = stations; //TODO afficher que les stations qui ont encore une place de libre return(View()); }
public ActionResult Index() { var db = new AutolibContext(); var id = User.Claims.FirstOrDefault(c => c.Type == "IdClient").Value; var user = db.Clients.FirstOrDefault(c => c.IdClient.ToString() == id); //var client = Controller.CurrentClient; return(View(user)); }
public IActionResult Reserver(int id) { int intIdVehicule = id; string idSession = HttpContext.Session.GetString("idSession"); DateTime theDate = DateTime.Now; AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; context.reserver(intIdVehicule, Convert.ToInt32(idSession), theDate.ToString("yyyy-MM-dd H:mm:ss")); context.changeEtatVehicule(intIdVehicule, "Reserve en ligne"); return(RedirectToRoute(new { controller = "Client", action = "DetailsReservation" })); }
/// <summary> ///génération de la carte /// /// </summary> public void GenerateMap() { //creation d'un objet que l'on passe à la vue pour avoir les coordonnées des points var listStations = HttpContext.Session.GetObject <List <Station> >("ListStations"); if (listStations == null) { var db = new AutolibContext(); listStations = db.Stations.ToList(); } var mapStation = new MapStation() { Type = "FeatureCollection", Features = new List <MapFeatures>() }; foreach (var station in listStations) { //var coord1 = new MapCoordinates(); var coord1 = new List <decimal>(); coord1.Add(station.Latitude); coord1.Add(station.Longitude); var coord2 = new List <decimal>(); coord2.Add(station.Longitude); coord2.Add(station.Latitude); var geo = new MapGeometry() { Type = "Point", Geo_point_2d = coord1 }; coord1.Reverse(); var prop = new MapProperties() { CodePostal = station.CodePostal.ToString(), Commune = station.Ville, Localisation = station.Numero.ToString() + " " + station.Adresse, Geo_point_2d = coord2, IdStation = station.IdStation.ToString() }; var mf = new MapFeatures() { Type = "Feature", Geometry = geo, Properties = prop }; mapStation.Features.Add(mf); } mapStation.JsonValue = JsonConvert.SerializeObject(mapStation); ViewBag.station = mapStation; }
public ActionResult Reservation(string id) { var db = new AutolibContext(); var idClient = User.Claims.FirstOrDefault(c => c.Type == "IdClient").Value; checkReservation(id); var bornes = db.Bornes.Where(x => x.Station == Int32.Parse(id)).ToList(); var dt = new DataTable(); dt.Columns.Add("NumBorne", typeof(int)); dt.Columns.Add("IdVehicule", typeof(int)); dt.Columns.Add("EtatBatterie", typeof(int)); dt.Columns.Add("Disponibilite", typeof(string)); dt.Columns.Add("IdClient", typeof(string)); foreach (var b in bornes) { var reser = db.Reservations.FirstOrDefault(r => r.Vehicule == b.IdVehicule && r.Client == Int32.Parse(idClient) && r.DateEcheance > DateTime.Now); var row = dt.NewRow(); if (b.IdVehicule != null) { var v = db.Vehicules.FirstOrDefault(v => v.IdVehicule == b.IdVehicule); if (reser != null) { row["IdClient"] = idClient; } else { row["IdClient"] = 0; } row["NumBorne"] = b.IdBorne; row["IdVehicule"] = v.IdVehicule; row["EtatBatterie"] = v.EtatBatterie ?? 0; row["Disponibilite"] = v.Disponibilite ?? ""; } else { row["NumBorne"] = b.IdBorne; row["IdVehicule"] = 0; row["EtatBatterie"] = 0; row["Disponibilite"] = "Pas de véhicule"; row["IdClient"] = 0; } dt.Rows.Add(row); } return(View(dt)); }
public IActionResult Details(FormConnexion formConnexion) { AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; Client unClient = context.getUnClient(Convert.ToInt32(formConnexion.idClient)); if (unClient != null && unClient.Password == CreateMD5(formConnexion.mdpClient)) { HttpContext.Session.SetString("idSession", unClient.IdClient.ToString()); return(View(unClient)); } else { return(RedirectToAction("Index")); } }
public IActionResult Details() { string idSession = HttpContext.Session.GetString("idSession"); AutolibContext context = HttpContext.RequestServices.GetService(typeof(AutolibContext)) as AutolibContext; Client unClient = context.getUnClient(Convert.ToInt32(idSession)); if (unClient != null) { HttpContext.Session.SetString("idSession", unClient.IdClient.ToString()); return(View(unClient)); } else { return(RedirectToAction("Index")); } }
public ActionResult CreateAccount(string nom, string prenom, DateTime naiss) { var client = new Client() { DateNaissance = naiss, Nom = nom, Prenom = prenom }; using (var db = new AutolibContext()) { db.Clients.Add(client); db.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult UpdateInformations(string idC, string nom, string prenom, DateTime naiss) { //if id en param == id client var idClient = User.Claims.FirstOrDefault(c => c.Type == "IdClient").Value; var user = HttpContext.Session.GetObject <Client>("CurrentUser"); using (var db = new AutolibContext()) { var c = db.Clients.FirstOrDefault(u => u.IdClient.ToString() == idC); c.DateNaissance = naiss; c.Nom = nom; c.Prenom = prenom; db.SaveChanges(); if (idClient == idC) { HttpContext.Session.SetObject("CurrentUser", c); } } return(RedirectToAction("Index", "Home")); }
public ActionResult ManageAccount() { var db = new AutolibContext(); var dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Nom", typeof(string)); dt.Columns.Add("Prénom", typeof(string)); dt.Columns.Add("Date de naissance", typeof(DateTime)); foreach (var client in db.Clients.ToList()) { if (client.IdClient != 1) { var row = dt.NewRow(); row["Id"] = client.IdClient; row["Nom"] = client.Nom; row["Prénom"] = client.Prenom; row["Date de naissance"] = client.DateNaissance; dt.Rows.Add(row); } } return(View(dt)); }