Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Address")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Ejemplo n.º 2
0
        public void IntializeReturn()
        {
            using (var db = new CarRentalDBContext())
            {
                var resevations = db.Resevations.Where(x => x.Car.IsRented == true).ToList();
                Console.WriteLine("Select Booking number");
                var loop = 1;
                foreach (var item in resevations)
                {
                    Console.WriteLine($"{loop} - {item.BookingNumber}");
                    loop++;
                }
                var listindex = int.Parse(Console.ReadLine());
                var userresv  = resevations.ElementAt(listindex - 1);
                var car       = db.Cars.Find(userresv.CarId);
                var dayspent  = (DateTime.Now - userresv.BookingDate).Days;
                //var tempdate = new DateTime(2021,03,13);
                //var dayspent = (DateTime.Now - tempdate).Days;
                Console.WriteLine("What is the current milage on the car? Enter numbers");
                var currentmileage = int.Parse(Console.ReadLine());

                var mileage        = currentmileage - car.Mileage;
                var rentalcategory = userresv.RentalCategory;
                var cost           = CalculateCost(dayspent, mileage, rentalcategory);
                Console.WriteLine($"Total cost of the resevation is {cost}");
                car.Mileage  = currentmileage;
                car.IsRented = false;
                db.Update(car);
                db.SaveChanges();
                Console.ReadLine();
            }
        }
Ejemplo n.º 3
0
        public void RentCar(Car car, RentalCategory category, string socialsecuritynumber, CarRentalDBContext db)
        {
            var resevation = new Resevation();
            var customer   = new Customer();

            resevation.CarId               = car.Id;
            resevation.Car                 = car;
            resevation.RentalCategory      = category;
            resevation.BookingNumber       = random.Next(1, 999999);
            resevation.CustomerId          = customer.Id;
            resevation.BookingDate         = DateTime.Now;
            customer.SocialSercurityNumber = socialsecuritynumber;
            car.IsRented = true;
            db.Update(car);
            db.Add(customer);
            db.Add(resevation);
            db.SaveChanges();
            Console.WriteLine($"You have rented the car with booking number {resevation.BookingNumber}");
        }