Exemplo n.º 1
0
        internal void BookCar(CreateBookingVM createBooking)
        {
            Customer customer = new Customer();

            if (carRentalContext.Customer.Any(c => c.CustomerSsn == createBooking.SSN))
            {
                Customer existingCustomer = carRentalContext.Customer.Single(c => c.CustomerSsn == createBooking.SSN);
                customer = existingCustomer;
            }
            else
            {
                Customer newCustomer = new Customer
                {
                    CustomerSsn = createBooking.SSN
                };
                carRentalContext.Customer.Add(newCustomer);
                carRentalContext.SaveChanges();
                customer = newCustomer;
            }

            Booking booking = new Booking
            {
                RentedCar  = carRentalContext.Car.Single(c => c.CarRegistrationNumber == createBooking.RegistrationNumber).Id,
                CustomerId = customer.Id,
            };

            carRentalContext.Car.SingleOrDefault(c => c.Id == booking.RentedCar).RentalStart = createBooking.StartOfRental;
            carRentalContext.Booking.Add(booking);
            carRentalContext.SaveChanges();
        }
Exemplo n.º 2
0
 public IActionResult Post([FromBody] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Orders.Add(order);
         db.SaveChanges();
         return(Ok(order));
     }
     return(BadRequest(ModelState));
 }
Exemplo n.º 3
0
        protected CarRental ReturnRental(string bookingNumber, decimal milageAtReturn)
        {
            using (var db = new CarRentalContext())
            {
                CarRental rental = FirstOrDefaultCarRental(bookingNumber, db);

                if (rental == null)
                {
                    throw new Exception("no such rental: " + bookingNumber);
                }
                if (rental.CarMilageAtRentInKm > milageAtReturn)
                {
                    throw new Exception("Milage is lower at return than at rent time. Customer may be cheating");
                }

                rental.CarMilageAtReturnInKm = milageAtReturn;

                rental.Returned = _dateTimeProvider.GetUtcNow();
                if (rental.Returned < rental.Rented)
                {
                    throw new Exception("Returned before it was rented");
                }

                db.SaveChanges();

                return(rental);
            }
        }
Exemplo n.º 4
0
        static void Update()
        {
            using (var db = new CarRentalContext())
            {
                Console.WriteLine("Wyszukaj Rejstrację do Zmiany Położenia Samochodu");
                string place = Console.ReadLine();
                Car    car   = db.Cars.Where(x => x.RegistrationNumber == place).FirstOrDefault();
                if (car != null)
                {
                    Console.WriteLine("Wprowadz Xpostion");
                    double x = Convert.ToDouble(Console.ReadLine());
                    car.XPosition = x;

                    Console.WriteLine("Wprowadz Ypostion");
                    double y = Convert.ToDouble(Console.ReadLine());
                    car.YPosition = x;

                    db.SaveChanges();
                }
                else
                {
                    Console.WriteLine("Nie odnaleziono samochodu o tym numerze rejstracyjnym");
                }
            }
            return;
        }
Exemplo n.º 5
0
        public async override Task FillTestDataAsync()
        {
            List <Company> Companies = new List <Company>();

            Companies.Add(new Company()
            {
                Name = "Vueling Airlines", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            });
            Companies.Add(new Company()
            {
                Name = "Blizzard", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            });
            Companies.Add(new Company()
            {
                Name = "Riot Games", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            });
            Companies.Add(new Company()
            {
                Name = "King", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            });
            Companies.Add(new Company()
            {
                Name = "ToySRUs", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            });
            Companies.Add(new Company()
            {
                Name = "Decathlon", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            });

            DeleteAll();

            Companies.ForEach(async x => await InsertAsync(x));

            _context.SaveChanges();
        }
