/// <summary> /// Provede rezervaci na akci. Vyhazuje ReservationException s popisem chyby, pokud se na akci neni mozne zaregistrovat. /// Podle UC6: Rezrvace akce. /// </summary> /// <param name="actionId"></param> /// <param name="clientId"></param> public static void ReservationToAction(int actionId, int clientId) { // Nacteni akce z databaze DatabaseLibrary.Action action = new DatabaseLibrary.ActionTable().SelectOne(actionId); DatabaseLibrary.ActionReservationTable actResTable = new DatabaseLibrary.ActionReservationTable(); // Overeni, zda je jeste volne misto int numOfRegClients = actResTable.SelectCountOfRegUser(actionId); // Overeni, zda je datum konani akce > aktualni datum if (action.action_date <= DateTime.Now) throw new ReservationException("Na tuto akci se j*z neni mozne rezervovat."); // Jestlize pocet registrovanych uzivatelu je mensi nez kapacita akce, muzeme provest registraci pokud j*z klient neni registrovan if (numOfRegClients < action.action_capacity) { // Zjisteni, zda j*z neni registrovan bool isReg = actResTable.IsUserRegisteredToAction(actionId, clientId); if (!isReg) { DatabaseLibrary.ActionReservation actRes = new DatabaseLibrary.ActionReservation(actionId, clientId); // Provedeme rezervaci - pokud dojde k vyhozeni vyjimky, klient j*z nema platne clenstvi. try { actResTable.InsertActionReservation(actRes); } catch (DatabaseLibrary.MembershipExpiredException ex) { // Klientovi j*z skoncilo clenstvi. Registrovat se nemuze. throw new ReservationException(ex.Message); // Pozdeji by se misto toho mohl user presmerovat na stranku s prodluzovanim clenstvi. } } else { throw new ReservationException("Tuto akci jste j*z rezervoval."); } } else { throw new ReservationException("Akce je j*z zaplnena."); } }
/// <summary> /// Zrusi rezervaci na akci. Vyhazuje ReservationException s popisem chyby, pokud se rezervaci nepodari zrusit. /// Podle UC9: Odhlaseni z akce. /// </summary> /// <param name="actionId"></param> /// <param name="clientId"></param> public static void CancelReservation(int actionId, int clientId) { DatabaseLibrary.ActionReservationTable actResTable = new DatabaseLibrary.ActionReservationTable(); // Musime overit, zda je mozne se jeste odhlasit. Odhlasovat se je mozno nejpozdeji 1 den pred zacatkem akce. Spravnou hodnotu jsem v dokumentu // nenasel, proto jsem si rekl, ze to bude jeden den. To se da pripadne kdykoliv zmenit. // Nacteni akce z databaze DatabaseLibrary.Action action = new DatabaseLibrary.ActionTable().SelectOne(actionId); if (action.action_date <= DateTime.Now.AddDays(1)) throw new ReservationException("Z teto akce se j*z neni mozne odhlasit. Muzete kontaktovat personal."); // Zruseni rezervace int res = actResTable.CancelClientReservation(actionId, clientId); if (res != 1) throw new ReservationException("Zruseni rezervace se nezdarilo."); }
protected void Page_Load(object sender, EventArgs e) { actResTable = new DatabaseLibrary.ActionReservationTable(); if (Session["actionId"] == null) { Response.Redirect("Default.aspx"); } // Jestli je j*z klient registrovan, zobrazime info a schovame tlacitko pro rezervaci a zobrazime tlacitko pro zruseni rezervace. int actionId = (int)Session["actionId"]; int clientId = (int)Session["clientId"]; bool isReg = actResTable.IsUserRegisteredToAction(actionId, clientId); if (isReg) { LabelInfo.Text = "Tuto akci jste j*z rezervoval."; BtnActionReservation.Visible = false; BtnCancelReservation.Visible = true; } else { BtnCancelReservation.Visible = false; } }