Skip to content

Commit

Permalink
Pair programming met Kai en Stefhan Phteven
Browse files Browse the repository at this point in the history
  • Loading branch information
Tukurai committed Jun 11, 2024
1 parent 8105e15 commit 42e2c4a
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 105 deletions.
139 changes: 35 additions & 104 deletions ProjectB/Client/DepotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ProjectB.Models;
using ProjectB.Services;
using ProjectB.Workflows;
using ProjectB.Workflows.EmployeeFlows;
using ProjectB.Workflows.GuestFlows;
using Spectre.Console;

Expand Down Expand Up @@ -252,12 +253,7 @@ private void ShowTourMenu(Tour tour)

private void BeginStartTour(Tour tour)
{
if (tour.Departed)
{
Print("tourAlreadyDeparted");
Prompts.ShowSpinner("returningToMenu", 2000);
return;
}
var flow = GetFlow<StartTourFlow>();

Print("employeeTourInfo", new() { tour.Start.ToShortTimeString() });
Console.WriteLine();
Expand All @@ -267,6 +263,9 @@ private void BeginStartTour(Tour tour)
Print("guestList", new() { guestNumber });
Console.WriteLine();

if (!HandleFlowResult(flow.SetTour(tour)))
return;

if (tour.EmployeeNumber != Employee!.EmployeeNumber)
{
if (!string.IsNullOrWhiteSpace(tour.EmployeeNumber))
Expand All @@ -279,16 +278,13 @@ private void BeginStartTour(Tour tour)
}
}

tour.EmployeeNumber = Employee.EmployeeNumber;
TourService.SaveChanges();
if (!HandleFlowResult(flow.SetEmployeeNumber(Employee.EmployeeNumber)))
return;
}

Print("scanAllTickets");

List<int> scannedTickets = new List<int>();

bool continueScanning = true;
while (scannedTickets.Count != tour.Participants.Count && continueScanning)
while (flow.ScannedTickets.Count != tour.Participants.Count && flow.Scanning)
{
if (!int.TryParse(Prompts.AskTicketOrEmployeeNumber("ticketNumberOrEmployeeNumber"), out int number))
continue;
Expand All @@ -304,40 +300,22 @@ private void BeginStartTour(Tour tour)
Print("finishedScanningQuestion");
if (Prompts.AskYesNo("confirmYesNo", "yes", "no"))
{
continueScanning = false;
flow.Scanning = false;
continue;
}
}

if (GuestService.FindValidGuestById(number.ToString()) == null)
{
Print("invalidTicketNumber");
continue;
}

if (scannedTickets.Contains(number))
{
Print("ticketAlreadyScanned");
continue;
}
if (!HandleFlowResult(flow.AddGuest(number.ToString())))
return;

if (!tour.Participants.Contains(number.ToString()))
{
Print("ticketNotInTour");
continue;
}

scannedTickets.Add(number);
Print("ticketScanned", new() { number.ToString() });
Affirmation();
}

Print("finishedScanning");

tour.Participants = scannedTickets.Select(number => number.ToString()).ToList();

continueScanning = true;
while (scannedTickets.Count < tour.Capacity && continueScanning)
flow.Scanning = true;
while (flow.ScannedTickets.Count < tour.Capacity && flow.Scanning)
{
if (!int.TryParse(Prompts.AskTicketOrEmployeeNumber("ticketNumberOrEmployeeNumber"), out int number))
continue;
Expand All @@ -347,101 +325,62 @@ private void BeginStartTour(Tour tour)
Print("finishedScanningQuestion");
if (Prompts.AskYesNo("confirmYesNo", "yes", "no"))
{
continueScanning = false;
flow.Scanning = false;
continue;
}
}

if (scannedTickets.Contains(number))
{
Print("ticketAlreadyScanned");
continue;
}
if (!HandleFlowResult(flow.AddGuest(number.ToString(), true)))
return;

scannedTickets.Add(number);
Print("extraTicketScanned", new() { number.ToString() });
Affirmation();
}

Prompts.ShowSpinner("finishedScanningExtraTickets", 2000);
Console.Clear();

tour.Participants = scannedTickets.Select(number => number.ToString()).ToList();

Print("employeeTourInfo", new() { tour.Start.ToShortTimeString() });
Console.WriteLine();

Print("registeredGuests");
foreach (var guestNumber in tour.Participants)
foreach (var guestNumber in flow.ScannedTickets)
Print("guestList", new() { guestNumber });

Print("confirmStartTour");
if (!Prompts.AskYesNo("confirmYesNo", "yes", "no"))
{
Prompts.ShowSpinner("returningToMenu", 2000);
return;
}

tour.Departed = true;
TourService.SaveChanges();
HandleFlowConfirmation(flow,
TGet("confirmStartTour"),
TGet("startTourSuccess"),
TGet("startTourCancelled"));

Prompts.ShowSpinner("returningToMenu", 2000);
}

