コード例 #1
0
        // GET: Reservations/Create
        public async Task <IActionResult> Create(short id)
        {
            var user = await _user.GetUserAsync(User);

            var         client       = _context.Client.Where(c => c.Email == user.Email).FirstOrDefault();
            var         reservations = HttpContext.Session.GetObjectFromJson <List <ReserVationSession> >("Resa");
            Reservation reservation;

            for (int res = 0; res < reservations.Count; res++)
            {
                reservation = new Reservation
                {
                    IdClient     = client.Id,
                    HeureArrivee = reservations[res].HeureArrivee,
                    Jour         = reservations[res].Jour,
                    NumChambre   = id,
                    NbPersonnes  = reservations[res].NbPersonnes,
                    Travail      = reservations[res].Travail
                };
                if (ModelState.IsValid)
                {
                    reservations[res].NumChambre = id;
                    _context.Add(reservation);
                }
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(DetailsReservarion)));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Numero,Etage,Bain,Douche,Wc,NbLits,NumTel")] Chambre chambre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(chambre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(chambre));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,IdClient,DateFacture,DatePaiement,CodeModePaiement")] Facture facture)
        {
            if (ModelState.IsValid)
            {
                _context.Add(facture);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CodeModePaiement"] = new SelectList(_context.ModePaiement, "Code", "Code", facture.CodeModePaiement);
            ViewData["IdClient"]         = new SelectList(_context.Client, "Id", "Civilite", facture.IdClient);
            return(View(facture));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("NumChambre,Jour,IdClient,NbPersonnes,HeureArrivee,Travail")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdClient"]   = new SelectList(_context.Client, "Id", "Civilite", reservation.IdClient);
            ViewData["Jour"]       = new SelectList(_context.Calendrier, "Jour", "Jour", reservation.Jour);
            ViewData["NumChambre"] = new SelectList(_context.Chambre, "Numero", "Numero", reservation.NumChambre);
            return(View(reservation));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Jour,NbPersonnes,HeureArrivee,Travail")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["NbPersonne"]   = new SelectList(_context.Set <Reservation>(), "NbPersonne", "NbPersonne", reservation.NbPersonnes);
            ViewData["Jour"]         = new SelectList(_context.Set <Calendrier>(), "Jour", "Jour", reservation.Jour);
            ViewData["HeureArrivee"] = new SelectList(_context.Set <Reservation>(), "HeureArrivee", "HeureArrivee", reservation.HeureArrivee);
            return(View(reservation));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Civilite,Nom,Prenom,Email,CarteFidelite,Societe,Adresse,Telephone")] Client client)
        {
            var uniqueTel  = _context.Telephone.Where(t => t.Numero == client.Telephone[0].Numero).FirstOrDefault();
            var clientBase = _context.Client.Where(c => c.Email == client.Email).FirstOrDefault();


            var chambre = HttpContext.Session.GetObjectFromJson <List <Chambre> >("Cham");

            if (ModelState.IsValid && uniqueTel == null && clientBase == null)
            {
                var user = await _user.GetUserAsync(User);

                client.Email = user.Email;

                if (client.Adresse.Rue == null || client.Adresse.Ville == null || client.Adresse.CodePostal == null)
                {
                    client.Adresse.Rue        = "non renseigné";
                    client.Adresse.CodePostal = "00000";
                    client.Adresse.Ville      = "non renseigné";
                }
                _context.Add(client);

                await _context.SaveChangesAsync();

                if (chambre == null)
                {
                    return(RedirectToAction(nameof(ManageController.Index), "Manage"));
                }
                //Récuperation du numero de chambre à Reserver et redirection vers le récapitulatif de la commande
                short idChambre = chambre.Last().Numero;
                return(RedirectToAction("Create", "Reservations", new { id = idChambre }));
            }
            if (uniqueTel != null)
            {
                ViewBag.ErreurTelephone = "le numero " + client.Telephone[0].Numero + " est déjà utilisé, veuillez en saisir un nouveau";
            }
            if (clientBase != null)
            {
                return(RedirectToAction(nameof(ManageController.Index), "Manage"));
            }

            if (uniqueTel != null)
            {
                ViewBag.ErreurTelephone = "le numero " + client.Telephone[0].Numero + " est déjà utilisé, veuillez en saisir un nouveau";
            }
            return(View(client));
        }
コード例 #7
0
        [Authorize] // Before confirming the reservation and writing the information in the database we ask for authentication.
                    // We put this here because a) it makes more sense to ask for authentication right before editing the database and
                    // b) beacause it is easier to redirect to this action from the controller Client since this action does not take parameters
        public async Task <IActionResult> Confirm()
        {
            var user = await _userManager.GetUserAsync(User); // This is the "active" user

            // Before confirming the reservation
            var reservations = HttpContext.Session.GetObjectFromJson <List <Reservation> >("ResaFinal"); // We recover here the reservation which has all the information stored ecxept for the Id client

            for (int res = 0; res < reservations.Count; res++)
            {
                if (ModelState.IsValid)
                { // Here we add the id of the client to all the reservations (one for each day) that he  created
                    reservations[res].IdClient = (_context.Client.FirstOrDefault(c => c.Email == user.Email)).Id;
                    _context.Add(reservations[res]);
                }
            }
            await _context.SaveChangesAsync(); // Finally the reservation is saved in the database


            return(View());
        }
コード例 #8
0
        [ValidateAntiForgeryToken]  //, string Email
        public async Task <IActionResult> CreatePost([Bind("Id,Civilite,Nom,Prenom,Email,CarteFidelite,Societe")] Client client, string Email)
        {
            if (ModelState.IsValid)
            {
                Email = client.Email;
                _context.Add(client);
                await _context.SaveChangesAsync();


                var reservations = HttpContext.Session.GetObjectFromJson <List <Reservation> >("ResaFinal");

                if (reservations != null)                                // We test here if there is a reservation running. If yes we redirect to Confirm to finish the reservation. If not we go to the last url.
                {
                    return(RedirectToAction("Confirm", "Reservations")); //, new {Email=user.Email }
                }
                else
                {
                    var returnUrl = HttpContext.Session.GetObjectFromJson <string>("url"); // We recover the url saved in the Register process of the authentication
                    return(RedirectToLocal(returnUrl));
                }
            }
            return(View(client));
        }