blob: a6d0e955d543373a7801735063d1cada12b41e97 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include "Event.h"
#include "Reservation.h"
#include "StatusCodes.h"
Event::Event() : Event(nullptr, "", DateTime()) {}
Event::Event(const Hall* hall, String name, DateTime time) {
this->hall = hall;
this->name = name;
this->time = time;
}
StatusCode Event::reserveTicket(const Ticket& ticket, const char* password, const char* note) {
if (tickets.contain(ticket)) return E_TicketAlreadyBought;
if (reservations.contain(ticket)) return E_TicketAlreadyReserved;
reservations.insert(Reservation(ticket, password, note));
return Success;
}
StatusCode Event::cancelReservation(const Ticket& ticket) {
unsigned ind = reservations.findIndex(ticket);
if (ind == reservations.get_count())
return W_TicketWasNotReserved;
reservations.removeAt(ind);
return Success;
}
StatusCode Event::buyTicket(const Ticket& ticket) {
if (tickets.contain(ticket)) return E_TicketAlreadyBought;
if (reservations.contain(ticket)) return E_TicketAlreadyReserved;
tickets.insert(ticket);
return Success;
}
StatusCode Event::buyTicketFromReservation(const Reservation& reservation, const char* password) {
unsigned resInd = reservations.findIndex(reservation);
if (resInd == reservations.get_count()) return E_ReservationDoesNotExist;
if (!reservation.checkPassword(password)) return E_WrongReservationPassword;
reservations.removeAt(resInd);
tickets.insert(reservation.get_ticket());
return Success;
}
|