Ejemplo n.º 1
0
        protected override Account GetEntity(CarRentalContext entityContext, int id)
        {
            var query = (from e in entityContext.AccountSet where e.AccountId == id select e);

            var results = query.FirstOrDefault();

            return(results);
        }
Ejemplo n.º 2
0
        protected override Rental GetEntity(CarRentalContext entityContext, int id)
        {
            var query = (from rental in entityContext.RentalSet
                         where rental.RentalId == id
                         select rental);

            return(query.FirstOrDefault());
        }
Ejemplo n.º 3
0
        protected override Reservation UpdateEntity(CarRentalContext entityContext, Reservation entity)
        {
            var query = (from e in entityContext.ReservationSet
                         where e.ReservationId == entity.ReservationId
                         select e);

            return(query.FirstOrDefault());
        }
Ejemplo n.º 4
0
 private void CreateDbIfItDoesntExit()
 {
     CarRentalContext.ConnectionString = TestConnectionString;
     using (var db = new CarRentalContext())
     {
         db.Database.EnsureCreated();
     }
 }
Ejemplo n.º 5
0
 public User Get(int id)
 {
     using (var context = new CarRentalContext())
     {
         var user = context.User.Single(u => u.Id == id);
         return(Convert.FromDataModel(user));
     }
 }
        protected override Car GetEntity(CarRentalContext entityContext, int id)
        {
            var query = (from e in entityContext.CarSet
                         where e.CarId == id
                         select e);

            return(query.FirstOrDefault());
        }
Ejemplo n.º 7
0
        protected override Car UpdateEntity(CarRentalContext entityContext, Car entity)
        {
            var query = from c in entityContext.CarSet
                        where c.CarId == entity.CarId
                        select c;

            return(query.FirstOrDefault());
        }
Ejemplo n.º 8
0
 public Account GetByLogin(string login)
 {
     using (CarRentalContext entityContext = new CarRentalContext())
     {
         return(entityContext.AccountSet
                .FirstOrDefault(e => e.LoginEmail == login));
     }
 }
Ejemplo n.º 9
0
        protected override Reservation GetEntity(CarRentalContext entityContext, int id)
        {
            var query = (from e in entityContext.ReservationSet
                         where e.ReservationId == id
                         select e);

            return(query.FirstOrDefault());
        }
Ejemplo n.º 10
0
 public IEnumerable <Rental> GetRentalHistoryByCar(int id)
 {
     using (CarRentalContext entityContext = new CarRentalContext())
     {
         return(entityContext.RentalSet
                .Where(e => e.CarId == id)
                .Select(e => e).ToFullyLoaded());
     }
 }
Ejemplo n.º 11
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();
     }
 }
Ejemplo n.º 12
0
 public void Add(User user)
 {
     using (var context = new CarRentalContext())
     {
         var newUser = Convert.ToDataModel(user);
         context.User.Add(newUser);
         context.SaveChanges();
     }
 }
        public IEnumerable <Reservation> GetReservationByPickupDate(DateTime pickupDate)
        {
            using (CarRentalContext entityContext = new CarRentalContext())
            {
                var query = from r in entityContext.ReservationSet where r.RentalDate < pickupDate select r;

                return(query.ToFullyLoaded());
            }
        }
        public IEnumerable <Rental> GetRentalHistoryByAccount(int accountId)
        {
            using (CarRentalContext entityContext = new CarRentalContext())
            {
                var query = from e in entityContext.RentalSet where e.AccountId == accountId select e;

                return(query.ToFullyLoaded());
            }
        }
        public IEnumerable <Rental> GetCurrentlyRentedCars()
        {
            using (CarRentalContext entityContext = new CarRentalContext())
            {
                var query = from e in entityContext.RentalSet where e.DateReturned == null select e;

                return(query.ToFullyLoaded());
            }
        }
        public Rental GetCurrentRentalByCar(int carId)
        {
            using (CarRentalContext entityContext = new CarRentalContext())
            {
                var query = from e in entityContext.RentalSet where e.CarId == carId && e.DateReturned == null select e;

                return(query.FirstOrDefault());
            }
        }
Ejemplo n.º 17
0
 public IEnumerable <Rental> GetCurrentlyRentedCars()
 {
     using (CarRentalContext entityContext = new CarRentalContext())
     {
         return(entityContext.RentalSet
                .Where(e => e.DateReturned == null)
                .Select(e => e).ToFullyLoaded());
     }
 }
Ejemplo n.º 18
0
 public Rental GetCurrentRentalByCar(int id)
 {
     using (CarRentalContext entityContext = new CarRentalContext())
     {
         return(entityContext.RentalSet
                .Where(e => e.CarId == id && e.DateReturned == null)
                .Select(e => e).FirstOrDefault());
     }
 }
Ejemplo n.º 19
0
 public Account GetByLogin(string login)
 {
     using (CarRentalContext dbContext = new CarRentalContext())
     {
         return((from e in dbContext.AccountSet
                 where e.LoginEmail == login
                 select e).SingleOrDefault());
     }
 }
Ejemplo n.º 20
0
 public void Add(Maintenance maint)
 {
     using (var context = new CarRentalContext())
     {
         var newMaint = Convert.ToDataModel(maint);
         context.Maintenance.Add(newMaint);
         context.SaveChanges();
     }
 }
Ejemplo n.º 21
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();
     }
 }
Ejemplo n.º 22
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();
     }
 }
Ejemplo n.º 23
0
 public Account GetByLogin(string login)
 {
     using (CarRentalContext entityContext = new CarRentalContext())
     {
         return((from a in entityContext.AccountSet
                 where a.LoginEmail == login
                 select a).FirstOrDefault());
     }
 }
Ejemplo n.º 24
0
 public void Delete(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var deletedEntity = context.Entry(car);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Ejemplo n.º 25
0
 public void Add(Vehicle vehicle)
 {
     using (var context = new CarRentalContext())
     {
         var newVehicle = Convert.ToDataModel(vehicle);
         context.Vehicle.Add(newVehicle);
         context.SaveChanges();
     }
 }
Ejemplo n.º 26
0
 public void Update(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var updatedEntity = context.Entry(car);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 27
0
 public void Add(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var addedEntity = context.Entry(car);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Ejemplo n.º 28
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();
            }
        }
Ejemplo n.º 29
0
        public void AddCustomer(CustomerDetailsDto customerDetailsDto)
        {
            var customer = Mapper.Map <CustomerDetails>(customerDetailsDto);

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

            using (var context = new CarRentalContext())
            {
                context.Rentals.Add(rental);
                context.SaveChanges();
            }
        }
Ejemplo n.º 31
0
 public static ValidationResult ValidateBrandName(string brandName)
 {
     if (String.IsNullOrWhiteSpace(brandName))
         return new ValidationResult("Brand Name Cannot be Empty");
     using (var _db = new CarRentalContext())
     {
         if (_db.CarBrands.SingleOrDefault(x => x.BrandName == brandName) == null)
             return ValidationResult.Success;
         return new ValidationResult("Brand " + brandName + " Already Exists");
     }
 }