public RentalAreaDTO Map(RentalArea r) { var rental = new RentalAreaDTO { Id = r.Id, Name = r.Name, OutOfBondsPenaltyPerDistanceUnit = r.OutOfBondsPenaltyPerDistanceUnit.Amount, Area = new List <PositionDTO>(), CarStartingPositionDTO = new PositionDTO { Latitude = r.CarStartingPosition.Latitude, Longitude = r.CarStartingPosition.Longitude } }; foreach (var point in r.Area.Polygon) { rental.Area.Add(new PositionDTO { Latitude = point.Latitude, Longitude = point.Longitude }); } return(rental); }
public static RentalAreaDTO CreateRentalAreaDTO() { var rentalArea = new RentalAreaDTO() { Id = new Guid(), Name = "Kraków", OutOfBondsPenaltyPerDistanceUnit = 2.5m, Area = new List <PositionDTO>() { new PositionDTO() { Latitude = 50.010231, Longitude = 19.899144 }, new PositionDTO() { Latitude = 50.011054, Longitude = 20.042123 }, new PositionDTO() { Latitude = 50.093429, Longitude = 20.057025 }, new PositionDTO() { Latitude = 50.094973, Longitude = 19.870131 } } }; return(rentalArea); }
public void UpdateRentalArea(RentalAreaDTO rentalAreaDto) { var rentalArea = _unitOfWork.RentalAreaRepository.Find(d => d.Id == rentalAreaDto.Id) .FirstOrDefault(); if (rentalArea == null) { throw new Exception($"Rental Area with {rentalAreaDto.Name} doesn't exists."); } rentalArea.Name = rentalAreaDto.Name; rentalArea.OutOfBondsPenaltyPerDistanceUnit = new Money(rentalAreaDto.OutOfBondsPenaltyPerDistanceUnit); rentalArea.Area = new Area(rentalAreaDto.Area.ToList()); _unitOfWork.Commit(); }
public RentalAreaDTO Map(RentalAreaViewModel rentalArea) { var result = new RentalAreaDTO { CarStartingPositionDTO = _positionVewModelMapper.Map(rentalArea.CarStartingPosition), Area = new List <PositionDTO>(), Id = rentalArea.Id, OutOfBondsPenaltyPerDistanceUnit = decimal.Parse(rentalArea.OutOfBondsPenaltyPerDistanceUnit), Name = rentalArea.Name }; foreach (var position in rentalArea.Area) { result.Area.Add(_positionVewModelMapper.Map(position)); } return(result); }
public RentalAreaViewModel Map(RentalAreaDTO rentalAreaDto) { var result = new RentalAreaViewModel { CarStartingPosition = _positionVewModelMapper.Map(rentalAreaDto.CarStartingPositionDTO), Area = new ObservableCollection <PositionViewModel>(), Id = rentalAreaDto.Id, OutOfBondsPenaltyPerDistanceUnit = $"{rentalAreaDto.OutOfBondsPenaltyPerDistanceUnit:0.00}", Name = rentalAreaDto.Name }; foreach (var positionDto in rentalAreaDto.Area) { result.Area.Add(_positionVewModelMapper.Map(positionDto)); } return(result); }
public void CreateRentalArea(RentalAreaDTO rentalAreaDto) { var rentalArea = _unitOfWork.RentalAreaRepository.Find(d => d.Id == rentalAreaDto.Id) .FirstOrDefault(); if (rentalArea != null) { throw new Exception($"Rental Area with {rentalArea.Id} Id already exists."); } rentalArea = _rentalAreaFactory.Create(rentalAreaDto.Id, rentalAreaDto.OutOfBondsPenaltyPerDistanceUnit, rentalAreaDto.Area.ToList(), rentalAreaDto.Name); if (rentalAreaDto.CarStartingPositionDTO != null) { rentalArea.CarStartingPosition = new Position(rentalAreaDto.CarStartingPositionDTO.Latitude, rentalAreaDto.CarStartingPositionDTO.Longitude); } _unitOfWork.RentalAreaRepository.Insert(rentalArea); _unitOfWork.Commit(); }
public static void SeedInitialData(IDriverService driverService, ICarService carService, IRentalService rentalService, IRentalAreaService rentalAreaService) { var driver = new DriverDTO { Id = Guid.NewGuid(), FirstName = "Mikołaj", LastName = "Fitowski", LicenseNumber = "CDJ813" }; var driver1 = new DriverDTO { Id = Guid.NewGuid(), FirstName = "Paweł", LastName = "Nowak", LicenseNumber = "ABBCDEFD" }; var driver2 = new DriverDTO { Id = new Guid(), FirstName = "Michał", LastName = "Kowalski", LicenseNumber = "CD1813" }; driverService.CreateDriver(driver); driverService.CreateDriver(driver1); driverService.CreateDriver(driver2); var rentalArea = new RentalAreaDTO() { Id = Guid.NewGuid(), Name = "Kraków", OutOfBondsPenaltyPerDistanceUnit = 2.5m, Area = new List <PositionDTO>() { new PositionDTO() { Latitude = 50.010231, Longitude = 19.899144 }, new PositionDTO() { Latitude = 50.011054, Longitude = 20.042123 }, new PositionDTO() { Latitude = 50.093429, Longitude = 20.057025 }, new PositionDTO() { Latitude = 50.094973, Longitude = 19.870131 } }, CarStartingPositionDTO = new PositionDTO() { Latitude = 50.057236, Longitude = 19.945147, } }; rentalAreaService.CreateRentalArea(rentalArea); var car = new CarDTO { Id = Guid.NewGuid(), RegistrationNumber = "KR12245", RentalAreaId = rentalArea.Id, CurrentLatitude = 50.057236, CurrentLongitude = 19.945147, PricePerMinute = 1 }; var car1 = new CarDTO { Id = Guid.NewGuid(), RegistrationNumber = "KR16345", RentalAreaId = rentalArea.Id, CurrentLatitude = 50.057236, CurrentLongitude = 19.945147, PricePerMinute = 1 }; var car2 = new CarDTO { Id = Guid.NewGuid(), RegistrationNumber = "KR02345", RentalAreaId = rentalArea.Id, CurrentLatitude = 50.057236, CurrentLongitude = 19.945147, PricePerMinute = 1 }; var car3 = new CarDTO { Id = Guid.NewGuid(), RegistrationNumber = "KRA2345", RentalAreaId = rentalArea.Id, CurrentLatitude = 50.057236, CurrentLongitude = 19.945147, PricePerMinute = 0.5m }; carService.CreateCar(car); carService.CreateCar(car1); carService.CreateCar(car2); carService.CreateCar(car3); var rentalId = Guid.NewGuid(); var startTime = new DateTime(2020, 04, 19); rentalService.TakeCar(rentalId, car.Id, driver.Id, startTime); rentalService.ReturnCar(rentalId, DateTime.Now); var rentalId1 = Guid.NewGuid(); var startTime1 = new DateTime(2020, 05, 19); rentalService.TakeCar(rentalId1, car1.Id, driver.Id, startTime1); rentalService.ReturnCar(rentalId1, DateTime.Now); var rentalId2 = Guid.NewGuid(); var startTime2 = new DateTime(2020, 05, 17); rentalService.TakeCar(rentalId2, car2.Id, driver.Id, startTime2); rentalService.ReturnCar(rentalId2, DateTime.Now); var rentalId3 = Guid.NewGuid(); var startTime3 = new DateTime(2020, 06, 25, 20, 0, 20); rentalService.TakeCar(rentalId3, car3.Id, driver1.Id, startTime3); }