public async Task <List <CarEquipment> > GetAllCarEquipment() { var carEquipments = await CarEquipment .ToListAsync(); return(carEquipments); }
public void Execute(CarDto request) { if (Context.Cars.Any(c => c.Name == request.Name)) { throw new EntityAlreadyExistsException("Car"); } var car = new Car(); car.Name = request.Name; car.Price = request.Price; car.Src = request.Src; car.Alt = request.Name; car.EngineId = request.EngineId; car.FuelId = request.FuelId; car.ModelId = request.ModelId; car.TransmissionId = request.TransmissionId; car.CarEquipment = new List <CarEquipment>(); foreach (EquipmentDto dto in request.Equipment) { var equipment = Context.Equipment.Find(dto.Id); if (equipment == null) { throw new EntityNotFoundException("Equipment"); } var CarEquipment = new CarEquipment(); CarEquipment.Equipment = equipment; car.CarEquipment.Add(CarEquipment); } Context.Cars.Add(car); Context.SaveChanges(); }
//Delete public async Task RemoveCarEquipment(int ID) { var carEquipment = new CarEquipment { CarEquipmentID = ID }; Attach(carEquipment); Remove(carEquipment); await SaveChangesAsync(); }
//Update public async Task UpdateCarEquipment(CarEquipment carEquipment) { var result = await CarEquipment.SingleOrDefaultAsync(b => b.CarEquipmentID == carEquipment.CarEquipmentID); if (result == default(CarEquipment)) { return; } Update(result); result = carEquipment; await SaveChangesAsync(); }
private void Test() { AbsEquipment equipment = new CarEquipment(); equipment.TurnOn(); equipment.TurnOff(); equipment = new TVEquipment(); equipment.TurnOn(); equipment.TurnOff(); equipment = new BookAdapter(new Book()); equipment.TurnOn(); equipment.TurnOff(); }
public static CarProfile CarProfileModelToCarProfil(CarProfileModel model) { var newModel = new CarProfile(); var carEquip = new CarEquipment(); newModel.CarEquipment = new Database.Models.CarEquipment(); newModel.Age = model.Age; newModel.Brand = model.Brand; newModel.CarDescription = model.CarDescription; newModel.FuelType = model.FuelType; newModel.Location = model.Location; newModel.Model = model.Model; newModel.Price = model.Price; return(newModel); }
public void Setup() { // model _carEquipment = new CarEquipment(); _carProfile = new CarProfile(); _dayThatIsRented = new DayThatIsRented(); _possibleToRentDay = new PossibleToRentDay(); _message = new Message(); _messagesWithUsers = new MessagesWithUsers(); _user = new User(); //security _carAgeValidator = new CarAgeValidator(); _emailValidator = new EmailValidator(); _licensePlateValidator = new LicensePlateValidator(); _nameValidator = new NameValidator(); _passwordMatchValidator = new PasswordMatchValidator(); _passwordValidator = new PasswordValidator(); _priceValidator = new PriceValidator(); }
public static async Task SeedDatabase() { User lessor = new User() { Email = "car@owner", FirstName = "Owner", LastName = "Owner", Password = "******", Address = "Here", UserType = 2, AuthenticationString = Guid.Empty, }; User renter = new User() { Email = "car@renter", FirstName = "Renter", LastName = "Renter", Password = "******", Address = "There", UserType = 1, AuthenticationString = Guid.Empty, }; List <CarProfile> ourCars = new List <CarProfile>(); List <CarEquipment> ourEquip = new List <CarEquipment>(); for (int i = 1; i < 12; i++) { CarEquipment tempCarEquipment = new CarEquipment(); CarProfile tempCarProfile = new CarProfile(); bool iseven; if (i / 2 == 0) { iseven = true; } else { iseven = false; } tempCarProfile.RegNr = "8FJSM2" + Convert.ToString(i); tempCarProfile.Model = "7"; tempCarProfile.Brand = $"BMW{i}"; tempCarProfile.Age = 5 + i; tempCarProfile.Location = "City" + i; tempCarProfile.Seats = i; tempCarProfile.Price = (i * 1000) + 50000; tempCarProfile.RentalPrice = (i * 100) + 500; tempCarProfile.FuelType = "92"; tempCarProfile.CarDescription = $"#{i}: The very best, like no one ever was"; tempCarProfile.Owner = lessor; tempCarProfile.User = renter; tempCarProfile.OwnerEmail = lessor.Email; tempCarProfile.UserEmail = renter.Email; tempCarProfile.PossibleToRentDays = new List <PossibleToRentDay>(); tempCarProfile.MessagesCarOccursIn = new List <Message>(); tempCarEquipment.Smoking = iseven; tempCarEquipment.Audioplayer = iseven; tempCarEquipment.GPS = iseven; tempCarEquipment.Childseat = iseven; tempCarEquipment.CarProfile = tempCarProfile; tempCarProfile.CarEquipment = tempCarEquipment; ourCars.Add(tempCarProfile); ourEquip.Add(tempCarEquipment); } ourCars.ForEach(c => { List <PossibleToRentDay> possibleToRentDay = new List <PossibleToRentDay>(); for (int i = 0; i < ourCars.Count; i++) { DateTime tempDateTime = DateTime.Now + TimeSpan.FromDays(i); PossibleToRentDay tempday = new PossibleToRentDay() { Date = tempDateTime, CarProfile = c }; possibleToRentDay.Add(tempday); } List <DayThatIsRented> daysThatIs = new List <DayThatIsRented>(); for (int i = 5; i < 10; i++) { DateTime tempDateTime = DateTime.Now + TimeSpan.FromDays(i + 4); DayThatIsRented tempday = new DayThatIsRented { Date = tempDateTime, CarProfile = c, Renter = lessor }; daysThatIs.Add(tempday); } c.PossibleToRentDays = possibleToRentDay; c.DaysThatIsRented = daysThatIs; c.StartLeaseTime = daysThatIs[0].Date; c.EndLeaseTime = daysThatIs[4].Date; }); Message ourMessage1 = new Message() { HaveBeenSeen = true, ConfirmationStatus = 0, TheMessage = "Can I rent your car please?", LessorEmail = lessor.Email, RenterEmail = renter.Email, SenderEmail = renter.Email, ReceiverEmail = lessor.Email, CreatedDate = new DateTime(2019, 05, 2), MsgType = 1, CarProfile = ourCars[0], CarProfileRegNr = ourCars[0].RegNr, MessagesWithUsers = new List <MessagesWithUsers>() }; Message ourMessage2 = new Message() { HaveBeenSeen = true, ConfirmationStatus = 2, TheMessage = "Yes you can!", LessorEmail = lessor.Email, RenterEmail = renter.Email, SenderEmail = lessor.Email, ReceiverEmail = renter.Email, CreatedDate = new DateTime(2019, 05, 3), MsgType = 0, CarProfile = ourCars[1], CarProfileRegNr = ourCars[1].RegNr, MessagesWithUsers = new List <MessagesWithUsers>() }; Message ourMessage3 = new Message() { HaveBeenSeen = false, ConfirmationStatus = 1, TheMessage = "Can I rent another car??", LessorEmail = lessor.Email, RenterEmail = renter.Email, SenderEmail = renter.Email, ReceiverEmail = lessor.Email, CreatedDate = new DateTime(2019, 05, 4), MsgType = 1, CarProfile = ourCars[2], CarProfileRegNr = ourCars[2].RegNr, MessagesWithUsers = new List <MessagesWithUsers>() }; using (var db = new AppDbContext()) { await db.AddUser(renter); await db.AddUser(lessor); foreach (var car in ourCars) { await db.AddCarProfile(car); } await db.AddMessage(ourMessage1); await db.AddMessage(ourMessage2); await db.AddMessage(ourMessage3); } }
//Create public async Task AddCarEquipment(CarEquipment carEquipment) { CarEquipment.Add(carEquipment); await SaveChangesAsync(); }
static void Main(string[] args) { var context = new ProjectContext(); var trans1 = new Transmission(); trans1.Type = "automatic"; context.Transmissions.Add(trans1); var trans2 = new Transmission(); trans2.Type = "manual"; context.Transmissions.Add(trans2); var fuel1 = new Fuel(); fuel1.Type = "diesel"; context.Fuels.Add(fuel1); var fuel2 = new Fuel(); fuel2.Type = "gasolene"; context.Fuels.Add(fuel2); // var equipment1 = new Equipment(); equipment1.Name = "airbag"; context.Equipment.Add(equipment1); var equipment2 = new Equipment(); equipment2.Name = "Seatbelts"; context.Equipment.Add(equipment2); var equipment3 = new Equipment(); equipment3.Name = "Gps"; context.Equipment.Add(equipment3); // var engine1 = new Engine(); engine1.Name = "V7"; engine1.CC = 3500; context.Engines.Add(engine1); var engine2 = new Engine(); engine2.Name = "V8"; engine2.CC = 3500; context.Engines.Add(engine2); var model = new Model(); model.Name = "maserati"; context.Models.Add(model); var car1 = new Car(); car1.Name = "X1"; car1.Price = 58000; car1.Engine = engine1; car1.Model = model; car1.Fuel = fuel1; car1.Transmission = trans1; car1.Alt = "X1"; car1.Src = "www.example.com"; car1.CarEquipment = new List <CarEquipment>(); var carEquipment1 = new CarEquipment(); carEquipment1.Equipment = equipment1; car1.CarEquipment.Add(carEquipment1); var carEquipment2 = new CarEquipment(); carEquipment2.Equipment = equipment2; car1.CarEquipment.Add(carEquipment2); context.Cars.Add(car1); var car2 = new Car(); car2.Name = "X2"; car2.Price = 58000; car2.Engine = engine1; car2.Model = model; car2.Fuel = fuel1; car2.Transmission = trans1; car2.Alt = "X2"; car2.Src = "www.example.com"; car2.CarEquipment = new List <CarEquipment>(); var carEquipment3 = new CarEquipment(); carEquipment3.Equipment = equipment1; car2.CarEquipment.Add(carEquipment3); var carEquipment4 = new CarEquipment(); carEquipment4.Equipment = equipment2; car2.CarEquipment.Add(carEquipment4); var carEquipment5 = new CarEquipment(); carEquipment5.Equipment = equipment3; car2.CarEquipment.Add(carEquipment5); context.Cars.Add(car2); context.SaveChanges(); }