public async Task <IActionResult> Create([Bind("Id,IdDestination,DateDepart,DateRetour,PlacesDispo,PrixHt,Reduction,Descriptif")] Voyage voyage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(voyage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdDestination"] = new SelectList(_context.Destination, "Id", "Nom", voyage.IdDestination);
            return(View(voyage));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,IdParente,Nom,Niveau,Description")] Destination destination)
        {
            if (ModelState.IsValid)
            {
                _context.Add(destination);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdParente"] = new SelectList(_context.Destination, "Id", "Nom", destination.IdParente);
            return(View(destination));
        }
        public async Task <IActionResult> ValiderResa(Dossierresa dossierresa)
        {
            if (ModelState.IsValid)
            {
                var personne = await _context.Personne.Where(p => p.Email == User.FindFirstValue(ClaimTypes.Name)).FirstOrDefaultAsync();

                if (personne.TypePers == 4)
                {
                    personne.TypePers = 1;
                    _context.Client.Add(new BoVoyage.Models.Client()
                    {
                        Id = personne.Id
                    });
                }

                foreach (var voyageur in HttpContext.Session.Get <List <Personne> >("voyageurs"))
                {
                    if (voyageur.Nom != null)
                    {
                        if (!_context.Personne.Where(p => p.Email == voyageur.Email).Any())
                        {
                            voyageur.TypePers = 2;
                            _context.Personne.Add(voyageur);
                        }
                        await _context.SaveChangesAsync();

                        _context.Voyageur.Add(new Voyageur()
                        {
                            Id = voyageur.Id, Idvoyage = HttpContext.Session.Get <int>("idVoyage")
                        });
                    }
                }
                _context.Voyageur.Add(new Voyageur()
                {
                    Id = personne.Id, Idvoyage = HttpContext.Session.Get <int>("idVoyage")
                });
                var dossier = new Dossierresa()
                {
                    NumeroCb = dossierresa.NumeroCb, IdClient = personne.Id, IdEtatDossier = 2, IdVoyage = HttpContext.Session.Get <int>("idVoyage"), PrixTotal = HttpContext.Session.Get <decimal>("prix")
                };
                _context.Personne.Update(personne);
                _context.Dossierresa.Add(dossier);
                var voyage = await _context.Voyage.FindAsync(HttpContext.Session.Get <int>("idVoyage"));

                voyage.PlacesDispo = voyage.PlacesDispo - (HttpContext.Session.Get <List <Personne> >("voyageurs").Count() + 1);
                _context.Voyage.Update(voyage);
                await _context.SaveChangesAsync();

                return(View());
            }
            ViewBag.Prix = HttpContext.Session.Get <double>("prix");
            return(View("Paiement", dossierresa));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Id,TypePers,Civilite,Nom,Prenom,Email,Telephone,Datenaissance")] Personne personne)
        {
            if (ModelState.IsValid)
            {
                var userMail = _userManager.GetUserName(HttpContext.User);
                //await _userManager.AddToRoleAsync(user, "Member");
                _context.Add(personne);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(personne));
        }
        public async Task <IActionResult> Create([Bind("Id,NumeroCb,PrixTotal,IdClient,IdEtatDossier,IdVoyage")] Dossierresa dossierresa)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dossierresa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdClient"]      = new SelectList(_context.Client, "Id", "Id", dossierresa.IdClient);
            ViewData["IdEtatDossier"] = new SelectList(_context.Etatdossier, "Id", "Libelle", dossierresa.IdEtatDossier);
            ViewData["IdVoyage"]      = new SelectList(_context.Voyage, "Id", "Descriptif", dossierresa.IdVoyage);
            return(View(dossierresa));
        }
        public async Task <IActionResult> Create([Bind("Id,IdParente,Nom,Niveau,Description")] Destination destination)
        {
            if (ModelState.IsValid)
            {
                _context.Add(destination);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            // ViewData["IdParente"] = new SelectList(_context.Destination, "Id", "Nom", destination.IdParente);
            // L'objectif de la requête ci-dessous serait de n'afficher que les IdParente de destinations de niveau inférieur à 3, donc pas les régions
            //ViewData["IdParente"] = new SelectList(_context.Destination.Where(d => d.Niveau < 3).OrderBy(d => d.Nom), "Id", "Nom", destination.IdParente);

            // Essai
            var destinationParente = await _context.Destination.Where(d => d.Niveau < 3).OrderBy(d => d.Nom).AsNoTracking().ToListAsync();

            ViewData["IdParente"] = new SelectList(destinationParente, "Id", "Nom", destination.IdParente);

            return(View(destination));
        }
Beispiel #7
0
        public async Task <IActionResult> Create([Bind("Civilite", "Nom", "Prenom", "Telephone", "Email", "SujetMessage", "Message")] ContactViewModel newContact)
        {
            if (ModelState.IsValid)
            {
                var pers = _context.Personne.Where(p => p.Email == newContact.Email).FirstOrDefault();
                if (pers == null)

                {
                    Personne personne = new Personne()

                    {
                        Civilite = newContact.Civilite,

                        Nom = newContact.Nom,

                        Prenom = newContact.Prenom,

                        Telephone = newContact.Telephone,

                        Email = newContact.Email,

                        TypePers = 3,

                        Datenaissance = new DateTime().Date
                    };

                    _context.Personne.Add(personne);
                    await _context.SaveChangesAsync();



                    //return RedirectToAction(nameof(Index));
                }

                if (newContact.SujetMessage != null && newContact.Message != null)
                {
                    ViewBag.Valid = "Le message a bien été envoyé.";
                }
            }



            return(View("Contact", newContact));
        }
        public async Task <IActionResult> Create([Bind("Id,TypePers,Civilite,Nom,Prenom,Email,Telephone,Datenaissance")] Personne personne)
        {
            personne.TypePers = 1; // Pour definir que c'est un client : TypePers =1.
            if (ModelState.IsValid)
            {
                _context.Add(personne);

                // On assigne le rôle Member par défaut aux nouveaux utilisateurs enregistrés



                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }



            return(View(personne));
        }
Beispiel #9
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email, PhoneNumber = Input.Telephone
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    if (_context.Personne.Where(p => p.Email == Input.Email).SingleOrDefault() == null)
                    {
                        var personne = new Personne()
                        {
                            Nom           = Input.Nom,
                            Prenom        = Input.Prenom,
                            Civilite      = Input.Civilite,
                            Telephone     = Input.Telephone,
                            Email         = Input.Email,
                            TypePers      = 4,
                            Datenaissance = Input.Datenaissance
                        };
                        _context.Personne.Add(personne);
                        await _context.SaveChangesAsync();
                    }
                    _logger.LogInformation("User created a new account with password.");
                    await _userManager.AddToRoleAsync(user, "Member");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Merci de confirmer la créaction de votre compte en cliquant <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>ici</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }