public ActionResult GetNumberOfBikes(string dateString) { try { DateTime startDate = DateTime.ParseExact(dateString, "d/M/yyyy", CultureInfo.InvariantCulture); using (BikeDbContext db = new BikeDbContext()) { var bookings = db.Bookings.Where(b => b.EndDate >= startDate.Date).ToList(); int[] nums = new int[7]; for (int i = 0; i < 7; i++) { var count = 0; foreach (var b in bookings) { var date = startDate.AddDays(i).Date; if (b.StartDate.Date <= date && b.EndDate.Date >= date) { count++; } } nums[i] = count; } return(Json(nums, JsonRequestBehavior.AllowGet)); } } catch (System.FormatException e) { return(HttpNotFound()); } }
public ModelController(BikeDbContext db) { _db = db; ModelVM = new ModelViewModel() { Makes = _db.Makes.ToList(), Model = new Models.Model() }; }
public ModelController(BikeDbContext dbContext) { mDbContext = dbContext; ModelViewModel = new ModelViewModel { Makes = mDbContext.Makes.ToList(), Model = new Models.Model() }; }
public BikeModelController(BikeDbContext context) { _context = context; ModelVM = new BikeModelVM() { Makes = _context.Makes.ToList(), BikeModel = new Models.BikeModel() }; }
public ModelController(BikeDbContext db, IMapper mapper) // mapper is passed using dependency injection { _db = db; _mapper = mapper; ModelVM = new ModelViewModel() { Makes = _db.Makes.ToList(), Model = new Models.Model() }; }
public BikeController(BikeDbContext db) { _db = db; BikeVM = new BikeViewModel() { Makes = _db.Makes.ToList(), Models = _db.Models.ToList(), Bike = new Models.Bike() }; }
public MotorBikeController(BikeDbContext db, IWebHostEnvironment webHostEnvironment) { _db = db; _webHostEnvironment = webHostEnvironment; MotorBikeVM = new MotorBikeViewModel() { Makes = _db.Makes.ToList(), Models = _db.Models.ToList(), MotorBike = new Models.MotorBike() }; }
public async Task GetAsyncReturnsEmptyList() { // arrange this.bikeDbContext = new InMemoryDbContextFactory <Bike>(null, false).GetBikeDbContext(); var sut = CreateSut(this.bikeDbContext); // act var actual = await sut.GetAsync(); // assert actual.Should().NotBeNull().And.BeEmpty(); }
public async Task GetAsyncReturnsList() { // arrange var expected = GetExpectedModels(10).ToList(); this.bikeDbContext = new InMemoryDbContextFactory <Bike>(expected, true).GetBikeDbContext(); var sut = CreateSut(this.bikeDbContext); // act var actual = await sut.GetAsync(); // assert actual.Should().NotBeNull().And.BeEquivalentTo(expected); }
public InMemoryDbContextFactory(IEnumerable <T> data, bool seedData = true) { var options = new DbContextOptionsBuilder <BikeDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; context = new BikeDbContext(options); if (seedData == false) { return; } context.Set <T>().AddRange(data); context.SaveChanges(); }
public void GetByIdReturnsNull() { var bikeId = Guid.NewGuid(); var expected = new Bike { Id = Guid.NewGuid(), Colour = ExpectedColour, Model = ExpectedModel, Name = ExpectedName }; this.bikeDbContext = new InMemoryDbContextFactory <Bike>(new List <Bike> { expected }, true).GetBikeDbContext(); var sut = CreateSut(this.bikeDbContext); // act var actual = sut.GetById(bikeId); //assert actual.Should().BeNull(); }
public BrandsController(BikeDbContext context) { _context = context; }
public MakeController(BikeDbContext dbContext) { mDbContext = dbContext; mDbContext.GetType(); }
public MembershipDataSql(BikeDbContext bikeDbContext) { this.bikeDbContext = bikeDbContext; }
public BikeRepository(BikeDbContext context) { _context = context; _bikes = context.Bikes; }
public MakeController(BikeDbContext context) { _context = context; }
public OrderRepository(BikeDbContext context) { _context = context; _orders = context.Orders; }
protected static IQueryRepository <Bike> CreateSut(BikeDbContext bikeDbContext) { return(new QueryRepository <Bike>(bikeDbContext)); }
public QueryRepository(BikeDbContext bikeDbContext) { this.bikeDbContext = bikeDbContext; }
public CustomerDataSql(BikeDbContext bikeDbContext) { this.bikeDbContext = bikeDbContext; }
public MakeController(BikeDbContext db) { _db = db; }
public PurchaseDataSql(BikeDbContext bikeDbContext) { this.bikeDbContext = bikeDbContext; }