Exemplo n.º 6
0
 public void Delete(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var deletedEntity = context.Entry(car);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public void Update(User user)
 {
     using (var context = new CarRentalContext())
     {
         var updateUser = context.User.Single(u => u.Id == user.Id);
         updateUser = Convert.ToDataModel(user);
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public void Add(User user)
 {
     using (var context = new CarRentalContext())
     {
         var newUser = Convert.ToDataModel(user);
         context.User.Add(newUser);
         context.SaveChanges();
     }
 }
Exemplo n.º 9
0
 public void Add(Maintenance maint)
 {
     using (var context = new CarRentalContext())
     {
         var newMaint = Convert.ToDataModel(maint);
         context.Maintenance.Add(newMaint);
         context.SaveChanges();
     }
 }
Exemplo n.º 10
0
 public void Update(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var updatedEntity = context.Entry(car);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 11
0
 public void Update(Maintenance maint)
 {
     using (var context = new CarRentalContext())
     {
         var updateMaint = context.Maintenance.Single(m => m.Id == maint.Id);
         updateMaint = Convert.ToDataModel(maint);
         context.SaveChanges();
     }
 }
Exemplo n.º 12
0
 public void Add(Vehicle vehicle)
 {
     using (var context = new CarRentalContext())
     {
         var newVehicle = Convert.ToDataModel(vehicle);
         context.Vehicle.Add(newVehicle);
         context.SaveChanges();
     }
 }
Exemplo n.º 13
0
 public void Add(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var addedEntity = context.Entry(car);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Exemplo n.º 14
0
 public void Update(Vehicle vehicle)
 {
     using (var context = new CarRentalContext())
     {
         var updateVehicle = context.Vehicle.Single(v => v.Id == vehicle.Id);
         updateVehicle = Convert.ToDataModel(vehicle);
         context.SaveChanges();
     }
 }
Exemplo n.º 15
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new CarRentalContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <CarRentalContext> >()))
            {
                // Look for any cars.
                if (context.Car.Any())
                {
                    return;   // DB has been seeded
                }

                context.Car.AddRange(
                    new Car
                {
                    Model     = "Sedan",
                    ImageSrc  = "https://c4.wallpaperflare.com/wallpaper/413/595/829/2014-audi-a8-l-w12-exclusive-concept-blue-audi-sedan-wallpaper-preview.jpg",
                    Doors     = 4,
                    seats     = 5,
                    automatic = false,
                    Price     = 99.99m
                },

                    new Car
                {
                    Model     = "HatchBack",
                    ImageSrc  = "https://c4.wallpaperflare.com/wallpaper/832/475/785/audi-rs4-side-view-black-wallpaper-preview.jpg",
                    Doors     = 3,
                    seats     = 4,
                    automatic = true,
                    Price     = 64.95m
                },

                    new Car
                {
                    Model     = "SUV",
                    ImageSrc  = "https://pxhere.com/en/photo/1447497",
                    Doors     = 5,
                    seats     = 7,
                    automatic = false,
                    Price     = 120m
                },

                    new Car
                {
                    Model     = "Van",
                    ImageSrc  = "https://cdn.pixabay.com/photo/2017/01/23/10/54/van-2002079_960_720.png",
                    Doors     = 4,
                    seats     = 2,
                    automatic = false,
                    Price     = 120m
                }
                    );
                context.SaveChanges();
            }
        }
Exemplo n.º 16
0
        public void AddCustomer(CustomerDetailsDto customerDetailsDto)
        {
            var customer = Mapper.Map <CustomerDetails>(customerDetailsDto);

            using (var context = new CarRentalContext())
            {
                context.Customers.Add(customer);
                context.SaveChanges();
            }
        }
Exemplo n.º 17
0
        public void AddRental(RentalDto rentalDto)
        {
            var rental = Mapper.Map <Rental>(rentalDto);

            using (var context = new CarRentalContext())
            {
                context.Rentals.Add(rental);
                context.SaveChanges();
            }
        }
Exemplo n.º 18
0
        public void UpdateCustomer(CustomerDetailsDto customerDetailsDto)
        {
            var customer = Mapper.Map <CustomerDetails>(customerDetailsDto);

            using (var context = new CarRentalContext())
            {
                context.Customers.Attach(customer);
                context.Entry(customer).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Exemplo n.º 19
0
        public User Remove(int id)
        {
            using (var context = new CarRentalContext())
            {
                var user = context.User.Single(u => u.Id == id);
                user.UserType = (int)Enums.UserTypes.Noone;
                context.SaveChanges();

                return(Convert.FromDataModel(user));
            }
        }
Exemplo n.º 20
0
        protected string CreateAndSaveACarRental(string carCategory, string customerSocialSecurityNumber, decimal currentMilage)
        {
            using (var db = new CarRentalContext())
            {
                var rental = new CarRental()
                {
                    CarCategory = carCategory,
                    CustomerSocialSecurityNumber = customerSocialSecurityNumber,
                    CarMilageAtRentInKm          = currentMilage,
                    Rented = _dateTimeProvider.GetUtcNow()
                };
                db.Add(rental);
                db.SaveChanges();

                rental.BookingNumber = "BN" + rental.Id; //No real req. here, just it made up for now
                db.SaveChanges();

                return(rental.BookingNumber);
            }
        }
Exemplo n.º 21
0
        public Vehicle Remove(int id)
        {
            using (var context = new CarRentalContext())
            {
                var vehicle = context.Vehicle.Single(v => v.Id == id);
                vehicle.Removed = true;
                context.SaveChanges();

                return(Convert.FromDataModel(vehicle));
            }
        }
Exemplo n.º 22
0
        public Maintenance Remove(int id)
        {
            using (var context = new CarRentalContext())
            {
                var maint = context.Maintenance.Single(m => m.Id == id);
                maint.Completed = true;
                context.SaveChanges();

                return(Convert.FromDataModel(maint));
            }
        }
Exemplo n.º 23
0
        public ActionResult Rent()
        {
            string status = String.Empty;

            try {
                Rental r = new Rental();
                r.PickupDate = DateTime.ParseExact(Request.Form["pickupDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                r.ReturnDate = DateTime.ParseExact(Request.Form["returnDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                r.CarID      = int.Parse(Request.Form["CarID"]);
                r.DriverAge  = 21;
                r.UserID     = int.Parse(Request.Form["UserID"]);
                dbContext.Rental.Add(r);
                dbContext.SaveChanges();
                status = "success";
            }
            catch (Exception ex)
            {
                status = "failure";
            }
            return(Content(status, "application/json"));
        }
 public ActionResult AddManufacture(Manufacture m)
 {
     try
     {
         Manufacture temp = dbContext.Manufacture.Where(x => x.Name.Contains(m.Name)).FirstOrDefault();
         if (temp == null)
         {
             dbContext.Manufacture.Add(m);
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         RedirectToAction("Index", "Home");
     }
     return(View());
 }
Exemplo n.º 25
0
 static void Delete()
 {
     using (var db = new CarRentalContext())
     {
         Console.WriteLine("Wyszukaj Rejstrację do Zmiany Położenia Samochodu");
         string place = Console.ReadLine();
         Car    car   = db.Cars.Where(x => x.RegistrationNumber == place).FirstOrDefault();
         if (car != null)
         {
             db.Cars.Remove(car);
             db.SaveChanges();
         }
         else
         {
             Console.WriteLine("Nie odnaleziono samochodu o tym numerze rejstracyjnym");
         }
     }
     return;
 }
Exemplo n.º 26
0
 public async override Task FillTestDataAsync()
 {
     _fleet.Add(new Car()
     {
         Registration = "ESP-1234", Brand = Brand.Tesla, Model = "model 3", Type = CarType.Convertible
     });
     _fleet.Add(new Car()
     {
         Registration = "ASD-1234", Brand = Brand.Renault, Model = "Megane Sport", Type = CarType.Convertible
     });
     _fleet.Add(new Car()
     {
         Registration = "EFA-1234", Brand = Brand.Ford, Model = "Kuga", Type = CarType.MiniVan
     });
     _fleet.Add(new Car()
     {
         Registration = "GFE-1234", Brand = Brand.Renault, Model = "Scenic", Type = CarType.MiniVan
     });
     _fleet.Add(new Car()
     {
         Registration = "SDE-1234", Brand = Brand.Renault, Model = "Megane F", Type = CarType.Convertible
     });
     _fleet.Add(new Car()
     {
         Registration = "ASD-1234", Brand = Brand.Tesla, Model = "model S", Type = CarType.SUV
     });
     _fleet.Add(new Car()
     {
         Registration = "FAS-1234", Brand = Brand.Ferrari, Model = "Imprezza", Type = CarType.SUV
     });
     _fleet.Add(new Car()
     {
         Registration = "FEW-1234", Brand = Brand.Audi, Model = "A4 Sport", Type = CarType.Convertible
     });
     _fleet.Add(new Car()
     {
         Registration = "FES-1234", Brand = Brand.Audi, Model = "A4", Type = CarType.SUV
     });
     DeleteAll();
     _fleet.ForEach(async x => await InsertAsync(x));
     _context.SaveChanges();
 }
Exemplo n.º 27
0
 public void AddCustomer(Customer customer)
 {
     inputUserData.Customers.Add(customer);
     inputUserData.SaveChanges();
 }
Exemplo n.º 28
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }
Exemplo n.º 29
0
        //using (var context = new CarRentalContext())
        //{
        //    ManyToManyRelationship(context);
        //}
        private static void ManyToManyRelationship(CarRentalContext context)
        {
            var car1 = new Car
            {
                BrandId    = 1,
                ColorId    = 1,
                CarTypeId  = 1,
                Model      = "Focus",
                Capacity   = 4,
                ModelYear  = "2018",
                DailyPrice = 150,
            };
            var car2 = new Car
            {
                Model      = "Fiesta",
                ModelYear  = "2012",
                ColorId    = 1,
                BrandId    = 1,
                CarTypeId  = 1,
                Capacity   = 4,
                DailyPrice = 100,
            };

            context.AddRange(
                //new Brand
                //{
                //    Name = "Ford"
                //},
                //new Color
                //{
                //    Name = "Siyah"
                //},
                //new CarType
                //{
                //    Name = "Hatchback"
                //},
                //new Department
                //{
                //    Name = "Satış"
                //},
                //new Employee
                //{
                //    IdentityNo = "23456789101",
                //    FirstName = "Ahmet",
                //    LastName = "Çalışkan",
                //    Gender = 'M',
                //    DOB = Convert.ToDateTime("12/24/1987"),
                //    Address = "İzmir",
                //    PhoneNumber = "05554443322",
                //    Email = "*****@*****.**",
                //    PasswordHash = "23456",
                //    DepartmentId = 1,
                //    Position = "Satis Temsilcisi",
                //    JoinDate = DateTime.Now
                //},
                //new IndividualCustomer
                //{
                //    IdentityNo = "12345678910",
                //    FirstName = "Ali",
                //    LastName = "Yaman",
                //    DOB = Convert.ToDateTime("10/10/1990"),
                //    PhoneNumber = "05556667788",
                //    Address = "İzmir",
                //    Email = "*****@*****.**",
                //    PasswordHash = "12345",
                //    JoinDate = DateTime.Now
                //},
                new Rental
            {
                CustomerId = 2,
                EmployeeId = 1,
                RentDate   = DateTime.Now,
                TotalPrice = 100,
                Discount   = 0
            },
                new Rental
            {
                CustomerId = 2,
                EmployeeId = 1,
                RentDate   = DateTime.Now,
            });
            context.SaveChanges();
        }
Exemplo n.º 30
0
 public void AddCar(Car car)
 {
     inputUserData.Cars.Add(car);
     inputUserData.SaveChanges();
 }