public void InitializeGarage() { var garage = _garageRepository.GetAll(); if (garage.Count == 0) { var garage1 = new Garage() { Id = Guid.Parse("8b3c08d1-37fb-4879-9fb1-f456e366a030"), Name = "ГАРАЖА", Address = "Street-OT", Email = "*****@*****.**", PhoneNumber = "464846466", MaxCarsInStock = 50, CreatedBy = "Tatjana", Created = DateTime.UtcNow }; _garageRepository.Add(garage1); var garage2 = new Garage() { Id = Guid.Parse("e1a4cfd6-14b2-4aec-aa93-8822f0b84a46"), Name = "НЕ ПАРКИРАЈ", Address = "Car-OT", Email = "*****@*****.**", PhoneNumber = "5465464", MaxCarsInStock = 51, CreatedBy = "Tatjana", Created = DateTime.UtcNow }; _garageRepository.Add(garage2); } }
public bool approveGarage(Application application) { Garage garage = new Garage(); Location location = new Location(); var holder = applicationRepository.Update(application); bool gar, loc; if (holder) { garage.garageName = application.garageName; garage.username = application.username; garage.password = application.password; garage.email = application.email; garage.phoneNumber = application.phoneNumber; } gar = garageRepository.Add(garage); var garageId = garageRepository.garages.Where(g => g.username == application.username).Select(g => g.Id).FirstOrDefault(); if (garageId != 0) { location.ApplicationId = application.Id; location.GarageId = garageId; location.longitude = application.longitude; location.latitude = application.lattitude; } loc = locationRepository.Add(location); return(gar && loc); }
public void InsertGarage(Garage garage) { var addGarage = _garageRepository.GetAll().Where(x => x.Name == garage.Name).FirstOrDefault(); if (addGarage != null) { throw new Exception("The Garage With That Name Already Exists"); } garage.Id = Guid.NewGuid(); _garageRepository.Add(garage); _memoryCache.Remove(_allGaragesKey); }
public async Task <Garage> CreateAsync(Garage garage) { if (garage == null) { throw new ArgumentException(); } if (!garage.AreaId.HasValue) { throw new ArgumentException(nameof(garage.AreaId)); } if (_garageRepository.GetByIdAsync(garage.Id).Result != null) { throw new Exception("Bad Request: garage already exists"); } if (!_areaRepository.AnyAsync(a => a.Id == garage.AreaId).Result) { throw new Exception("Bad Request: area does not exist"); } if (garage.Cars != null) { foreach (var car in garage.Cars) { if (!car.CategoryId.HasValue || !_carCategoryRepository.AnyAsync(c => c.Id == car.CategoryId.Value).Result) { throw new Exception($"Bad Request: carCategory of {car.Title} does not exist"); } } } var garageEntity = Mapper.Map <GarageEntity>(garage); _garageRepository.Add(garageEntity); try { await _garageRepository.SaveChangesAsync(); return(Mapper.Map <Garage>(garageEntity)); } catch (Exception e) { // log error throw e; } }
public void TestNumVehiclesIsCorrectWhenClearing() { //Arrange foreach (var vehicle in list) { garageRepository.Add(vehicle); } //Act garageRepository.Clear(); //Assert Assert.AreEqual(0, garageRepository.Occupied); }