public async Task <ActionResult <BikeDto> > PostBike(BikeDto bike)
        {
            Bike b = BikeDto.FromBikeDto(bike);

            _context.Bikes.Add(b);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBike", new { id = bike.Id }, BikeDto.ToBikeDto(b)));
        }
        public async Task <ActionResult <BikeDto> > GetBike(int id)
        {
            var bike = await _context.Bikes.FindAsync(id);

            if (bike == null)
            {
                return(NotFound());
            }

            return(BikeDto.ToBikeDto(bike));
        }
        public async Task <ActionResult <BikeDto> > DeleteBike(int id)
        {
            var bike = await _context.Bikes.FindAsync(id);

            if (bike == null)
            {
                return(NotFound());
            }

            _context.Bikes.Remove(bike);
            await _context.SaveChangesAsync();

            return(BikeDto.ToBikeDto(bike));
        }
        public ActionResult <IEnumerable <BikeDto> > GetAvailableBikes([FromQuery] string sortBy = "")
        {
            var rentals        = _context.Rentals;
            var bikes          = _context.Bikes;
            var availableBikes = bikes.Where(b => !rentals.Any(r => r.BikeId == b.Id));

            switch (sortBy)
            {
            case "": break;

            case "priceFirstHour": availableBikes = availableBikes.OrderBy(b => b.PriceFirstHour); break;

            case "priceAdditionalHours": availableBikes = availableBikes.OrderBy(b => b.PricePerAdditionalHour); break;

            case "purchaseDate": availableBikes = availableBikes.OrderByDescending(b => b.PurchaseDate); break;

            default: return(NotFound("No such filter method found"));
            }

            return(BikeDto.ToBikeDto(availableBikes.ToList()));
        }
 public ActionResult <IEnumerable <BikeDto> > GetBikes()
 {
     return(BikeDto.ToBikeDto(_context.Bikes.ToList()));
 }