コード例 #1
0
        /// <summary>
        /// Precondition: The given reservation must exist in the database
        /// Activates the given reservation. This means the car has been rented to a customer.
        /// A car is assigned and the car mileage is tracked.
        /// </summary>
        /// <param name="reservationId"></param>
        /// <returns>Returns the ActivatedReservation class that was created.</returns>
        ///

        public async Task <ActivatedReservation> activateReservation(int reservationId)
        {
            RentalCar car = await db.getAvailableRentalCar(reservationId);

            var res = await db.getReservation(reservationId);

            if (res.cancelled)
            {
                throw new InvalidOperationException("A cancelled reservation cannot be activated.");
            }

            ActivatedReservation activatedReservation = new ActivatedReservation(res, car, car.currentMileage, true);

            if (activatedReservation.reservation.expectedReturnDate < DateTime.Now ||
                activatedReservation.reservation.rentalDate > DateTime.Now)
            {
                throw new InvalidOperationException("The rental date has not yet been passed. " +
                                                    "Cannot activate reservation. " +
                                                    "\nGiven startDate: " + activatedReservation.reservation.rentalDate +
                                                    "\nGiven endDate: " + activatedReservation.reservation.rentalDate);
            }

            context.activatedReservations.Add(activatedReservation);
            await context.SaveChangesAsync();

            return(activatedReservation);
        }
コード例 #2
0
 private void Rent_Click(object sender, RoutedEventArgs e)
 {
     if (RentalCardGrid.SelectedItem != null)
     {
         if (rentalCarViewModel.SelectedCar.Available)
         {
             if (user.Balance >= numeric_numOfDays.Value * rentalCarViewModel.SelectedCar.PricePerDay)
             {
                 rentalCarViewModel.SelectedCar.AvailableFrom = DateTime.Now;
                 rentalCarViewModel.SelectedCar.AvailableFrom = rentalCarViewModel.SelectedCar.AvailableFrom.AddDays((int)numeric_numOfDays.Value);
                 rentalCarViewModel.SelectedCar.Available     = false;
                 rentalCarViewModel.SelectedCar.RentedID      = user.ID;
                 user.Pay(rentalCarViewModel.SelectedCar.PricePerDay * numeric_numOfDays.Value);
                 rentalCarViewModel.SerializeCars();
                 user.Serialize();
                 Find_Click(sender, e);
                 ShowMsg("Rental success", "The car is successfully rented");
             }
             else
             {
                 ShowMsg("Rental error", "There are not enough funds on your balance for this rent");
             }
         }
         else
         {
             ShowMsg("Rental error", "The selected car is not available");
             RentalCar.UpdateCarsStatus(this.rentalCarViewModel.Cars.ToList());
         }
     }
     else
     {
         ShowMsg("Rental error", "You have not chosen the car you want to rent");
     }
 }
コード例 #3
0
 public AdminCarsMenu(RentalCarViewModel rentalCarViewModel)
 {
     InitializeComponent();
     this.rentalCarViewModel = rentalCarViewModel;
     this.rentalCarViewModel.DeserializeCars();
     this.rentalCarViewModel.UnfilteredCars();
     RentalCar.UpdateCarsStatus(this.rentalCarViewModel.Cars.ToList());
 }
コード例 #4
0
        public void DeleteCar(RentalCar car)
        {
            if (car == null)
            {
                throw new ArgumentNullException(nameof(car));
            }

            _context.RentalCars.Remove(car);
        }
コード例 #5
0
        public async Task AddCar(RentalCar car)
        {
            if (car == null)
            {
                throw new ArgumentNullException(nameof(car));
            }

            await _context.RentalCars.AddAsync(car);
        }
コード例 #6
0
 public RentCars(RentalCarViewModel rentalCarViewModel, User user)
 {
     InitializeComponent();
     this.rentalCarViewModel = rentalCarViewModel;
     this.rentalCarViewModel.DeserializeCars();
     this.rentalCarViewModel.UnfilteredCars();
     this.user = user;
     RentalCar.UpdateCarsStatus(this.rentalCarViewModel.Cars.ToList());
 }
