Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #418 from fsimonazzi/386-show-seat-types
Browse files Browse the repository at this point in the history
Show the available seats in the ui
  • Loading branch information
jdom committed May 17, 2012
2 parents ce43498 + 828fb28 commit 3b0bee1
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 14 deletions.
2 changes: 2 additions & 0 deletions scripts/CreateDatabaseObjects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ CREATE TABLE [ConferenceRegistration].[ConferencesView](
[Tagline] [nvarchar](max) NULL,
[TwitterSearch] [nvarchar](max) NULL,
[StartDate] [datetimeoffset](7) NOT NULL,
[SeatsAvailabilityVersion] [int] NOT NULL,
[IsPublished] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
Expand Down Expand Up @@ -288,6 +289,7 @@ CREATE TABLE [ConferenceRegistration].[ConferenceSeatTypesView](
[Description] [nvarchar](max) NULL,
[Price] [decimal](18, 2) NOT NULL,
[Quantity] [int] NOT NULL,
[AvailableQuantity] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ private OrderViewModel CreateViewModel()
{
SeatType = s,
OrderItem = new DraftOrderItem(s.Id, 0),
MaxSeatSelection = 20
AvailableQuantityForOrder = Math.Max(s.AvailableQuantity, 0),
MaxSelectionQuantity = Math.Max(Math.Min(s.AvailableQuantity, 20), 0)
}).ToList(),
};

Expand All @@ -314,11 +315,9 @@ private OrderViewModel CreateViewModel(DraftOrder order)
{
var seat = viewModel.Items.First(s => s.SeatType.Id == line.SeatType);
seat.OrderItem = line;
if (line.RequestedSeats > line.ReservedSeats)
{
seat.PartiallyFulfilled = true;
seat.MaxSeatSelection = line.ReservedSeats;
}
seat.AvailableQuantityForOrder = seat.AvailableQuantityForOrder + line.ReservedSeats;
seat.MaxSelectionQuantity = Math.Min(seat.AvailableQuantityForOrder, 20);
seat.PartiallyFulfilled = line.RequestedSeats > line.ReservedSeats;
}

return viewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class OrderItemViewModel

public bool PartiallyFulfilled { get; set; }

public int MaxSeatSelection { get; set; }
public int AvailableQuantityForOrder { get; set; }

public int MaxSelectionQuantity { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<tr>
<th style="width: 75%">Registration type</th>
<th scope="col" style="text-align: right">Price</th>
@*<th scope="col">Available</th>*@
<th scope="col">Available</th>
<th scope="col">Quantity</th>
</tr>
@for (var i = 0; i < this.Model.Items.Count; i++)
Expand All @@ -38,8 +38,18 @@
</td>
<td style="text-align: right">$<span class="unitPrice">@Html.DisplayFor(model => model.Items[i].SeatType.Price)</span>
</td>
<td>@Html.DropDownList("Seats[" + i + "].Quantity", new SelectList(Enumerable.Range(0, this.Model.Items[i].MaxSeatSelection + 1), this.Model.Items[i].OrderItem.ReservedSeats), new { @class = "itemQuantity" })
@Html.Hidden("Seats[" + i + "].SeatType", this.Model.Items[i].SeatType.Id)
<td style="text-align: right">@Html.DisplayFor(model => model.Items[i].AvailableQuantityForOrder)
</td>
<td>
@if ((this.Model.Items[i].MaxSelectionQuantity) > 0)
{
@Html.DropDownList("Seats[" + i + "].Quantity", new SelectList(Enumerable.Range(0, this.Model.Items[i].MaxSelectionQuantity + 1), this.Model.Items[i].OrderItem.ReservedSeats), new { @class = "itemQuantity" })
@Html.Hidden("Seats[" + i + "].SeatType", this.Model.Items[i].SeatType.Id)
}
else
{
<text>Sold out</text>
}
</td>
</tr>
if (this.Model.Items[i].PartiallyFulfilled)
Expand All @@ -59,7 +69,7 @@
<input class="form-promo__txt"><input class="form-promo__but" value="Submit" type="Submit">
</div>
</td>*@
<td colspan="2" class="content__table-cell_right content__cell_total">Estimated Total:</td>
<td colspan="3" class="content__table-cell_right content__cell_total">Estimated Total:</td>
<td class="content__cell_total content__table-cell_left">$<span id="total">0</span></td>
</tr>
</table>
Expand Down Expand Up @@ -123,7 +133,7 @@
$(".lineItem").each(function (index, item) {
var unitPrice = $(item).find(".unitPrice").text();
var quantity = $(item).find(".itemQuantity input").val();
total += unitPrice * quantity;
total += unitPrice * (quantity ? quantity : 0);
});
// round to 2 decimals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Registration.Tests.ConferenceViewModelGeneratorFixture
using Infrastructure.Messaging;
using Moq;
using Registration.Commands;
using Registration.Events;
using Registration.Handlers;
using Registration.IntegrationTests;
using Registration.ReadModel;
Expand Down Expand Up @@ -74,6 +75,7 @@ public void when_conference_created_then_conference_dto_populated()
Assert.Equal("description", dto.Description);
Assert.Equal("test", dto.Code);
Assert.Equal(0, dto.Seats.Count);
Assert.Equal(-1, dto.SeatsAvailabilityVersion);
}
}
}
Expand Down Expand Up @@ -197,6 +199,7 @@ public void when_seat_created_then_adds_seat_to_conference_dto()
Assert.Equal("seat", dto.Name);
Assert.Equal("description", dto.Description);
Assert.Equal(200, dto.Price);
Assert.Equal(0, dto.AvailableQuantity);
}

}
Expand Down Expand Up @@ -330,5 +333,239 @@ public void when_seats_removed_then_add_seats_command_sent()
Assert.Equal(seatId, e.SeatType);
Assert.Equal(50, e.Quantity);
}