private void BeginAddGuest(Tour tour)
{
if (tour.Departed)
{
Print("tourAlreadyDeparted");
Prompts.ShowSpinner("returningToMenu", 2000);
return;
}
var flow = GetFlow<AddGuestFlow>();

Print("employeeTourInfo", new() { tour.Start.ToShortTimeString() });
Console.WriteLine();

if (tour.Participants.Count == tour.Capacity)
{
Print("noSpaceInTour");
Prompts.ShowSpinner("returningToMenu", 2000);
return;
}

string ticketNumber = Prompts.AskTicketNumber("ticketNumber");
var guest = GuestService.FindValidGuestById(ticketNumber);
if (guest == null)
{
Print("guestNotFound");
Prompts.ShowSpinner("returningToMenu", 2000);
if (!HandleFlowResult(flow.SetTour(tour)))
return;
}

var currentTour = TourService.GetTourForGuest(guest);
if (currentTour != null)
{
Print("guestAlreadyHasReservation");
Prompts.ShowSpinner("returningToMenu", 2000);
if (!HandleFlowResult(flow.SetGuest(Prompts.AskTicketNumber("scanGuestTicket"))))
return;
}

Print("confirmAddGuest", new() { tour.Start.ToShortTimeString() });
if (Prompts.AskYesNo("confirmYesNo", "yes", "no"))
{
if (guest != null && tour != null)
TourService.RegisterGuestForTour(guest, tour);
}
HandleFlowConfirmation(flow,
TGet("confirmAddGuest", new() { flow.Guest!.TicketNumber }),
TGet("addSuccess", new() { flow.Guest!.TicketNumber }),
TGet("addCancelled"));

Prompts.ShowSpinner("returningToMenu", 2000);
}

private void BeginRemoveGuest(Tour tour)
{
if (tour.Departed)
{
Print("tourAlreadyDeparted");
Prompts.ShowSpinner("returningToMenu", 2000);
return;
}
var flow = GetFlow<RemoveGuestFlow>();

Print("employeeTourInfo", new() { tour.Start.ToShortTimeString() });
Console.WriteLine();
Expand All @@ -451,24 +390,16 @@ private void BeginRemoveGuest(Tour tour)
Print("guestList", new() { guestNumber });
Console.WriteLine();

string ticketNumber = Prompts.AskTicketNumber("ticketNumberToRemove");
var guest = GuestService.FindValidGuestById(ticketNumber);
if (guest == null || !tour.Participants.Contains(guest.TicketNumber))
{
Print("guestNotFoundInTour");
Prompts.ShowSpinner("returningToMenu", 2000);
if (!HandleFlowResult(flow.SetTour(tour)))
return;
}

Print("confirmGuestRemoval");
if (!Prompts.AskYesNo("confirmYesNo", "yes", "no"))
{
Prompts.ShowSpinner("returningToMenu", 2000);
if (!HandleFlowResult(flow.SetGuest(Prompts.AskTicketNumber("scanGuestTicket"))))
return;
}

if (guest != null)
TourService.DeleteReservationGuest(guest);
HandleFlowConfirmation(flow,
TGet("confirmGuestRemoval", new() { flow.Guest!.TicketNumber }),
TGet("removeSuccess", new() { flow.Guest!.TicketNumber }),
TGet("removeCancelled"));

Prompts.ShowSpinner("returningToMenu", 2000);
}
Expand Down
6 changes: 6 additions & 0 deletions ProjectB/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ProjectB.Database;
using ProjectB.Repositories;
using ProjectB.Services;
using ProjectB.Workflows.EmployeeFlows;
using ProjectB.Workflows.GuestFlows;
using Spectre.Console;

Expand Down Expand Up @@ -41,6 +42,11 @@ private static IServiceProvider GetServices()
.AddTransient<EditReservationFlow>()
.AddTransient<DeleteReservationFlow>()

.AddTransient<AddGuestFlow>()
.AddTransient<RemoveGuestFlow>()
.AddTransient<StartTourFlow>()


.BuildServiceProvider();
}
}
Expand Down
1 change: 0 additions & 1 deletion ProjectB/ProjectB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@

<ItemGroup>
<Folder Include="Workflows\EmployeeFlows\" />
<Folder Include="Workflows\DebugFlows\" />
</ItemGroup>

</Project>
63 changes: 63 additions & 0 deletions ProjectB/Workflows/EmployeeFlows/AddGuestFlow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using ProjectB.Database;
using ProjectB.Models;
using ProjectB.Services;

namespace ProjectB.Workflows.EmployeeFlows
{
public class AddGuestFlow(IDatabaseContext context, ITourService tourService, IGuestService guestService) : AbstractWorkflow(context)
{
public Guest? Guest { get; private set; }
public Tour? Tour { get; private set; }

public (bool Success, string MessageKey) SetGuest(string ticketNumber)
{
if (string.IsNullOrWhiteSpace(ticketNumber))
return (false, "guestIsNull");

var guest = guestService.FindValidGuestById(ticketNumber);

if (guest == null)
return (false, "invalidTicket");

if (tourService.GetTourForGuest(guest) != null)
return (false, "alreadyHasReservation");

Guest = guest;

return (true, string.Empty);
}

public (bool Success, string MessageKey) SetTour(Tour tour)
{
if (tour == null)
return (false, "tourIsNull");

if (tour.Participants.Count >= tour.Capacity)
return (false, "tourFull");

if (tour.Start < DateTime.Now)
return (false, "tourInPast");

if (tour.Departed)
return (false, "tourDeparted");

Tour = tour;

return (true, string.Empty);
}

public override (bool Success, string MessageKey) Commit()
{
if (Guest == null)
return (false, "guestIsNull");

if (Tour == null)
return (false, "tourIsNull");

tourService.RegisterGuestForTour(Guest, Tour);

//No need to call base commit for this due to the service handling the changes
return (true, string.Empty);
}
}
}
Loading

0 comments on commit 42e2c4a

Please sign in to comment.