コード例 #7
0
        public IActionResult Update(RentalCar rentalCar)
        {
            var result = _rentalCarService.Update(rentalCar);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result.Massage));
        }
 public IActionResult Post(RentalCar rentcar)
 {
     _log4net.Info("Post Api Initiated");
     using (var scope = new TransactionScope())
     {
         _carrent.Add(rentcar);
         scope.Complete();
         return(Ok());
     }
 }
コード例 #9
0
        //Funkcja przypisuję wypożyczenie samochodu do użytkownika
        public ActionResult Rent(int?id)
        {
            RentalCar rentalCar = db.RentalCars.Find(id);

            db.Current.Add(new Current {
                ID = rentalCar.ID, Car = rentalCar.CarName, CarRegistration = rentalCar.CarRegistration, RentalDate = _reservation.Date1, ReturnDate = _reservation.Date2, userid = User.Identity.Name
            });
            db.RentalCars.Remove(rentalCar);
            db.SaveChanges();
            return(new RedirectResult(@"~\Current\Index"));
        }
コード例 #10
0
        public static void SeedData(RentalCarsContext context)
        {
            Console.WriteLine("Applying migrations");
            context.Database.Migrate();

            if (!context.Rentals.Any())
            {
                Console.WriteLine("Adding data - retnals - seeeding");

                var rental = new Rental
                {
                    Name          = "OX-RENTAL",
                    RentalAddress = new Address {
                        City = "WARSAW", Street = "MAZOWIECKA", Number = 1
                    }
                };

                context.Rentals.Add(rental);
                context.SaveChanges();
            }

            if (!context.RentalCars.Any())
            {
                Console.WriteLine("Adding data - cars - seeeding");

                var retnalId = context.Rentals.FirstOrDefault();
                var car1     = new RentalCar
                {
                    Brand          = "BMW",
                    ModelName      = "M3",
                    EngineCapacity = 2.5f,
                    Mileage        = 167000,
                    ProductionYear = 2004,
                    VinNumber      = "EAS42RWE32123",
                    BaseRentCost   = 256,
                    RentalId       = retnalId?.Id ?? 0
                };

                var car2 = new RentalCar
                {
                    Brand          = "FORD",
                    ModelName      = "FOCUS",
                    EngineCapacity = 1.9f,
                    Mileage        = 127000,
                    ProductionYear = 2006,
                    VinNumber      = "EWS42RWE321T6",
                    BaseRentCost   = 152,
                    RentalId       = retnalId?.Id ?? 0
                };

                context.RentalCars.AddRange(car1, car2);
                context.SaveChanges();
            }
        }
コード例 #11
0
 public EditCar(RentalCarViewModel rentalCarViewModel, Grid parent, AdminCarsMenu carmenu)
 {
     InitializeComponent();
     this.parent               = parent;
     this.carmenu              = carmenu;
     this.rentalCarViewModel   = rentalCarViewModel;
     this.rentalCar            = this.rentalCarViewModel.CarToEditOrCreate;
     txtbox_carBrand.Text      = rentalCar.Brand;
     txtbox_carModel.Text      = rentalCar.Model;
     txtbox_licensePlate.Text  = rentalCar.LicensePlate;
     comboBox_carType.Text     = rentalCar.Type;
     numeric_pricePerDay.Value = rentalCar.PricePerDay;
 }