[Fact]
public void when_available_seats_change_then_updates_remaining_quantity()
{
var seatId = Guid.NewGuid();

this.sut.Handle(new SeatCreated
{
ConferenceId = conferenceId,
SourceId = seatId,
Name = "seat",
Description = "description",
Price = 200,
});

this.sut.Handle(new AvailableSeatsChanged
{
SourceId = conferenceId,
Version = 0,
Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
});

using (var context = new ConferenceRegistrationDbContext(dbName))
{
var dtos = context.Set<Conference>()
.Where(x => x.Id == conferenceId)
.SelectMany(x => x.Seats, (Conference, Seat) => new { Conference, Seat })
.FirstOrDefault(x => x.Seat.Id == seatId);

Assert.NotNull(dtos);
Assert.Equal("seat", dtos.Seat.Name);
Assert.Equal("description", dtos.Seat.Description);
Assert.Equal(200, dtos.Seat.Price);
Assert.Equal(200, dtos.Seat.AvailableQuantity);
Assert.Equal(0, dtos.Conference.SeatsAvailabilityVersion);
}
}

[Fact]
public void when_seats_are_reserved_then_updates_remaining_quantity()
{
var seatId = Guid.NewGuid();

this.sut.Handle(new SeatCreated
{
ConferenceId = conferenceId,
SourceId = seatId,
Name = "seat",
Description = "description",
Price = 200,
});

this.sut.Handle(new AvailableSeatsChanged
{
SourceId = conferenceId,
Version = 0,
Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
});

this.sut.Handle(new SeatsReserved
{
SourceId = conferenceId,
Version = 1,
AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
});

using (var context = new ConferenceRegistrationDbContext(dbName))
{
var dtos = context.Set<Conference>()
.Where(x => x.Id == conferenceId)
.SelectMany(x => x.Seats, (Conference, Seat) => new { Conference, Seat })
.FirstOrDefault(x => x.Seat.Id == seatId);

Assert.NotNull(dtos);
Assert.Equal("seat", dtos.Seat.Name);
Assert.Equal("description", dtos.Seat.Description);
Assert.Equal(200, dtos.Seat.Price);
Assert.Equal(150, dtos.Seat.AvailableQuantity);
Assert.Equal(1, dtos.Conference.SeatsAvailabilityVersion);
}
}

[Fact]
public void when_seats_are_released_then_updates_remaining_quantity()
{
var seatId = Guid.NewGuid();

this.sut.Handle(new SeatCreated
{
ConferenceId = conferenceId,
SourceId = seatId,
Name = "seat",
Description = "description",
Price = 200,
});

this.sut.Handle(new AvailableSeatsChanged
{
SourceId = conferenceId,
Version = 0,
Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
});

this.sut.Handle(new SeatsReserved
{
SourceId = conferenceId,
Version = 1,
AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
});

this.sut.Handle(new SeatsReservationCancelled
{
SourceId = conferenceId,
Version = 2,
AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = 50 } }
});

using (var context = new ConferenceRegistrationDbContext(dbName))
{
var dtos = context.Set<Conference>()
.Where(x => x.Id == conferenceId)
.SelectMany(x => x.Seats, (Conference, Seat) => new { Conference, Seat })
.FirstOrDefault(x => x.Seat.Id == seatId);

Assert.NotNull(dtos);
Assert.Equal("seat", dtos.Seat.Name);
Assert.Equal("description", dtos.Seat.Description);
Assert.Equal(200, dtos.Seat.Price);
Assert.Equal(200, dtos.Seat.AvailableQuantity);
Assert.Equal(2, dtos.Conference.SeatsAvailabilityVersion);
}
}

[Fact]
public void when_seat_availability_update_event_has_version_equal_to_last_update_then_event_is_ignored()
{
var seatId = Guid.NewGuid();

this.sut.Handle(new SeatCreated
{
ConferenceId = conferenceId,
SourceId = seatId,
Name = "seat",
Description = "description",
Price = 200,
});

this.sut.Handle(new AvailableSeatsChanged
{
SourceId = conferenceId,
Version = 0,
Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
});

this.sut.Handle(new SeatsReserved
{
SourceId = conferenceId,
Version = 1,
AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
});

this.sut.Handle(new SeatsReserved
{
SourceId = conferenceId,
Version = 1,
AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
});

using (var context = new ConferenceRegistrationDbContext(dbName))
{
var dtos = context.Set<Conference>()
.Where(x => x.Id == conferenceId)
.SelectMany(x => x.Seats, (Conference, Seat) => new { Conference, Seat })
.FirstOrDefault(x => x.Seat.Id == seatId);

Assert.NotNull(dtos);
Assert.Equal("seat", dtos.Seat.Name);
Assert.Equal("description", dtos.Seat.Description);
Assert.Equal(200, dtos.Seat.Price);
Assert.Equal(150, dtos.Seat.AvailableQuantity);
Assert.Equal(1, dtos.Conference.SeatsAvailabilityVersion);
}
}

[Fact]
public void when_seat_availability_update_event_has_version_lower_than_last_update_then_event_is_ignored()
{
var seatId = Guid.NewGuid();

this.sut.Handle(new SeatCreated
{
ConferenceId = conferenceId,
SourceId = seatId,
Name = "seat",
Description = "description",
Price = 200,
});

this.sut.Handle(new AvailableSeatsChanged
{
SourceId = conferenceId,
Version = 0,
Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
});

this.sut.Handle(new SeatsReserved
{
SourceId = conferenceId,
Version = 1,
AvailableSeatsChanged = new[] { new SeatQuantity { SeatType = seatId, Quantity = -50 } }
});

this.sut.Handle(new AvailableSeatsChanged
{
SourceId = conferenceId,
Version = 0,
Seats = new[] { new SeatQuantity { SeatType = seatId, Quantity = 200 } }
});

using (var context = new ConferenceRegistrationDbContext(dbName))
{
var dtos = context.Set<Conference>()
.Where(x => x.Id == conferenceId)
.SelectMany(x => x.Seats, (Conference, Seat) => new { Conference, Seat })
.FirstOrDefault(x => x.Seat.Id == seatId);

Assert.NotNull(dtos);
Assert.Equal("seat", dtos.Seat.Name);
Assert.Equal("description", dtos.Seat.Description);
Assert.Equal(200, dtos.Seat.Price);
Assert.Equal(150, dtos.Seat.AvailableQuantity);
Assert.Equal(1, dtos.Conference.SeatsAvailabilityVersion);
}
}
}
}
Loading

0 comments on commit 3b0bee1

Please sign in to comment.