public ClientAggregate Create(long clientId)
        {
            var clientResult = _clientsReadRepo.GetClient(clientId);

            if (clientResult is null)
            {
                throw new ArgumentException("No client with this id was found!");
            }
            var cars = _clientsReadRepo.GetClientCars(clientId).Select(c => new Car(c.Id, c.ClientId, c.BrandName,
                                                                                    c.ModelName, c.PlateNumber, c.RegistrationId)).ToList();

            if (cars is null)
            {
                throw new ArgumentException("No car for this client was found!");
            }
            var revisions = _clientsReadRepo.GetClientRevisions(clientId).Select(r => new Revision(r.Id, r.ClientId, r.CarId, r.Title, r.ProblemDetails)).ToList();

            if (revisions is null)
            {
                throw new ArgumentException(nameof(revisions), "No revision for this client was found!");
            }
            var client = new ClientAggregate(clientResult.Id, clientResult.FirstName, clientResult.LastName,
                                             clientResult.PhoneNumber, clientResult.Email, clientResult.Password,
                                             cars, revisions);

            return(client);
        }
Esempio n. 2
0
 public IActionResult GetClientCars(long clientId)
 {
     try
     {
         var clientCars = _clientReadRepository.GetClientCars(clientId);
         return(Ok(clientCars));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }