public ReservationClientLinker(ReservationClientLinker other) { this.id = other.id; this.client = new Client(other.client); this.reservation = new Reservation(other.reservation); }
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")); }