Beispiel #1
0
        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()
     };
 }
Beispiel #4
0
 public BikeModelController(BikeDbContext context)
 {
     _context = context;
     ModelVM  = new BikeModelVM()
     {
         Makes     = _context.Makes.ToList(),
         BikeModel = new Models.BikeModel()
     };
 }
Beispiel #5
0
        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()
            };
        }
Beispiel #6
0
        public BikeController(BikeDbContext db)
        {
            _db = db;

            BikeVM = new BikeViewModel()
            {
                Makes  = _db.Makes.ToList(),
                Models = _db.Models.ToList(),
                Bike   = new Models.Bike()
            };
        }
Beispiel #7
0
        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()
            };
        }
Beispiel #8
0
        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();
        }
Beispiel #9
0
        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();
        }
Beispiel #11
0
        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();
        }
Beispiel #12
0
 public BrandsController(BikeDbContext context)
 {
     _context = context;
 }
 public MakeController(BikeDbContext dbContext)
 {
     mDbContext = dbContext;
     mDbContext.GetType();
 }
Beispiel #14
0
 public MembershipDataSql(BikeDbContext bikeDbContext)
 {
     this.bikeDbContext = bikeDbContext;
 }
 public BikeRepository(BikeDbContext context)
 {
     _context = context;
     _bikes   = context.Bikes;
 }
Beispiel #16
0
 public MakeController(BikeDbContext context)
 {
     _context = context;
 }
Beispiel #17
0
 public OrderRepository(BikeDbContext context)
 {
     _context = context;
     _orders  = context.Orders;
 }
Beispiel #18
0
 protected static IQueryRepository <Bike> CreateSut(BikeDbContext bikeDbContext)
 {
     return(new QueryRepository <Bike>(bikeDbContext));
 }
Beispiel #19
0
 public QueryRepository(BikeDbContext bikeDbContext)
 {
     this.bikeDbContext = bikeDbContext;
 }
Beispiel #20
0
 public CustomerDataSql(BikeDbContext bikeDbContext)
 {
     this.bikeDbContext = bikeDbContext;
 }
Beispiel #21
0
 public MakeController(BikeDbContext db)
 {
     _db = db;
 }
Beispiel #22
0
 public PurchaseDataSql(BikeDbContext bikeDbContext)
 {
     this.bikeDbContext = bikeDbContext;
 }