Example #1
0
        public async Task <IActionResult> PutClient([FromRoute] int id, [FromBody] ClientVM client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != client.Id)
            {
                return(BadRequest());
            }

            _context.Entry(client).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        // 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)));
        }
        //[Authorize]
        public IActionResult Details(Reservation reservation)
        {
            _context.SaveChangesAsync();
            var reservations = HttpContext.Session.GetObjectFromJson <List <Reservation> >("ResaFinal");

            // We recover form the memory the reservation with all the information (except for the Id of the client which is given after the creation of his account) in order to show it here with all its details
            ViewBag.duree = reservations.Count;
            return(View(reservation));
        }
Example #4
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));
        }
        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));
        }
Example #6
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));
        }
Example #7
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));
        }
        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));
        }
        [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));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id, Civilite, Nom, Email, Prenom, CarteFidelite, Societe, Adresse, Telephone")] Client client)
        {
            var uniqueTel = _context.Telephone.Where(t => t.Numero == client.Telephone[0].Numero).FirstOrDefault();
            var user      = await _userManager.GetUserAsync(User);

            client.Email = user.Email;
            var adresseToUpdate = _context.Adresse.Find(client.Id);

            Telephone ancienNumero = _context.Telephone.Where(t => t.IdClient == client.Id).FirstOrDefault();

            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid && (uniqueTel == null || uniqueTel.IdClient == client.Id))
            {
                if (client.Adresse.Rue == null || client.Adresse.Ville == null || client.Adresse.CodePostal == null)
                {
                    client.Adresse.Rue        = "non renseigné";
                    client.Adresse.Complement = "non renseigné";
                    client.Adresse.CodePostal = "00000";
                    client.Adresse.Ville      = "non renseigné";
                }

                try
                {
                    if (uniqueTel == null)
                    {
                        ///////////////////
                        _context.Client.Where(c => c.Id == client.Id).Include(t => t.Telephone).FirstOrDefault().Telephone.Add(client.Telephone[0]);
                        _context.Telephone.Remove(ancienNumero);
                        await _context.SaveChangesAsync();

                        //////////////////
                    }

                    adresseToUpdate.Rue        = client.Adresse.Rue;
                    adresseToUpdate.Complement = client.Adresse.Complement;
                    adresseToUpdate.Ville      = client.Adresse.Ville;
                    adresseToUpdate.CodePostal = client.Adresse.CodePostal;

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            if (uniqueTel != null)
            {
                ViewBag.ErreurTelephone = "le numero " + client.Telephone[0].Numero + " est déjà utilisé, veuillez en saisir un nouveau";
            }
            return(View(client));
        }