// GET: Bestellinghistoriek
        public ActionResult Index()
        {
            tblBestellingService         bestellingservice = new tblBestellingService();
            BestellinghistoriekViewModel vm = new BestellinghistoriekViewModel();
            tblBestellijnService         bestellijnservice = new tblBestellijnService();
            tblProductService            productservice    = new tblProductService();

            var claimsIdentity = User.Identity as ClaimsIdentity;

            if (claimsIdentity != null)
            {
                var userIdClaim = claimsIdentity.Claims
                                  .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

                if (userIdClaim != null)
                {
                    string id = userIdClaim.Value;

                    IEnumerable <tblBestelling> bestellijst = bestellingservice.getBestellingenBytblGebruiker(id);
                    vm.bestellingID = bestellijst.Select(a => a.BestellingID).ToArray();
                    vm.besteldatum  = bestellijst.Select(a => a.Besteldatum).ToArray();
                    vm.vertekdatum  = bestellijst.Select(a => a.Vertrekdatum).ToArray();
                    double[]           ordertotalen    = new double[bestellijst.Count()];
                    Bestellingstatus[] bestelstatussen = new Bestellingstatus[bestellijst.Count()];

                    for (int i = 0; i < bestellijst.Count(); i++)
                    {
                        double ordertotaal = 0;
                        IEnumerable <tblBestellijn> bestellijnen = bestellingservice.getBestellijnenByBestelling(bestellijst.ElementAt(i));
                        for (int j = 0; j < bestellijnen.Count(); j++)
                        {
                            tblProduct product = productservice.getProduct(bestellijnen.ElementAt(j).ProductID);
                            ordertotaal += productservice.getPrijs(product);
                        }
                        ordertotalen[i] = ordertotaal;
                        Bestellingstatus status = Bestellingstatus.InBewerking;
                        if (bestellijst.ElementAt(i).Geannuleerd == 1)
                        {
                            status = Bestellingstatus.Geannuleerd;
                        }
                        else
                        {
                            if (bestellijst.ElementAt(i).Vertrekdatum <= DateTime.Today)
                            {
                                status = Bestellingstatus.Voltooid;
                            }
                            else
                            {
                                status = Bestellingstatus.InBewerking;
                            }
                        }
                        bestelstatussen[i] = status;
                    }
                    vm.ordertotaal = ordertotalen;
                    vm.status      = bestelstatussen;
                }
            }
            return(View(vm));
        }
Esempio n. 2
0
        public async Task <ActionResult> Index(WinkelmandViewModel vm)
        {
            tblBestellijnService  bestellijnservice  = new tblBestellijnService();
            tblBestellingService  bestellingservice  = new tblBestellingService();
            tblTreinplaatsService treinplaatsservice = new tblTreinplaatsService();
            tblProductService     productservice     = new tblProductService();
            var claimsIdentity = User.Identity as ClaimsIdentity;

            if (claimsIdentity != null)
            {
                var userIdClaim = claimsIdentity.Claims
                                  .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

                if (userIdClaim != null)
                {
                    string id = userIdClaim.Value;

                    tblBestelling bestelling = new tblBestelling();
                    bestelling.GebruikersID = id;
                    bestelling.Vertrekdatum = vm.trajectdatum.FirstOrDefault();
                    bestelling.Besteldatum  = DateTime.Today;
                    bestelling.Geannuleerd  = 0;
                    int bestellingid = bestellingservice.addBestelling(bestelling);
                    List <tblBestellijn> bestellijnen = new List <tblBestellijn>();
                    for (int i = 0; i < vm.hotelIDs.Count(); i++)
                    {
                        tblBestellijn bestellijn = new tblBestellijn();
                        bestellijn.BestellingID = bestellingid;
                        tblProduct product = productservice.getProductByHotel(vm.hotelIDs[i]);
                        bestellijn.ProductID = product.ProductID;
                        int bestellijnID = bestellijnservice.addBestellijn(bestellijn);
                    }
                    for (int i = 0; i < vm.trajectenIDs.Count(); i++)
                    {
                        tblBestellijn bestellijn = new tblBestellijn();
                        bestellijn.BestellingID = bestellingid;
                        tblProduct product;

                        product = productservice.getProductByTraject(vm.trajectenIDs[i], vm.treinklassen[i]);


                        bestellijn.ProductID = product.ProductID;

                        int            bestellijnID = bestellijnservice.addBestellijn(bestellijn);
                        tblTreinplaats treinplaats  = new tblTreinplaats();
                        treinplaats.BestellijnID = bestellijnID;
                        treinplaats.Naam         = vm.trajectnamen[i];
                        treinplaats.Plaatsnummer = vm.treinplaats[i];
                        if (vm.treinklassen[i])
                        {
                            treinplaats.Treinklasse = 1;
                        }
                        else
                        {
                            treinplaats.Treinklasse = 0;
                        }

                        treinplaatsservice.addTreinplaats(treinplaats);
                    }

                    tblWinkelmandlijnService winkelmandlijnservice = new tblWinkelmandlijnService();
                    winkelmandlijnservice.clearWinkelmand(id);
                    string bericht = "Dit zijn de gegevens van uw bestelling<br/><br/> <table class='table'><thead> <tr><th> Beschrijving </th><th> Vertrekdatum </th><th> Naam reiziger </th><th> Prijs </th></tr></thead> ";
                    for (int i = 0; i < vm.trajectenIDs.Count(); i++)
                    {
                        string tablelijn = "<tr><td>Treinticket van " + vm.trajectvertrek[i] + " naar " + vm.trajectaankomst[i] + " treinplaats " + vm.treinplaats[i] + "</td><td>" + vm.trajectdatum[i].Date.ToShortDateString() + " </td><td>" + vm.trajectnamen[i] + " </td><td>€" + vm.trajectprijzen[i] + "</td> </tr>";
                        bericht += tablelijn;
                    }
                    for (int i = 0; i < vm.hotelIDs.Count(); i++)
                    {
                        string tablelijn = "<tr><td>Hotelboeking in " + vm.hotelnaam[i] + "</td><td>" + vm.hoteldatum[i].Date.ToShortDateString() + " </td><td>" + vm.hotelnamen[i] + " </td><td>€" + vm.hotelprijzen[i] + "</td> </tr>";
                        bericht += tablelijn;
                    }
                    bericht += "</table>";

                    var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                    await userManager.SendEmailAsync(id, "VivesTGV: Uw bestelling " + bestelling.BestellingID, bericht);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }