public static async Task <Booking> CreateBookingWithTwoSpotsInSameMarina() { using (var transaction = Fixture.Connection.BeginTransaction()) { using (var context = Fixture.CreateContext(transaction)) { IPDFService <Booking> pDFService = new BookingPDFService(); IBookingService bookingService = new BookingService(context, null, null, pDFService, null); BoatOwner boatOwner = context.BoatOwners.Where(b => b.BoatOwnerId == 1).FirstOrDefault(); Boat boat = context.Boats.Where(b => b.BoatId == 1).FirstOrDefault(); Spot spot1 = context.Spots.Where(s => s.MarinaId == 1 && s.SpotNumber == 1).FirstOrDefault(); Spot spot2 = context.Spots.Where(s => s.MarinaId == 1 && s.SpotNumber == 2).FirstOrDefault(); Booking booking = new Booking { Boat = boat }; await bookingService.Create(booking); booking = bookingService.CreateBookingLine(booking, DateTime.Now, DateTime.Now.AddDays(1), spot1); booking = bookingService.CreateBookingLine(booking, DateTime.Now.AddDays(1), DateTime.Now.AddDays(2), spot2); await bookingService.SaveBooking(booking); return(booking); } } }
public async Task<int> Create(BoatOwner boatOwner) { boatOwner.ThrowIfNull(); await _context.BoatOwners.AddAsync(boatOwner); return boatOwner.BoatOwnerId; }
public double MoneySpent(BoatOwner boatOwner) { boatOwner.ThrowIfNull(); var boats = boatOwner.Boats; var moneySpent = (from boat in boats from booking in boat.Bookings select booking.TotalPrice).Sum(); return moneySpent; }
public IEnumerable<Booking> GetOngoingBookings(BoatOwner boatOwner) { boatOwner.ThrowIfNull(); var boats = boatOwner.Boats; var bookingsToReturn = from boat in boats from booking in boat.Bookings where HasOngoing(booking) select booking; return bookingsToReturn; }
public TimeSpan TotalTime(BoatOwner boatOwner) { boatOwner.ThrowIfNull(); TimeSpan totalTime = new TimeSpan(); var boats = boatOwner.Boats; var bookings = (from boat in boats from booking in boat.Bookings select booking).ToList(); foreach (var booking in bookings) totalTime += TotalTime(booking); return totalTime; }
public async Task <BoatOwner> MakePersonBoatOwner(Person person) { person.ThrowIfNull(); if (_context.BoatOwners.AsQueryable().Any(p => p.PersonId.Equals(person.Id))) { throw new BusinessException("Email", "You are already registered as a boat owner!"); } var boatOwner = new BoatOwner { PersonId = person.Id }; await _context.BoatOwners.AddAsync(boatOwner); await AddToRoleAsync(person, RoleName.BoatOwner); return(boatOwner); }
public BoatOwner Update(BoatOwner boatOwner) { _context.Update(boatOwner); return boatOwner; }
public static void SeedDb(SportsContext context) { //TODO: Remove in Release :) context.Database.EnsureDeleted(); context.Database.EnsureCreated(); //TODO: Add seed data or use NMockaroo //Insert data into the database if there aren't any in the specific table if (!context.Addresses.Any()) { var addresses = new Address[] { new Address { Street = "Amazing Drive", City = "Aalborg", Country = "DK", State = "DK" }, new Address { Street = "Not so Amazing Drive", City = "Copenhagen", Country = "DK", State = "DK" }, new Address { City = "Aalborg", Street = "Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, new Address { City = "Aarhus", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, new Address { City = "Copenhagen", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, new Address { City = "Esbjerg", Street = "Not so Amazing Drive", Country = "Denmark", PostalCode = "9000", State = "Denmark" }, }; context.Addresses.AddRange(addresses); context.SaveChanges(); } if (!context.Locations.Any()) { var locations = new Location[] { new Location { Latitude = 55.724478044067006, Longitude = 12.60262191295624 }, new Location { Latitude = 57.058790791383466, Longitude = 9.895803630352022 }, new Location { Latitude = 57.05889288811736, Longitude = 9.895127713680269 }, }; context.Locations.AddRange(locations); context.SaveChanges(); } if (!context.Persons.Any()) { var persons = new Person[] { new Person { FirstName = "Bartosz", LastName = "Urban", Email = "*****@*****.**", AddressId = 1 }, new Person { FirstName = "Dragos", LastName = "Ionescu", Email = "*****@*****.**", AddressId = 1 }, new Person { FirstName = "Peter", LastName = "Boelt", Email = "*****@*****.**", AddressId = 2 }, new Person { FirstName = "Zach", LastName = "Horatau", Email = "*****@*****.**", AddressId = 2 } }; context.Persons.AddRange(persons); context.SaveChanges(); } if (!context.MarinaOwners.Any()) { var marinaOwners = new MarinaOwner[] { new MarinaOwner { PersonId = 1 }, new MarinaOwner { PersonId = 2 }, new MarinaOwner { PersonId = 3 }, new MarinaOwner { PersonId = 4 }, }; context.MarinaOwners.AddRange(marinaOwners); context.SaveChanges(); } if (!context.Marinas.Any()) { var marinas = new Marina[] { new Marina { Name = "Aalborg Marina", MarinaOwnerId = 1, Description = "Coolest marina", Facilities = "none", AddressId = 1 }, new Marina { Name = "Aarhus Marina", MarinaOwnerId = 2, Description = "Some marina", Facilities = "none", AddressId = 2 }, new Marina { Name = "Copenhagen Marina", MarinaOwnerId = 3, Description = "Some marina", Facilities = "none", AddressId = 3 }, new Marina { Name = "Esbjerg Marina", MarinaOwnerId = 1, Description = "Some marina", Facilities = "none", AddressId = 4 }, }; context.Marinas.AddRange(marinas); context.SaveChanges(); } if (!context.BoatOwners.Any()) { var boatOwners = new BoatOwner[] { new BoatOwner { PersonId = 3 }, new BoatOwner { PersonId = 4 } }; context.BoatOwners.AddRange(boatOwners); context.SaveChanges(); } if (!context.Boats.Any()) { var boats = new Boat[] { new Boat { Name = "Titanic", BoatOwnerId = 1, Depth = 2, Length = 5, Width = 3 }, new Boat { Name = "Mama Destroyer", BoatOwnerId = 2, Depth = 5, Length = 20, Width = 9 }, }; context.Boats.AddRange(boats); context.SaveChanges(); } if (!context.Spots.Any()) { var spots = new Spot[] { new Spot { SpotNumber = 1, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 10, MaxLength = 30 }, new Spot { SpotNumber = 2, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 }, new Spot { SpotNumber = 3, MarinaId = 1, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 }, new Spot { SpotNumber = 4, MarinaId = 2, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 3 }, new Spot { SpotNumber = 5, MarinaId = 3, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 }, new Spot { SpotNumber = 1, MarinaId = 4, Available = true, Price = 50.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 1 }, new Spot { SpotNumber = 2, MarinaId = 4, Available = true, Price = 40.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30, LocationId = 2 }, new Spot { SpotNumber = 3, MarinaId = 4, Available = true, Price = 30.00, MaxDepth = 30, MaxWidth = 30, MaxLength = 30 } }; context.Spots.AddRange(spots); context.SaveChanges(); } if (!context.Bookings.Any()) { var bookings = new Booking[] { new Booking { BookingReferenceNo = 1, BoatId = 1, TotalPrice = 2, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 2, BoatId = 1, TotalPrice = 10, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 3, BoatId = 1, TotalPrice = 100, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 4, BoatId = 2, TotalPrice = 83, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 5, BoatId = 2, TotalPrice = 97, PaymentStatus = "not paid", CreationDate = DateTime.Now }, new Booking { BookingReferenceNo = 6, BoatId = 2, TotalPrice = 23, PaymentStatus = "not paid", CreationDate = DateTime.Now } }; context.Bookings.AddRange(bookings); context.SaveChanges(); } if (!context.BookingLines.Any()) { var bookingLines = new BookingLine[] { // Ongoing: True new BookingLine { Ongoing = true, BookingId = 1, SpotId = 1, DiscountedTotalPrice = 1, Confirmed = true, StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1) }, new BookingLine { Ongoing = false, BookingId = 1, SpotId = 2, DiscountedTotalPrice = 2, StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1) }, new BookingLine { Ongoing = false, BookingId = 1, SpotId = 3, DiscountedTotalPrice = 3, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4) }, // Ongoing: False new BookingLine { Ongoing = false, BookingId = 2, SpotId = 1, DiscountedTotalPrice = 4, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4) }, new BookingLine { Ongoing = false, BookingId = 2, SpotId = 2, DiscountedTotalPrice = 5, StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(4) }, new BookingLine { Ongoing = false, BookingId = 2, SpotId = 3, DiscountedTotalPrice = 6, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, // Ongoing: False new BookingLine { Ongoing = false, BookingId = 3, SpotId = 1, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, new BookingLine { Ongoing = false, BookingId = 3, SpotId = 2, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, new BookingLine { Ongoing = false, BookingId = 3, SpotId = 3, DiscountedTotalPrice = 10, StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(7) }, // Ongoing: False new BookingLine { Ongoing = false, BookingId = 4, SpotId = 1, DiscountedTotalPrice = 19, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15) }, new BookingLine { Ongoing = false, BookingId = 4, SpotId = 2, DiscountedTotalPrice = 11, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15) }, new BookingLine { Ongoing = false, BookingId = 4, SpotId = 3, DiscountedTotalPrice = 17, StartDate = DateTime.Now.AddDays(12), EndDate = DateTime.Now.AddDays(15) }, // Ongoing: True new BookingLine { Ongoing = true, BookingId = 5, SpotId = 1, DiscountedTotalPrice = 15, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25) }, new BookingLine { Ongoing = true, BookingId = 5, SpotId = 3, DiscountedTotalPrice = 16, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25) }, new BookingLine { Ongoing = true, BookingId = 5, SpotId = 2, DiscountedTotalPrice = 14, StartDate = DateTime.Now.AddDays(22), EndDate = DateTime.Now.AddDays(25) }, // Ongoing: True new BookingLine { Ongoing = false, BookingId = 6, SpotId = 1, DiscountedTotalPrice = 12 }, new BookingLine { Ongoing = true, BookingId = 6, SpotId = 2, DiscountedTotalPrice = 13 }, new BookingLine { Ongoing = true, BookingId = 6, SpotId = 5, DiscountedTotalPrice = 14 } }; context.BookingLines.AddRange(bookingLines); context.SaveChanges(); } }