コード例 #12
0
        private void Find_Click(object sender, RoutedEventArgs e)
        {
            RentalCar.UpdateCarsStatus(this.rentalCarViewModel.Cars.ToList());
            this.rentalCarViewModel.LoadUserRentedCars(this.user.ID);
            rentalCarViewModel.ClearFiltredUserCars();
            if (isAllFiltersUnchecked())
            {
                rentalCarViewModel.UnfilteredUserCars();
            }
            else
            {
                foreach (var car in rentalCarViewModel.UserRentedCars)
                {
                    if (chb_sportCoupe.IsChecked == true && car.Type == chb_sportCoupe.Content.ToString() && !rentalCarViewModel.FiltredUserCars.Contains(car))
                    {
                        rentalCarViewModel.AddUserCarToFiltred(car);
                    }

                    if (chb_suv.IsChecked == true && car.Type == chb_suv.Content.ToString() && !rentalCarViewModel.FiltredUserCars.Contains(car))
                    {
                        rentalCarViewModel.AddUserCarToFiltred(car);
                    }

                    if (chb_stationWagon.IsChecked == true && car.Type == chb_stationWagon.Content.ToString() && !rentalCarViewModel.FiltredUserCars.Contains(car))
                    {
                        rentalCarViewModel.AddUserCarToFiltred(car);
                    }

                    if (chb_minivan.IsChecked == true && car.Type == chb_minivan.Content.ToString() && !rentalCarViewModel.FiltredCars.Contains(car))
                    {
                        rentalCarViewModel.AddUserCarToFiltred(car);
                    }

                    if (chb_electricCar.IsChecked == true && car.Type == chb_electricCar.Content.ToString() && !rentalCarViewModel.FiltredUserCars.Contains(car))
                    {
                        rentalCarViewModel.AddUserCarToFiltred(car);
                    }

                    if (chb_cabriolet.IsChecked == true && car.Type == chb_cabriolet.Content.ToString() && !rentalCarViewModel.FiltredUserCars.Contains(car))
                    {
                        rentalCarViewModel.AddUserCarToFiltred(car);
                    }

                    if (chb_sedan.IsChecked == true && car.Type == chb_sedan.Content.ToString() && !rentalCarViewModel.FiltredUserCars.Contains(car))
                    {
                        rentalCarViewModel.AddUserCarToFiltred(car);
                    }
                }
            }
        }
コード例 #13
0
        public IResult Add(RentalCar rentalCar)
        {
            var result = _rentalCarDal.GetAll(c => (c.CarId == rentalCar.CarId) && !(c.RentDate == null && c.ReturnDate == null) && (c.ReturnDate == null)).ToList();

            if (result.Count == 0)
            {
                _rentalCarDal.Add(rentalCar);
                return(new SuccessResult(Messages.RentalAdded));
            }
            else
            {
                return(new ErrorResult(Messages.NotRentalAdded));
            }
        }
コード例 #14
0
        private async Task <RentalCar> CreateAndSaveCar(int milageKm, CarCategory carCategory)
        {
            var rentalCar = new RentalCar()
            {
                CarCategoryId = carCategory.IdCarCategory,
                MilageKm      = milageKm
            };

            await this.unitOfWork.RentalCar.Add(rentalCar);

            await this.unitOfWork.CompleteAsync();

            return(rentalCar);
        }
コード例 #15
0
        public List <RentalCar> GetAllRentalCars()
        {
            using (var con = GetConnection())
            {
                var cmd = con.CreateCommand();

                cmd.CommandText = "RentalCars_SelectAll";
                cmd.CommandType = CommandType.StoredProcedure;

                using (var reader = cmd.ExecuteReader())
                {
                    List <RentalCar> rentalCars = new List <RentalCar>();

                    while (reader.Read())
                    {
                        RentalCar car = new RentalCar();

                        car.Id          = (int)reader["Id"];
                        car.Make        = (string)reader["Make"];
                        car.Model       = (string)reader["Model"];
                        car.Year        = (int)reader["Year"];
                        car.CarType     = (int)reader["CarType"];
                        car.DateCreated = (DateTime)reader["DateCreated"];

                        object vinValue = reader["VIN"];
                        if (vinValue != DBNull.Value)
                        {
                            car.VIN = (string)vinValue;
                        }

                        object colorValue = reader["Color"];
                        if (colorValue != DBNull.Value)
                        {
                            car.Color = (string)colorValue;
                        }

                        object dateModifiedValue = reader["DateModified"];
                        if (dateModifiedValue != DBNull.Value)
                        {
                            car.DateModified = (DateTime)dateModifiedValue;
                        }

                        rentalCars.Add(car);
                    }

                    return(rentalCars);
                }
            }
        }
