Ejemplo n.º 1
0
        public override bool Validate()
        {
            Program            app                = Program.GetInstance();
            ShowService        showService        = app.GetService <ShowService>("shows");
            UserService        userService        = app.GetService <UserService>("users");
            ChairService       chairService       = app.GetService <ChairService>("chairs");
            ReservationService reservationService = app.GetService <ReservationService>("reservations");

            // Make sure the show exists
            Show show = showService.GetShowById(showId);

            if (show == null)
            {
                AddError("showId", "Ongeldige voorstelling");
                return(false);
            }

            // Make sure the user exists
            User user = userService.GetUserById(userId);

            if (user == null)
            {
                AddError("userId", "Ongeldige gebruiker");
                return(false);
            }

            // Make sure the chair exists
            Chair chair = chairService.GetChairById(chairId);

            if (chair == null)
            {
                AddError("chairId", "Ongeldige stoel");
                return(false);
            }

            // Make sure the chair belongs to this room
            if (chair.roomId != show.roomId)
            {
                AddError("chairId", "De gekozen stoel hoort niet bij de gekozen zaal");
                return(false);
            }

            // Make sure the chair hasn't been taken
            if (reservationService.IsChairTaken(chair, show))
            {
                AddError("chairId", "De gekozen stoel is niet beschikbaar");
                return(false);
            }

            return(true);
        }
        public override bool Validate()
        {
            Program      app          = Program.GetInstance();
            RoomService  roomService  = app.GetService <RoomService>("rooms");
            ChairService chairService = app.GetService <ChairService>("chairs");

            // Make sure the room exists
            Room room = roomService.GetRoomById(roomId);

            if (room == null)
            {
                AddError("roomId", "Ongeldige zaal");
                return(false);
            }

            // Make sure the row + number combo is unique
            Chair chair = chairService.GetChairByRoomAndPosition(room, row, number);

            if (chair != null && chair.id != id)
            {
                AddError("number", "Nummer moet uniek zijn voor de gekozen rij");
                return(false);
            }

            // Make sure price is 0 or higher
            if (price < 0)
            {
                AddError("price", "Prijs mag niet negatief zijn");
                return(false);
            }

            // Make a valid type was selected
            if (!TYPES.Contains(type))
            {
                AddError("type", "Ongeldig type");
                return(false);
            }

            return(true);
        }