Пример #1
0
 public async Task <Vehicle> GetAsync(int id)
 {
     using (IDbConnection connection = _vehiclesRepository.Connection)
     {
         return(await _vehiclesRepository.GetAsync(id));
     }
 }
Пример #2
0
        public async Task HandleAsync(DeleteVehicle command)
        {
            var vehicle = await _repository.GetAsync(command.Id);

            if (vehicle is null)
            {
                throw new VehicleNotFoundException(command.Id);
            }

            await _repository.DeleteAsync(vehicle);

            await _broker.PublishAsync(new VehicleDeleted(command.Id));
        }
Пример #3
0
        public async Task HandleAsync(UpdateVehicle command)
        {
            var vehicle = await _repository.GetAsync(command.VehicleId);

            if (vehicle is null)
            {
                throw new VehicleNotFoundException(command.VehicleId);
            }

            vehicle.ChangeDescription(command.Description);
            vehicle.ChangePricePerService(command.PricePerService);
            vehicle.ChangeVariants(command.Variants);
            await _repository.UpdateAsync(vehicle);

            await _broker.PublishAsync(new VehicleUpdated(command.VehicleId));
        }
Пример #4
0
        public async Task <IActionResult> DeleteVehicleAsync(int id)
        {
            var domainVehicle = await _vehiclesRepository.GetAsync(id);

            if (domainVehicle == null)
            {
                ModelState.AddModelError("Id", $"Vehicle with Id = {id} not found!");
            }

            if (ModelState.ErrorCount > 0)
            {
                return(BadRequest(ModelState));
            }

            try {
                // ReSharper disable once AssignNullToNotNullAttribute
                _vehiclesRepository.Delete(domainVehicle);
                await _unitOfWork.CompeleteAsync();

                return(Ok(id));
            } catch (Exception e) {
                return(StatusCode(500, e.InnerException?.Message ?? e.Message));
            }
        }