コード例 #16
0
        public RentalCar GetRentalCarById(int id)
        {
            using (var con = GetConnection())
            {
                var cmd = con.CreateCommand();

                cmd.CommandText = "RentalCars_SelectById";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", id);

                using (var reader = cmd.ExecuteReader())
                {
                    if (!reader.Read())
                    {
                        return(null);
                    }

                    RentalCar car = new RentalCar();

                    car.Id          = (int)reader["Id"];
                    car.Make        = (string)reader["Make"];
                    car.Model       = (string)reader["Model"];
                    car.Year        = (int)reader["Year"];
                    car.CarType     = (int)reader["CarType"];
                    car.DateCreated = (DateTime)reader["DateCreated"];

                    object vinValue = reader["VIN"];
                    if (vinValue != DBNull.Value)
                    {
                        car.VIN = (string)vinValue;
                    }

                    object colorValue = reader["Color"];
                    if (colorValue != DBNull.Value)
                    {
                        car.Color = (string)colorValue;
                    }

                    object dateModifiedValue = reader["DateModified"];
                    if (dateModifiedValue != DBNull.Value)
                    {
                        car.DateModified = (DateTime)dateModifiedValue;
                    }

                    return(car);
                }
            }
        }
コード例 #17
0
        public EditCarForm(RentalCar car_to_edit, List <RentalCar> cars, Guna.UI.WinForms.GunaDataGridView DataGrid_cars, Panel cars_menu)
        {
            InitializeComponent();
            rentalCar                = car_to_edit;
            txtbox_carBrand.Text     = rentalCar.Brand;
            txtbox_model.Text        = rentalCar.Model;
            txtbox_licensePlate.Text = rentalCar.LicensePlate;
            int index = comboBox_carType.FindString(rentalCar.Type);

            comboBox_carType.SelectedIndex = index;
            numeric_pricePerDay.Value      = rentalCar.PricePerDay;
            this.cars          = cars;
            this.DataGrid_cars = DataGrid_cars;
            this.pnCarsMenu    = cars_menu;
        }
コード例 #18
0
ファイル: CarService.cs プロジェクト: MikelGalaxy/Car_Rental
        private RentalCar CapitalizeCarValues(RentalCar car)
        {
            if (car == null)
            {
                var ex = new ArgumentNullException(nameof(car));
                _logger.LoggMessage("Can't capitalize null car", ex);
                throw ex;
            }

            car.Brand     = car.Brand?.ToUpper().Trim();
            car.ModelName = car.ModelName?.ToUpper().Trim();
            car.VinNumber = car.VinNumber?.ToUpper().Trim();

            return(car);
        }
コード例 #19
0
        private void bt_edit_Click(object sender, EventArgs e)
        {
            if (DataGrid_cars.Rows.Count > 0)
            {
                RentalCar rentalCar = new RentalCar()
                {
                    Available     = (bool)(DataGrid_cars.SelectedRows[0]).Cells[0].Value,
                    AvailableFrom = (DateTime)(DataGrid_cars.SelectedRows[0]).Cells[1].Value,
                    PricePerDay   = (int)(DataGrid_cars.SelectedRows[0]).Cells[2].Value,
                    Brand         = (string)(DataGrid_cars.SelectedRows[0]).Cells[3].Value,
                    Model         = (string)(DataGrid_cars.SelectedRows[0]).Cells[4].Value,
                    LicensePlate  = (string)(DataGrid_cars.SelectedRows[0]).Cells[5].Value,
                    Type          = (string)(DataGrid_cars.SelectedRows[0]).Cells[6].Value,
                };
                if (rentalCar.Available)
                {
                    int index = 0;
                    for (int i = 0; i < cars.Count; i++)
                    {
                        if (cars[i].LicensePlate == rentalCar.LicensePlate)
                        {
                            index = i;
                            break;
                        }
                    }
                    RentalCar editing_car = cars[index];

                    EditCarForm editCarForm = new EditCarForm(editing_car, cars, DataGrid_cars, pnCarsMenu);
                    editCarForm.TopLevel = false;
                    editCarForm.Dock     = DockStyle.Fill;
                    pnChildForm.Controls.Add(editCarForm);
                    editCarForm.BringToFront();
                    pnChildForm.BringToFront();

                    editCarForm.Show();
                }
                else
                {
                    MsgBox msgBox = new MsgBox("Editing error", "The selected car is not available");
                    msgBox.ShowDialog();
                }
            }
            else
            {
                MsgBox msgBox = new MsgBox("Editing error", "You have not chosen the car you want to rent");
                msgBox.ShowDialog();
            }
        }
