Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Event.cpp
blob: e6105eb832e464c3682647ddb932c11f2313fa31 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Event.h"
#include "Reservation.h"
#include "StatusCodes.h"

Event::Event() : Event(nullptr, "", Date()) {}

Event::Event(const Hall* hall, String name, Date date) : tickets(), reservations() {
	this->hall = hall;
	this->name = name;
	this->date = date;
}

const OrderedList<Ticket>& Event::get_tickets() const {
	return tickets;
}

const OrderedList<Reservation>& Event::get_reservations() const {
	return reservations;
}

const Hall& Event::get_hall() const {
	return *hall;
}

const String& Event::get_name() const {
	return name;
}

const Date& Event::get_date() const {
	return date;
}

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(unsigned row, unsigned seat) {
	return cancelReservation(Ticket(row, seat));
}

StatusCode Event::cancelReservation(const Ticket& ticket) {
	unsigned ind = reservations.findIndex(ticket);
	if (ind == reservations.get_count())
		return W_TicketHadNotBeenReserved;

	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 (!reservations[resInd].validPassword(password)) return E_WrongReservationPassword;

	reservations.removeAt(resInd);
	tickets.insert(reservation.get_ticket());
	return Success;
}

int Event::compare(const Event& other) {
	// TODO: improve
	return name.compare(other.name);
}