Exemplo n.º 1
0
        public IActionResult MakeReservation1()
        {
            if (loggedUser == null)
            {
                return(NotFound());
            }

            ReservationDashboardRegulatedViewModel model = new ReservationDashboardRegulatedViewModel();

            model.clients = new ClientDashboardRegulatedViewModel[model.clientsCnt];
            for (int i = 0; i < model.clients.Length; i++)
            {
                model.clients[i] = new ClientDashboardRegulatedViewModel();
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public IActionResult MakeReservation2(ReservationDashboardRegulatedViewModel model)
        {
            model.errorMessage = "";
            if (loggedUser == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid == false)
            {
                return(View(model));
            }
            if (model.roomNumber == null)
            {
                return(View(model));
            }

            Room r = dc.getAllRooms().FirstOrDefault(r => r.number == model.roomNumber);

            if (r is null)
            {
                model.errorMessage = "This room does not exist!";
                return(View(model));
            }
            if (r.isFree == false)
            {
                model.errorMessage = "This room is occupied!";
                return(View(model));
            }

            r.isFree = false;
            dc.updateRoom(r);

            Client[] clients = new Client[model.clientsCnt];
            for (int i = 0; i < model.clientsCnt; i++)
            {
                clients[i]    = new Client(model.clients[i]);
                clients[i].id = 0;
            }

            Reservation res = new Reservation()
            {
                id           = 0,
                user         = dc.getAllUsers().FirstOrDefault(u => u.id == HomeController.loggedUser.id),
                room         = r,
                dateStart    = model.dateStart,
                dateEnd      = model.dateEnd,
                allInclusive = model.allInclusive,
                breakfast    = model.breakfast,
            };

            res.cost = (model.dateEnd - model.dateStart).TotalDays * (clients.Count(c => c.isAdult == true) * r.priceAdult + clients.Count(c => c.isAdult == false) * r.priceChild
                                                                      + ((res.breakfast == true) ? 7 : 0) + ((res.allInclusive == true) ? 8 : 0));

            int id = dc.addReservation(res);

            res = dc.getAllReservations().FirstOrDefault(r => r.id == id);

            foreach (Client c in clients)
            {
                Client client = dc.getAllClients().FirstOrDefault(x => x.firstName == c.firstName && x.lastName == c.lastName);
                if (client == null)
                {
                    id     = dc.addClient(c);
                    client = dc.getAllClients().FirstOrDefault(x => x.id == id);
                }


                id = dc.addLinker(new ReservationClientLinker()
                {
                    client = client, reservation = res
                });
            }

            return(RedirectToAction(nameof(Dashboard)));
        }
        public IActionResult MakeReservation2(ReservationDashboardRegulatedViewModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(View(model));
            }
            if (model.roomNumber is null)
            {
                return(View(model));
            }

            model.errorMessage = "";
            Room r = ds.getFirstEntry <Room>(r => r.number == model.roomNumber);

            if (r is null)
            {
                model.errorMessage = "This room does not exist";
                return(View(model));
            }
            if (r.isFree == false)
            {
                model.errorMessage = "This room is occupied";
                return(View(model));
            }

            r.isFree = false;
            ds.updateEntry(r);

            Client[] clients = new Client[model.clientsCnt];
            for (int i = 0; i < model.clientsCnt; i++)
            {
                clients[i]    = new Client(model.clients[i]);
                clients[i].id = 0;
            }

            Reservation res = new Reservation()
            {
                id           = 0,
                user         = ds.getFirstEntry <User>(u => u.id == HomeController.loggedUser.id),
                room         = r,
                dateStart    = model.dateStart,
                dateEnd      = model.dateEnd,
                allInclusive = model.allInclusive,
                breakfast    = model.breakfast,
            };

            res.cost = (model.dateEnd - model.dateStart).TotalDays * (clients.Count(c => c.isAdult == true) * r.priceAdult + clients.Count(c => c.isAdult == false) * r.priceChild
                                                                      + ((res.breakfast == true) ? 1 : 0) + ((res.allInclusive == true) ? 3 : 0));

            int id = ds.addEntry(res);

            res = ds.getFirstEntry <Reservation>(r => r.id == id);

            foreach (Client c in clients)
            {
                if (res.clients == null)
                {
                    res.clients = new List <ReservationClientLinker>();
                }

                Client dsClient = ds.getFirstEntry <Client>(x => x.firstName == c.firstName && x.lastName == c.lastName);
                if (dsClient == null)
                {
                    id       = ds.addEntry(c);
                    dsClient = ds.getFirstEntry <Client>(x => x.id == id);
                }

                id = ds.addEntry(new ReservationClientLinker()
                {
                    client = dsClient, reservation = res
                });
                ReservationClientLinker linker = ds.getFirstEntry <ReservationClientLinker>(l => l.id == id);
            }

            return(Redirect("/Home/Dashboard"));
        }