Exemple #1
0
        /// <summary>
        /// Get bike information
        /// </summary>
        /// <param name="bikeId">The bike id you want to get information</param>
        /// <param name="category">The bike type</param>
        /// <param name="stationName">Representing station name contain the bike</param>
        /// <param name="stationAddress">Repensting station address contain the bike</param>
        /// <returns>The BaseBike representing the bike you want to get</returns>
        public BaseBike ViewBikeDetail(int bikeId, BikeCategory category, ref string stationName, ref string stationAddress)
        {
            BaseBike bike = null;

            if (category == BikeCategory.BIKE)
            {
                bike = bikeService.GetBikeById(bikeId);
            }
            else if (category == BikeCategory.ELECTRIC)
            {
                bike = electricBikeService.GetBikeById(bikeId);
            }
            else if (category == BikeCategory.TANDEM)
            {
                bike = tandemService.GetBikeById(bikeId);
            }
            if (bike == null)
            {
                return(null);
            }
            Station station = stationService.GetStationById(bike.StationId);

            stationName    = station.NameStation;
            stationAddress = station.AddressStation;
            return(bike);
        }
Exemple #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newBike = new Bike();

            if (selectedCategories != null)
            {
                newBike.BikeCategories = new List <BikeCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new BikeCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newBike.BikeCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Bike>(
                    newBike,
                    "Bike",
                    i => i.Series, i => i.Brand,
                    i => i.Price, i => i.AparitionDate, i => i.Size, i => i.StoreID))
            {
                _context.Bike.Add(newBike);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newBike);
            return(Page());
        }
Exemple #3
0
        /// <summary>
        /// Get bike information
        /// </summary>
        /// <param name="bikeId">The bike id you want to get information</param>
        /// <param name="category">The bike type</param>
        /// <returns>The BaseBike representing the bike you want to get</returns>
        public BaseBike ViewBikeDetail(int bikeId, BikeCategory category)
        {
            BaseBike bike = null;

            if (category == BikeCategory.BIKE)
            {
                bike = bikeService.GetBikeById(bikeId);
            }
            else if (category == BikeCategory.ELECTRIC)
            {
                bike = electricBikeService.GetBikeById(bikeId);
            }
            else if (category == BikeCategory.TANDEM)
            {
                bike = tandemService.GetBikeById(bikeId);
            }
            return(bike);
        }
Exemple #4
0
 /// <summary>
 /// Display bike information
 /// </summary>
 /// <param name="bike">The bike information</param>
 /// <param name="stationName">The station name contain this bike</param>
 /// <param name="stationAddress">The station address contain this bike</param>
 public void FillBikeInformation(BaseBike bike, string stationName, string stationAddress)
 {
     stationRtb.Text     = $"{stationName}\n{stationAddress}";
     qrCodeTxt.Text      = bike.QRCode;
     manufactureTxt.Text = bike.Manufacturer;
     avatarPb.Image      = Image.FromFile(bike.Images);
     if (bike.BikeStatus)
     {
         statusBikeLbl.Text      = "Renting";
         statusBikeLbl.BackColor = Color.Red;
         viewRentingBut.Visible  = true;
         rentThisBikeBut.Visible = false;
     }
     else
     {
         statusBikeLbl.Text      = "Available";
         statusBikeLbl.BackColor = Color.Green;
         viewRentingBut.Visible  = false;
         rentThisBikeBut.Visible = true;
     }
     if (bike.Category == "bike")
     {
         categoryBikeTxt.Text = "Xe đạp thường";
         powerTxt.Text        = "Không có thông tin";
         licenceTxt.Text      = "Không có thông tin";
         this.category        = BikeCategory.BIKE;
     }
     else if (bike.Category == "tandem")
     {
         categoryBikeTxt.Text = "Xe đạp đôi";
         powerTxt.Text        = "Không có thông tin";
         licenceTxt.Text      = "Không có thông tin";
         this.category        = BikeCategory.TANDEM;
     }
     else
     {
         ElectricBike electric = bike as ElectricBike;
         categoryBikeTxt.Text = "Xe đạp điện";
         powerTxt.Text        = $"{electric.Powers}%";
         licenceTxt.Text      = electric.LicensePlate;
         this.category        = BikeCategory.ELECTRIC;
     }
     this.bike = bike;
 }
Exemple #5
0
        /// <summary>
        /// Calculate rental fee for rental bike
        /// </summary>
        /// <param name="timeRent">The time that the user has rented the car</param>
        /// <param name="category">The category of rental bike</param>
        /// <returns>The rental money that use must rent</returns>
        public int CalculateFee(string timeRent, BikeCategory category)
        {
            string[] times       = timeRent.Split(':');
            double   hour        = Int64.Parse(times[0]);
            double   minute      = Int64.Parse(times[1]);
            double   second      = Int64.Parse(times[2]);
            double   timeMinutes = 60 * hour + minute + Math.Abs(second / 60) - 10;

            if (category != BikeCategory.BIKE)
            {
                timeMinutes = 1.5 * timeMinutes;
            }
            if (timeMinutes <= 0)
            {
                return(0);
            }
            timeMinutes -= 30;
            if (timeMinutes <= 0)
            {
                return(10000);
            }
            return((int)(10000 + Math.Abs(timeMinutes / 15)));
        }
 /// <summary>
 /// Fill transaction form with transaction's information when user process transaction for pay deposit money
 /// </summary>
 /// <param name="bike">the rental bike</param>
 /// <param name="card">The card</param>
 public void FillTransactionInformationWhenRentBike(BaseBike bike, Card card)
 {
     this.bike  = bike;
     this.card  = card;
     this.isPay = false;
     if (bike is Bike)
     {
         category = BikeCategory.BIKE;
     }
     else if (bike is ElectricBike)
     {
         category = BikeCategory.ELECTRIC;
     }
     else if (bike is Tandem)
     {
         category = BikeCategory.TANDEM;
     }
     this.deposit            = 40 * bike.Value / 100;
     depositTxt.Text         = String.Format("{0:n0}", this.deposit);
     rentalMoneyTxt.Text     = "Không có dữ liệu";
     transactionDateTxt.Text = "Không có dữ liệu";
     cancelBut.Visible       = true;
 }
 /// <summary>
 /// Fill transaction form with transaction's information when user process transaction for pay rental money
 /// </summary>
 /// <param name="stationId">The return station id</param>
 /// <param name="bike">The rental need to return</param>
 public void FillTransactionInformationWhenPay(int stationId, BaseBike bike)
 {
     this.bike               = bike;
     this.stationId          = stationId;
     remainMoneyTxt.Text     = "1000000";
     transactionDateTxt.Text = DateTime.Now.ToString("f");
     cancelBut.Visible       = false;
     this.isPay              = true;
     if (bike is Bike)
     {
         category = BikeCategory.BIKE;
     }
     else if (bike is ElectricBike)
     {
         category = BikeCategory.ELECTRIC;
     }
     else if (bike is Tandem)
     {
         category = BikeCategory.TANDEM;
     }
     rentalMoney         = rentBikeController.CalculateFee(rentingBikeForm.GetTotalTimeRent(), category);
     rentalMoneyTxt.Text = (rentalMoney == 0) ? "Miễn phí" : rentalMoney.ToString();
 }