public void CreateScooter(ScooterDTO scooterDTO) { Expression <Func <Scooter, bool> > expressionPredicate = x => x.RegistrationNumber == scooterDTO.RegistrationNumber; Scooter scooter = this._unitOfWork.ScooterRepository.Find(expressionPredicate).FirstOrDefault(); if (scooter != null) { throw new Exception($"Scooter '{scooterDTO.RegistrationNumber}' already exists"); } scooter = new Scooter(scooterDTO.Id, scooterDTO.RegistrationNumber, scooterDTO.CurrentPosition, scooterDTO.CurrentDistance, scooterDTO.TotalDistance, scooterDTO.UnitPrice, this._domainEventPublisher); this._unitOfWork.ScooterRepository.Insert(scooter); this._unitOfWork.Commit(); }
public Guid CreateScooter(string registrationNumber, Position currentPosition, Distance currentDistance, Distance totalDistance, Money unitPrice) { Guid scooterId = Guid.NewGuid(); ScooterDTO scooterDTO = new ScooterDTO() { Id = scooterId, RegistrationNumber = registrationNumber, CurrentPosition = currentPosition, CurrentDistance = currentDistance, TotalDistance = totalDistance, UnitPrice = unitPrice }; this._scooterService.CreateScooter(scooterDTO); return(scooterId); }