public async Task <IActionResult> Index(string statusChambre) { var vmChambre = new ChambreVM(); var chambres = new List <Chambre>(); //string req = ""; if (string.IsNullOrWhiteSpace(statusChambre)) { statusChambre = ""; } ViewBag.stat = statusChambre; /*Requete sql qui recupère toutes les chambres ainsi que leur tarif reviser au 1er janvier de l'année en cours * La requette est placé dans une vue dans la base GrandHotel*/ string req = @"select Numero, Etage, NbLits, Prix from vwChambresTarif"; /*Requete sql qui recupère toutes les chambres occupées. La requette est placé dans une vue dans la base GrandHotel*/ if (statusChambre == "Occupe") { req = @"select Numero, Etage, NbLits, Prix from vwChambresOccupeesTarif"; } /*Requete sql qui recupère toutes les chambres Livre. La requette est placé dans une vue dans la base GrandHotel*/ else if (statusChambre == "NonOccupe") { req = @"select Numero, Etage, NbLits, Prix from vwChambresLibreTarif"; } /*recupperation de la chaine de connexion dans une instruction using*/ using (var conn = (SqlConnection)_context.Database.GetDbConnection()) { /*Création de la commande et ajout de la code SQL et de la connexion*/ var cmd = new SqlCommand(req, conn); /*Ouverture de la connexion*/ await conn.OpenAsync(); /*Lecture des lignes de résultat une par une*/ using (var sdr = await cmd.ExecuteReaderAsync()) { while (sdr.Read()) { /*L'enregistrement est placé dans un objet l'entité Chambre et l'objet est ajouté à la liste chambres*/ var chambre = new Chambre(); chambre.Numero = (short)sdr["Numero"]; chambre.Etage = (byte)sdr["Etage"]; chambre.NbLits = (byte)sdr["NbLits"]; chambre.Tarifc = (decimal)sdr["Prix"]; chambres.Add(chambre); } } } /*L'instruction using appelle la méthode dispose qui ferme la connexion */ vmChambre.Chambre = chambres; return(View(vmChambre)); }
public List <ChambreVM> ListeDeChambre(Reservation reservation) { IQueryable <Chambre> chambre; IQueryable <Chambre> chambrereserve = null; List <Chambre> chambredispo = new List <Chambre>(); List <TarifChambre> tarifchambre = new List <TarifChambre>(); List <ChambreVM> ChambreEtPrix = new List <ChambreVM>(); try { chambre = grandhotel.Chambre.Where(x => x.NbLits == reservation.NbPersonnes); if (grandhotel.Reservation.Any(x => x.Jour == reservation.Jour)) { chambrereserve = grandhotel.Reservation .Include(x => x.NumChambreNavigation) .Where(x => x.Jour == reservation.Jour) .Select(x => x.NumChambreNavigation) .Where(x => x.NbLits == reservation.NbPersonnes); } if (chambrereserve != null) { chambredispo = chambre.Except(chambrereserve).ToList(); } else { chambredispo = chambre.ToList(); } var Tarifchambre = from c in chambredispo join tf in grandhotel.TarifChambre on c.Numero equals tf.NumChambre join t in grandhotel.Tarif on tf.CodeTarif equals t.Code where tf.CodeTarif.Contains(reservation.Jour.Year.ToString()) select tf; tarifchambre = Tarifchambre.ToList(); foreach (var chb in tarifchambre) { ChambreVM c = new ChambreVM(); c.Bain = chb.NumChambreNavigation.Bain; c.Douche = chb.NumChambreNavigation.Douche; c.Etage = chb.NumChambreNavigation.Etage; c.NbLits = chb.NumChambreNavigation.NbLits; c.Numero = chb.NumChambreNavigation.Numero; c.NumTel = chb.NumChambreNavigation.NumTel; c.Wc = chb.NumChambreNavigation.Wc; c.Prix = chb.CodeTarifNavigation.Prix; ChambreEtPrix.Add(c); } } catch (Exception ex) { } return(ChambreEtPrix); }
public ChambreVM DetailDeChambre(int numero) { ChambreVM chb = new ChambreVM(); try { Chambre chambre = new Chambre(); short num = (short)numero; chambre = grandhotel.Chambre.Where(x => x.Numero == num).FirstOrDefault(); chb.Numero = chambre.Numero; chb.Bain = chambre.Bain; chb.Douche = chambre.Douche; chb.Etage = chambre.Etage; chb.NbLits = chambre.NbLits; chb.NumTel = chambre.NumTel; chb.Wc = chambre.Wc; } catch (Exception ex) { } return(chb); }
// GET: Chambres/Details/5 //[Authorize] public IActionResult Details(short?id, string status) { ViewBag.DetailStatus = status; var vmChambre = new ChambreVM(); var chambres = new Chambre(); DateTime date = new DateTime(DateTime.Now.Year, 01, 01); if (id == null) { return(NotFound()); } var tarif = _context.TarifChambre .Include(tc => tc.NumChambreNavigation) .Include(tc => tc.CodeTarifNavigation) .Where(tc => tc.CodeTarifNavigation.DateDebut >= date && tc.NumChambreNavigation.Numero == id).FirstOrDefault(); if (chambres == null) { return(NotFound()); } ViewBag.id = id; vmChambre.TarifChambre = tarif; return(View(vmChambre)); }
public ChambreVM DetailChambre(int numero) { chb = reservations.DetailDeChambre(numero); return(chb); }
public static List <ChambreVM> GetChambre(double NbNuits, DateTime Jour, byte NbPersonnes) { List <ChambreVM> chambres = new List <ChambreVM>(); DateTime DateArrivee = Jour; DateTime DernierJour = Jour.AddDays(NbNuits - 1); // Le dernier jour de la réservation est le jour avant le départ car la nuit de la date de départ la chambre devrait être libre // The list of rooms available for the requested dates deduced by subtraction string req = @"select c.Numero, c.NbLits, c.Bain, c.Douche, c.Etage, c.WC, t.Prix, t.Prix*@NbNuits PrixTotal from Reservation r inner join Chambre c on c.Numero = r.NumChambre inner join TarifChambre tc on tc.NumChambre=c.Numero inner join Tarif t on t.Code=tc.CodeTarif where c.NbLits = @NbPersonnes and YEAR(t.DateDebut)=YEAR(@DateArrivee) group by c.Numero, c.NbLits, c.Bain, c.Douche, c.Etage, c.WC, t.Prix, t.Prix*@NbNuits, YEAR(t.DateDebut) except select c.Numero, c.NbLits, c.Bain, c.Douche, c.Etage, c.WC, t.Prix, t.Prix*@NbNuits PrixTotal from Reservation r inner join Chambre c on c.Numero = r.NumChambre inner join TarifChambre tc on tc.NumChambre=c.Numero inner join Tarif t on t.Code=tc.CodeTarif where r.Jour between @DateArrivee and @DernierJour group by c.Numero, c.NbLits, c.Bain, c.Douche, c.Etage, c.WC, t.Prix, t.Prix*@NbNuits"; var param0 = new SqlParameter("@NbNuits", SqlDbType.Int); param0.Value = NbNuits; var param1 = new SqlParameter("@DateArrivee", SqlDbType.Date); param1.Value = DateArrivee; var param2 = new SqlParameter("@DernierJour", SqlDbType.Date); param2.Value = DernierJour; var param3 = new SqlParameter("@NbPersonnes", SqlDbType.TinyInt); param3.Value = NbPersonnes; using (var conn = new SqlConnection(GrandHotelConnect)) { var cmd = new SqlCommand(req, conn); cmd.Parameters.Add(param0); cmd.Parameters.Add(param1); cmd.Parameters.Add(param2); cmd.Parameters.Add(param3); conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { var cVM = new ChambreVM(); // We had to create a ViewModel to add the property PrixTotal cVM.Chambre = new Chambre(); cVM.Chambre.Numero = (short)reader["Numero"]; cVM.Chambre.Etage = (byte)reader["Etage"]; cVM.Chambre.NbLits = (byte)reader["NbLits"]; cVM.Chambre.Bain = (bool)reader["Bain"]; cVM.Chambre.Douche = (bool)reader["Douche"]; cVM.Chambre.Wc = (bool)reader["Wc"]; cVM.Prix = (decimal)reader["Prix"]; cVM.PrixTotal = (decimal)reader["PrixTotal"]; chambres.Add(cVM); } } } return(chambres); }
// GET: Chambres public async Task <IActionResult> Index(int etat) { // Requête SQL optimisée: on ramène uniquement les infos nécessaires // Le but est de récupérer toutes les informations de toutes les chambres pour savoir si elles sont disponibles ou occupées à la date du jour // Elaboration d'une vue pour récupérer dans un premier temps les chambres occupées // Les paramètres id Client(utile pour la gestion interne) et Jour permettent d'indiquer l'état de la chambre string req = @" select C.Numero, C.Etage, C.Bain, C.Douche, C.WC, C.NbLits, C.NumTel, TC.CodeTarif,T.Prix,ECO.Jour, ECO.IdClient from Chambre C left outer join vwEtatChambresOccupees ECO on ECO.NumChambre=C.Numero left outer join TarifChambre TC on TC.NumChambre=C.Numero left outer join Tarif T on T.Code=TC.CodeTarif where year(T.DateDebut)=year(getdate())"; var chambre = new List <ChambreVM>(); using (var conn = (SqlConnection)_context.Database.GetDbConnection()) { var cmd = new SqlCommand(req, conn); await conn.OpenAsync(); using (var sdr = await cmd.ExecuteReaderAsync()) { while (sdr.Read()) { var c = new ChambreVM(); c.Chambre = new Chambre(); c.Reservation = new Reservation(); c.Chambre.Numero = (short)sdr["Numero"]; c.Chambre.Etage = (byte)sdr["Etage"]; c.Chambre.Bain = (bool)sdr["Bain"]; c.Chambre.Douche = (bool)sdr["Douche"]; c.Chambre.Wc = (bool)sdr["WC"]; c.Chambre.NbLits = (byte)sdr["NbLits"]; c.Chambre.NumTel = (short)sdr["NumTel"]; c.CodeTarif = (string)sdr["CodeTarif"]; c.Prix = (decimal)sdr["Prix"]; if (sdr["Jour"] != DBNull.Value) { c.Jour = (DateTime)sdr["Jour"]; } else { c.Jour = DateTime.Today; } if (sdr["IdClient"] != DBNull.Value) { c.Reservation.IdClient = (int)sdr["IdClient"]; } // Création d'une colonne: Etat d'occupation de la chambre à la date du jour (Disponible/Occupée) if (c.Reservation.IdClient != 0) { c.EtatChambre = "Chambre Occupée"; } else { c.EtatChambre = "Chambre DIsponible"; } //etat = c.EtatChambre; chambre.Add(c); } } } return(View(chambre)); }