public IActionResult PutPricingStrategy([FromRoute] int id, [FromBody] PricingStrategy pricingStrategy) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pricingStrategy.Id) { return(BadRequest()); } try { _unitOfWork.PricingStrategies.Update(pricingStrategy); } catch (DbUpdateConcurrencyException) { if (!PricingStrategiesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Should_GetPricingStrategyById(int id) { using (ApplicationDbContext context = SeedContext()) { var entity = new DbRepository <PricingStrategy>(context); PricingStrategy getPricingStrategy = entity.GetById(id); Assert.NotNull(getPricingStrategy); } }
public IActionResult PostPricingStrategy([FromBody] PricingStrategy pricingStrategy) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _unitOfWork.PricingStrategies.Create(pricingStrategy); return(CreatedAtAction("GetPricingStrategy", new { id = pricingStrategy.Id }, pricingStrategy)); }
public void Should_AddPricingStrategy() { using (ApplicationDbContext context = SeedContext()) { PricingStrategy pricingStrategy = new PricingStrategy { Name = "Test", Description = "Test" }; var entity = new DbRepository <PricingStrategy>(context); bool created = entity.Create(pricingStrategy); Assert.True(created); } }
public void ShouldNot_DeletePricingStrategy_NotFound() { PricingStrategy testPricingStrategy = new PricingStrategy { Id = 10 }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.PricingStrategies.GetById(10)).Returns((PricingStrategy)null); PricingStrategiesController controller = new PricingStrategiesController(mock.Object); var result = controller.DeletePricingStrategy(10); Assert.IsType <NotFoundResult>(result); }
public void Should_GetPricingStrategy() { PricingStrategy testPricingStrategy = new PricingStrategy { Id = 1, Name = "Test1", Description = "Test", PricingStrategyItems = new List <PricingStrategyItem>() }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.PricingStrategies.GetById(1)).Returns(testPricingStrategy); PricingStrategiesController controller = new PricingStrategiesController(mock.Object); var pricingStrategy = controller.GetPricingStrategy(1); Assert.IsType <OkObjectResult>(pricingStrategy); }
public void ShouldNot_PutPricingStrategy_IdMismatch() { PricingStrategy testPricingStrategy = new PricingStrategy { Id = 1 }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.PricingStrategies.Update(testPricingStrategy)).Returns(true); PricingStrategiesController controller = new PricingStrategiesController(mock.Object); var pricingStrategy = controller.PutPricingStrategy(2, testPricingStrategy); Assert.IsType <BadRequestResult>(pricingStrategy); }
public void Should_PutPricingStrategy() { PricingStrategy testPricingStrategy = new PricingStrategy { Id = 1 }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.PricingStrategies.Update(testPricingStrategy)).Returns(true); PricingStrategiesController controller = new PricingStrategiesController(mock.Object); var pricingStrategies = controller.PutPricingStrategy(1, testPricingStrategy); Assert.IsType <NoContentResult>(pricingStrategies); }
public void Should_DeletePricingStrategy() { PricingStrategy testPricingStrategy = new PricingStrategy { Id = 1 }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.PricingStrategies.GetById(1)).Returns(testPricingStrategy); mock.Setup(f => f.PricingStrategies.Delete(testPricingStrategy)).Returns(true); PricingStrategiesController controller = new PricingStrategiesController(mock.Object); var result = controller.DeletePricingStrategy(1); Assert.IsType <OkObjectResult>(result); }
public void Resolve(string productName, decimal productPrice, int quantity, PricingStrategy pricingStrategy, double?expectedPrice) { var promotionRepository = new Mock <IPromotionRepository>(); promotionRepository.Setup(p => p.FindByProduct("Apple")).Returns( new List <Promotion> { new Promotion("Test", "Apple", PromotionType.OnSale, null, 2.5m, null, DateTime.UtcNow.AddDays(-2), DateTime.UtcNow.AddDays(1), null), new Promotion("Test 2", "Apple", PromotionType.GroupSale, 2, 2.0m, null, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), null), new Promotion("Test 3", "Apple", PromotionType.AdditionalSale, 1, null, 0.5f, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), null) }); var priceResolver = new PriceResolver(promotionRepository.Object); var price = priceResolver.Resolve(productName, productPrice, quantity, pricingStrategy); Assert.Equal((decimal?)expectedPrice, price); }
public void ShouldNot_PutPricingStrategy_ModelStateError() { PricingStrategy testPricingStrategy = new PricingStrategy { Id = 1 }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.PricingStrategies.Update(testPricingStrategy)).Returns(true); PricingStrategiesController controller = new PricingStrategiesController(mock.Object); controller.ModelState.AddModelError("TestError", "Error"); var pricingStrategy = controller.PutPricingStrategy(1, testPricingStrategy); Assert.IsType <BadRequestObjectResult>(pricingStrategy); }
public void ShouldNot_PostPricingStrategy_ModelStateError() { PricingStrategy testPricingStrategy = new PricingStrategy { Id = 1, Name = "Test1", Description = "Test", PricingStrategyItems = new List <PricingStrategyItem>() }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.PricingStrategies.Create(testPricingStrategy)).Returns(true); mock.Setup(f => f.PricingStrategies.GetById(1)).Returns(testPricingStrategy); PricingStrategiesController controller = new PricingStrategiesController(mock.Object); controller.ModelState.AddModelError("TestError", "Error"); var pricingStrategy = controller.PostPricingStrategy(testPricingStrategy); Assert.IsType <BadRequestObjectResult>(pricingStrategy); }
public void Should_DeletePricingStrategy() { using (ApplicationDbContext context = SeedContext()) { var entity = new DbRepository <PricingStrategy>(context); var pricingStrategy = new PricingStrategy { Id = 1 }; if (pricingStrategy == null) { Assert.True(false); } bool deleted = entity.Delete(pricingStrategy); Assert.True(deleted); } }
public void Should_PricingStrategyExist() { using (ApplicationDbContext context = SeedContext()) { var entity = new DbRepository <PricingStrategy>(context); var pricingStrategy = new PricingStrategy { Id = 1 }; if (pricingStrategy == null) { Assert.True(false); } bool exists = entity.Exists(pricingStrategy); Assert.True(exists); } }
public Sale Checkout(string[] productNames, PricingStrategy pricingStrategy = PricingStrategy.Lowest) { if (productNames == null || !productNames.Any()) { throw new ArgumentException(nameof(productNames)) var saleItems = new List <SaleItem>(); } foreach (var productName in productNames.GroupBy(x => x)) { var product = productRepository.Find(productName.Key); if (product == null) { throw new ProductNotFoundException(productName.Key); } var price = priceResolver.Resolve(product.Name, product.Price, productName.Count(), pricingStrategy); saleItems.Add(new SaleItem(productName.Key, productName.Count(), price)); } return(new Sale(saleItems)); }
public async void Should_GetShowingAllocations() { // add seed data for showing & foreign dependencies var client = _factory.CreateClient(); // spoof admin access IJwtManager jwtManager = new InMemoryJwtManager(_configuration); string testToken = await jwtManager.GenerateJwtStringAsync("*****@*****.**", new List <Claim> { new Claim(ClaimTypes.Role, "admin") }); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + testToken); // get antiforgery token, and add to header var aftResponse = await client.GetAsync("/api/account/getCSRFToken"); var tokenData = JsonConvert.DeserializeAnonymousType(aftResponse.Content.ReadAsStringAsync().Result, new { Token = "", TokenName = "" }); client.DefaultRequestHeaders.Add(tokenData.TokenName, tokenData.Token); Event @event = new Event { Name = "Test Event", Description = "Event Desc", Image = "", Duration = 120, AgeRating = AgeRatingType.BBFC_PG }; string json = JsonConvert.SerializeObject(@event); var content = new StringContent(json, Encoding.UTF8, "application/json"); var postResponse = await client.PostAsync("api/events", content); Venue venue = new Venue { Name = "Test Venue", Description = "Venue Desc", Address1 = "Addr1", Address2 = "Addr2", Address3 = "Addr3", Address4 = "Addr4", Address5 = "Addr5", ContactPhone = "", Image = "", Website = "", Instagram = "", Facebook = "", Twitter = "", Facilities = FacilityFlags.Bar | FacilityFlags.GuideDogsPermitted, LatLong = "" }; json = JsonConvert.SerializeObject(venue); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/venues", content); Room room = new Room { Name = "Test Room", Description = "Room Desc", Columns = 10, Rows = 10, Isles = "", VenueId = 1 }; json = JsonConvert.SerializeObject(room); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/rooms", content); PricingStrategy strategy = new PricingStrategy { Name = "Test Strategy", Description = "Strategy Desc" }; json = JsonConvert.SerializeObject(strategy); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/pricingstrategies", content); Showing showing = new Showing { Id = 0, StartTime = DateTime.Now, EndTime = DateTime.Now.AddMinutes(120), PricingStrategyId = 1, EventId = 1, RoomId = 1 }; json = JsonConvert.SerializeObject(showing); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/showings", content); Customer customer = new Customer { Address1 = "", Address2 = "", Address3 = "", Address4 = "", Address5 = "", ContactEmail = "", ContactPhone = "", FirstName = "", LastName = "" }; json = JsonConvert.SerializeObject(customer); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/customers", content); Booking booking = new Booking { Id = 0, BookedDate = DateTime.Now, ShowingId = 1, CustomerId = 1, Status = BookingStatus.PaymentComplete }; json = JsonConvert.SerializeObject(booking); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/bookings", content); for (int i = 0; i < 5; i++) { BookingItem bookingItem = new BookingItem { Id = 0, AgreedPrice = 4.2f, AgreedPriceName = "", BookingId = 1, Location = i }; json = JsonConvert.SerializeObject(bookingItem); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/bookingitems", content); } var availabilityResponse = await client.GetAsync("api/showings/allocations/1"); if (availabilityResponse.StatusCode != System.Net.HttpStatusCode.OK) { Assert.True(false); } string data = await availabilityResponse.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(data)) { Assert.True(false); } }
public async void Should_GetShowings_IncludeEventRoomVenue(string name) { // add seed data for showing & foreign dependencies var client = _factory.CreateClient(); // spoof admin access IJwtManager jwtManager = new InMemoryJwtManager(_configuration); string testToken = await jwtManager.GenerateJwtStringAsync("*****@*****.**", new List <Claim> { new Claim(ClaimTypes.Role, "admin") }); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + testToken); // get antiforgery token, and add to header var aftResponse = await client.GetAsync("/api/account/getCSRFToken"); var tokenData = JsonConvert.DeserializeAnonymousType(aftResponse.Content.ReadAsStringAsync().Result, new { Token = "", TokenName = "" }); client.DefaultRequestHeaders.Add(tokenData.TokenName, tokenData.Token); Event @event = new Event { Name = "Test Event", Description = "Event Desc", Image = "", Duration = 120, AgeRating = AgeRatingType.BBFC_PG }; string json = JsonConvert.SerializeObject(@event); var content = new StringContent(json, Encoding.UTF8, "application/json"); var postResponse = await client.PostAsync("api/events", content); Venue venue = new Venue { Name = name, Description = "Venue Desc", Address1 = "Addr1", Address2 = "Addr2", Address3 = "Addr3", Address4 = "Addr4", Address5 = "Addr5", ContactPhone = "", Image = "", Website = "", Instagram = "", Facebook = "", Twitter = "", Facilities = FacilityFlags.Bar | FacilityFlags.GuideDogsPermitted, LatLong = "" }; json = JsonConvert.SerializeObject(venue); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/venues", content); Room room = new Room { Name = "Test Room", Description = "Room Desc", Columns = 10, Rows = 10, Isles = "", VenueId = 1 }; json = JsonConvert.SerializeObject(room); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/rooms", content); PricingStrategy strategy = new PricingStrategy { Name = "Test Strategy", Description = "Strategy Desc" }; json = JsonConvert.SerializeObject(strategy); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/pricingstrategies", content); Showing showing = new Showing { Id = 0, StartTime = DateTime.Now, EndTime = DateTime.Now.AddMinutes(120), PricingStrategyId = 1, EventId = 1, RoomId = 1 }; json = JsonConvert.SerializeObject(showing); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/showings", content); // get response, included expanded foreign records var filterResponse = await client.GetAsync($"/api/showings?$expand=Event,Room($expand=Venue)&$filter=Room/Venue/Name eq '{name}'"); string data = await filterResponse.Content.ReadAsStringAsync(); List <Showing> getShowings = await filterResponse.Content.ReadAsAsync <List <Showing> >(); if (getShowings != null && getShowings.Count() > 0) { Assert.True(getShowings[0].Event != null && getShowings[0].Room != null && getShowings[0].Room.Venue != null); } else { if (getShowings.Count == 0) { Assert.NotEmpty(getShowings); } Assert.NotNull(getShowings); } }
public PackageType(PricingStrategy pricingStrategy) { this.PricingStrategy = pricingStrategy; }
private decimal?PromotionPrice(string productName, decimal productPrice, int quantity, PricingStrategy pricingStrategy) { var promotions = promotionRepository.FindByProduct(productName); if (!promotions.Any()) { return(null); } decimal?price = null; foreach (var promotion in promotions) { IApplyPromotion applyPromotion = null; switch (promotion.PromotionType) { case PromotionType.OnSale: applyPromotion = new ApplyOnSalePromotion(promotion.Price.Value); break; case PromotionType.GroupSale: applyPromotion = new ApplyGroupSalePromotion(promotion.Quantity.Value, promotion.Price.Value, productPrice); break; case PromotionType.AdditionalSale: applyPromotion = new ApplyAdditionalSalePromotion(promotion.Quantity.Value, promotion.Discount.Value, productPrice); break; default: throw new PromotionTypeUnhandledException(promotion.PromotionType); } var promotionPrice = applyPromotion.Apply(quantity); if (!promotionPrice.HasValue) { continue; } price = !price.HasValue ? promotionPrice : (pricingStrategy == PricingStrategy.Lowest && promotionPrice < price ? promotionPrice : (pricingStrategy == PricingStrategy.Highest && promotionPrice > price ? promotionPrice : price)); } return(price); }
public decimal Resolve(string productName, decimal productPrice, int quantity, PricingStrategy pricingStrategy) { if (string.IsNullOrWhiteSpace(productName)) { throw new ArgumentException(nameof(productName)); } if (productPrice == default) { throw new ArgumentException(nameof(productPrice)); } var price = PromotionPrice(productName, productPrice, quantity, pricingStrategy); return(price ?? (productPrice * quantity)); }
public async void Should_GetRoom_WithShowingOnSpecifiedDate() { var client = _factory.CreateClient(); // spoof admin access IJwtManager jwtManager = new InMemoryJwtManager(_configuration); string testToken = await jwtManager.GenerateJwtStringAsync("*****@*****.**", new List <Claim> { new Claim(ClaimTypes.Role, "admin") }); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + testToken); // get antiforgery token, and add to header var aftResponse = await client.GetAsync("/api/account/getCSRFToken"); var tokenData = JsonConvert.DeserializeAnonymousType(aftResponse.Content.ReadAsStringAsync().Result, new { Token = "", TokenName = "" }); client.DefaultRequestHeaders.Add(tokenData.TokenName, tokenData.Token); // add seed data for dependencies Event @event = new Event { Name = "Test Event", Description = "Event Desc", Image = "", Duration = 120, AgeRating = AgeRatingType.BBFC_PG }; string json = JsonConvert.SerializeObject(@event); var content = new StringContent(json, Encoding.UTF8, "application/json"); var postResponse = await client.PostAsync("api/events", content); Venue venue = new Venue { Name = "Test Venue", Description = "Venue Desc", Address1 = "Addr1", Address2 = "Addr2", Address3 = "Addr3", Address4 = "Addr4", Address5 = "Addr5", ContactPhone = "", Image = "", Website = "", Instagram = "", Facebook = "", Twitter = "", Facilities = FacilityFlags.Bar | FacilityFlags.GuideDogsPermitted, LatLong = "" }; json = JsonConvert.SerializeObject(venue); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/venues", content); Room room = new Room { Name = "Test Room", Description = "Room Desc", Columns = 10, Rows = 10, Isles = "", VenueId = 1 }; json = JsonConvert.SerializeObject(room); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/rooms", content); PricingStrategy strategy = new PricingStrategy { Name = "Test Strategy", Description = "Strategy Desc" }; json = JsonConvert.SerializeObject(strategy); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/pricingstrategies", content); Showing showing = new Showing { Id = 0, StartTime = new DateTime(2018, 12, 1), EndTime = new DateTime(2018, 12, 2), PricingStrategyId = 1, EventId = 1, RoomId = 1 }; json = JsonConvert.SerializeObject(showing); content = new StringContent(json, Encoding.UTF8, "application/json"); postResponse = await client.PostAsync("api/showings", content); var filterResponse = await client.GetAsync($"api/rooms?$expand=Showings&$filter=Showings/any(s : date(s/StartTime) ge 2018-12-1 and date(s/StartTime) lt 2018-12-2 and s/EventId eq 1)&$select=Id,Name,Showings"); string data = await filterResponse.Content.ReadAsStringAsync(); List <Room> getRooms = await filterResponse.Content.ReadAsAsync <List <Room> >(); if (getRooms != null && getRooms.Count() > 0) { Assert.True(getRooms[0].Showings != null); } else { if (getRooms.Count == 0) { Assert.NotEmpty(getRooms); } Assert.NotNull(getRooms); } }
public static void Generate(ApplicationDbContext context, int days = 7, int rooms = 5, int minCols = 6, int maxCols = 12, int minRows = 6, int maxRows = 12) { // create demo data for booking system Random random = new Random(); // cache initial start time, so that all showings/bookings are accurately ahead of this time DateTime now = DateTime.Now; // then create entities which don't have strict relational dependencies // features List <Feature> features = new List <Feature>() { new Feature { Name = "Saver Wednesday Feature", Title = " ", Detail = " ", Link = "#", Image = ImageToBase64("Resources/images/feature/feature1.png"), Order = 2 }, new Feature { Name = "Booking Showcase", Title = " ", Detail = " ", Link = "https://github.com/adamlarner/angularbooking", Image = ImageToBase64("Resources/images/feature/feature2.png"), Order = 1 }, }; context.AddRange(features); context.SaveChanges(); // events List <Event> events = new List <Event>() { new Event { Name = "Office Party - The Movie", Description = "Jeff and his chums have decided to host the most epic office party ever! Featuring photocopiers, staplers, and the occasional post-it note, this movie offers all the amazing shenanigans that you'd expect around the water cooler, and more!", AgeRating = AgeRatingType.PEGI_12A, Duration = 210, Image = ImageToBase64("Resources/images/event/Comedy-1_Advert.jpg") }, new Event { Name = "Feeding Time", Description = "When Mittens decides that tinned food isn't to his liking, he instead looks at his owner and friends for an alternative diet...", AgeRating = AgeRatingType.PEGI_18, Duration = 124, Image = ImageToBase64("Resources/images/event/Horror-1_Advert.jpg") }, new Event { Name = "The journey to the Moon", Description = "A never before seen take on the first moon landing, featuring plastic figurines and terrible voice acting!", AgeRating = AgeRatingType.PEGI_Universal, Duration = 162, Image = ImageToBase64("Resources/images/event/Documentary-1_Advert.jpg") } }; context.Events.AddRange(events); context.SaveChanges(); //venues List <Venue> venues = new List <Venue>() { new Venue { Name = "Arty Theater", Description = "This artistic-looking building provides all the necessary features required for watching the latest and greatest film releases. At least in theory; the only showings nowadays feature evil cats and plastic astronauts.", Address1 = "123 Sample Street", Address2 = "Sample Town", Address3 = "Sample City", Address4 = "Sample Region", Address5 = "Sample Postcode", ContactPhone = "0123 456 7890", Website = "http://www.website.com", Facilities = FacilityFlags.AudioDescribed | FacilityFlags.Bar | FacilityFlags.Parking | FacilityFlags.Toilets, Facebook = "http://www.facebook.com", Twitter = "http://www.twitter.com", Instagram = "http://www.instagram.com", Image = ImageToBase64("Resources/images/venue/Arty Theater.jpg"), LatLong = "#" }, new Venue { Name = "Blue Theater", Description = "Don't let the garish colour's fool you, for this theater boasts not one, but two subtitle language settings! The screen is also a little makeshift, on account of the theater not really being designed for showing films...", Address1 = "Blue Street", Address2 = "Blueberryville", Address3 = "Blue City", Address4 = "Blueshire", Address5 = "B1 BBB", ContactPhone = "0123 131 1313", Website = "http://www.blueblueblue.com", Facilities = FacilityFlags.Bar | FacilityFlags.Toilets | FacilityFlags.Parking | FacilityFlags.Subtitled | FacilityFlags.DisabledAccess, Facebook = "http://www.facebook.com", Twitter = "http://www.twitter.com", Instagram = "http://www.instagram.com", Image = ImageToBase64("Resources/images/venue/Blue Theater.jpg"), LatLong = "#" }, new Venue { Name = "Concrete Theater", Description = "Made from pure concrete, this theater has fantastic acoustic properties! Due to limited access, this theater is not wheelchair friendly. It also smells quite bad...", Address1 = "1 Concrete Theater", Address2 = "Industrial Zone", Address3 = "Gritty", Address4 = "Gray City", Address5 = "GR1 IND", ContactPhone = "0123 111 2233", Website = "http://www.graygraygray.com", Facilities = FacilityFlags.AudioDescribed | FacilityFlags.Bar | FacilityFlags.Toilets, Facebook = "http://www.facebook.com", Twitter = "http://www.twitter.com", Instagram = "http://www.instagram.com", Image = ImageToBase64("Resources/images/venue/Concrete Theater.jpg"), LatLong = "#" }, new Venue { Name = "Run-down Theater", Description = "This super-budget theater complex has focused all of it's budget on the interior, and thus looks fairly run-down on the outside. It has a functioning toilet, and there's an off-license down the road. Very classy!", Address1 = "999 Dump Street", Address2 = "Grimeville", Address3 = "Dirt County", Address4 = "Crumbling City", Address5 = "CR1 APP", ContactPhone = "999", Website = "http://www.crackymccrackface.com", Facilities = FacilityFlags.Parking | FacilityFlags.Toilets | FacilityFlags.DisabledAccess | FacilityFlags.GuideDogsPermitted, Facebook = "http://www.facebook.com", Twitter = "http://www.twitter.com", Instagram = "http://www.instagram.com", Image = ImageToBase64("Resources/images/venue/Rundown Theater.jpg"), LatLong = "#" } }; context.Venues.AddRange(venues); context.SaveChanges(); // pricing PricingStrategy defaultPricing = new PricingStrategy { Name = "Default Pricing", Description = "Default Pricing", PricingStrategyItems = new List <PricingStrategyItem> { new PricingStrategyItem { Name = "Adult", Description = "Adult admission fee", Price = 8.99f }, new PricingStrategyItem { Name = "Child", Description = "Child admission fee", Price = 6.99f }, new PricingStrategyItem { Name = "OAP", Description = "Old-aged Pensioner (Over 65) admission fee", Price = 5.99f }, new PricingStrategyItem { Name = "Student", Description = "Student admission fee (ID required)", Price = 5.99f } } }; PricingStrategy saverPricing = new PricingStrategy { Name = "Saver Pricing", Description = "Discount Pricing for Wednesday", PricingStrategyItems = new List <PricingStrategyItem> { new PricingStrategyItem { Name = "Adult", Description = "Adult admission fee", Price = 6.99f }, new PricingStrategyItem { Name = "Child", Description = "Child admission fee", Price = 4.99f }, new PricingStrategyItem { Name = "OAP", Description = "Old-aged Pensioner (Over 65) admission fee", Price = 3.99f }, new PricingStrategyItem { Name = "Student", Description = "Student admission fee (ID required)", Price = 3.99f } } }; context.PricingStrategies.AddRange(defaultPricing, saverPricing); context.SaveChanges(); // create 5 screens for each venue, and fill each screen with different film showings for (int i = 0; i < venues.Count; i++) { for (int j = 0; j < 5; j++) { int rows = random.Next(6, 12); int columns = random.Next(6, 12); Room newRoom = new Room { VenueId = venues[i].Id, Name = $"Screen {j + 1}", Description = $"Basic Screen, with a total capacity of {rows * columns} seats.", Rows = rows, Columns = columns, Isles = $"{{ \"rows\": [2, {rows - 2}], \"columns\": [2, {columns - 2}] }}" }; context.Rooms.Add(newRoom); context.SaveChanges(); // create showings for next 7 days List <Showing> showings = new List <Showing>(); for (int k = 0; k < 7; k++) { DateTime currentDate = now.AddDays(k); // generate random event id int currentEventId = random.Next(1, 4); // create daily showings (3 hour slots, starting at 9:00) for (int l = 9; l < 23; l += 3) { Showing showing = new Showing { EventId = currentEventId, PricingStrategyId = currentDate.DayOfWeek == DayOfWeek.Wednesday ? 2 : 1, // discount pricing for wednesday RoomId = newRoom.Id, StartTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, l, 0, 0), EndTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, l + 2, 40, 0) // 20 minute interlude for cleaning }; showings.Add(showing); } } // bulk add context.AddRange(showings); context.SaveChanges(); } } }