コード例 #20
0
 private void bt_remove_Click(object sender, EventArgs e)
 {
     if (DataGrid_cars.Rows.Count > 0)
     {
         RentalCar rentalCar = new RentalCar()
         {
             Available     = (bool)(DataGrid_cars.SelectedRows[0]).Cells[0].Value,
             AvailableFrom = (DateTime)(DataGrid_cars.SelectedRows[0]).Cells[1].Value,
             PricePerDay   = (int)(DataGrid_cars.SelectedRows[0]).Cells[2].Value,
             Brand         = (string)(DataGrid_cars.SelectedRows[0]).Cells[3].Value,
             Model         = (string)(DataGrid_cars.SelectedRows[0]).Cells[4].Value,
             LicensePlate  = (string)(DataGrid_cars.SelectedRows[0]).Cells[5].Value,
             Type          = (string)(DataGrid_cars.SelectedRows[0]).Cells[6].Value,
         };
         if (rentalCar.Available)
         {
             for (int i = 0; i < cars.Count; i++)
             {
                 if (cars[i].LicensePlate == rentalCar.LicensePlate)
                 {
                     cars.RemoveAt(i);
                     break;
                 }
             }
             RentalSerivce.SerializeCars(cars);
             DataGrid_cars.Rows.Clear();
             foreach (var car in cars)
             {
                 AddCarToDataGrid(car);
             }
             MsgBox msgBox = new MsgBox("Removing car", "The car is successfully removed");
             msgBox.ShowDialog();
         }
         else
         {
             MsgBox msgBox = new MsgBox("Removing error", "The selected car is not available");
             msgBox.ShowDialog();
         }
     }
     else
     {
         MsgBox msgBox = new MsgBox("Removing error", "You have not chosen the car you want to remove");
         msgBox.ShowDialog();
     }
 }
コード例 #21
0
        public async Task <RentalCar> addRentalCar(string carPlateNumber, string carType, double mileage)
        {
            var carTypeObj = await getCarType(carType);


            RentalCar rentalCar = new RentalCar {
                carNumber = carPlateNumber, rentalCarType = carTypeObj, currentMileage = mileage
            };

            if (carTypeObj != null)
            {
                context.rentalCars.Add(rentalCar);
                context.carTypes.Attach(carTypeObj);
                await context.SaveChangesAsync();

                return(rentalCar);
            }

            return(null);
        }
コード例 #22
0
 public void DeserializeCars()
 {
     cars = RentalCar.DeserializeCars();
 }
コード例 #23
0
 public IResult Update(RentalCar rentalCar)
 {
     _rentalCarDal.Update(rentalCar);
     return(new SuccessResult(Messages.RentalUpdated));
 }
コード例 #24
0
 public IResult Delete(RentalCar rentalCar)
 {
     _rentalCarDal.Delete(rentalCar);
     return(new SuccessResult(Messages.RentalDeleted));
 }
コード例 #25
0
 public void SerializeCars()
 {
     RentalCar.SerializeCars(cars.ToList());
 }
コード例 #26
0
 public AddCar(RentalCarViewModel rentalCarViewModel)
 {
     InitializeComponent();
     this.rentalCarViewModel = rentalCarViewModel;
     this.rentalCar          = this.rentalCarViewModel.CarToEditOrCreate;
 }
コード例 #27
0
 public void UpdateCarsStatus()
 {
     RentalCar.UpdateCarsStatus(cars.ToList());
 }
コード例 #28
0
 private void AddCarToDataGrid(RentalCar car)
 {
     DataGrid_cars.Rows.Add(car.Available, car.AvailableFrom, car.PricePerDay, car.Brand, car.Model, car.LicensePlate, car.Type);
 }
コード例 #29
0
 public void AddUserCarToFiltred(RentalCar car)
 {
     filtredUserCars.Add(car);
 }
コード例 #30
0
 public void RemoveCar(RentalCar car)
 {
     cars.Remove(car);
 }