/// <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 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")); }
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 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")); }