Пример #1
0
        public async Task AddAsync(Guid id, string Brand, string model, int yearofproduction, string milage, string capacity, string fueltype, string power, string description, decimal price, string pictureurl)
        {
            var car = await _carReposotory.GetAsync(id);

            if (car != null)
            {
                throw new Exception($"Car with id: '{id}' already exists.");
            }
            car = new Car(id, Brand, model, yearofproduction, milage, capacity, fueltype, power, description, price, pictureurl);

            await _carReposotory.AddAsync(car);
        }
Пример #2
0
        public async Task HandleAsync(CreateCar command)
        {
            var car = new Car(command.Id, command.Brand, command.Model, command.Plate);
            await _carRepository.AddAsync(car);

            await _busClient.PublishAsync(new CarCreated(command.Id));
        }
Пример #3
0
        public async Task <int> AddAsync(Car car)
        {
            _logger.LogInformation("adding a car");
            var newCar = await _carRepository.AddAsync(car);

            return(newCar.Id);
        }
Пример #4
0
        public async Task <CarDto> AddCarAsync(string id, CarDto carToAdd)
        {
            CarDto addedCar;

            try
            {
                addedCar = await _carRepository.AddAsync(carToAdd);
            }
            catch (DataException)
            {
                throw;
            }

            if (addedCar != null)
            {
                var result = await OnCarAdded?.Invoke(id, addedCar.Id);

                if (!result)
                {
                    await _carRepository.DeleteAsync((int)addedCar.Id);
                }
            }

            return(addedCar);
        }
Пример #5
0
        public async Task CreateAsync(Car car)
        {
            var customer = await _customerRepository.FindByIdAsync(car.Customer.Id);

            if (customer == null)
            {
                throw new CustomerNotFoundException();
            }

            await _carRepository.AddAsync(car);
        }
Пример #6
0
        public async Task CreateAsync(Guid id, string mark, string model, float capacity, DateTime dateOc, DateTime dateReview, int carType)
        {
            if (carType != Convert.ToInt32(CarType.Car) && carType != Convert.ToInt32(CarType.SmallTruck) && carType != Convert.ToInt32(CarType.Truck))
            {
                throw new Exception($"Car Type: '{carType}' is invalid.");
            }

            var markAlphaNumericString = new AlphaNumericString(mark);

            var modelAlphaNumericString = new AlphaNumericString(model);

            var @car = new Car(id, markAlphaNumericString, modelAlphaNumericString, capacity, dateOc, dateReview, carType);
            await _carRepository.AddAsync(@car);
        }
Пример #7
0
        public async Task <CarDTO> CreateAsync(CarDTO car)
        {
            var carToCheck = await _carRepository.GetByVinAsync(car.VIN.ToUpperInvariant());

            if (carToCheck != null)
            {
                throw new Exception($"Car with VIN: {car.VIN} already exists.");
            }
            var carToAdd = Car.Create(car.VIN.ToUpperInvariant(), car.RegistrationNumber, car.Brand, car.Model, car.Price);
            await _carRepository.AddAsync(carToAdd);

            await _carRepository.SaveAsync();

            return(car);
        }
        public async Task CreateAsync(CreateCarDto createCarDto)
        {
            var createCarCommand = new CreateCarCommand(createCarDto.Make,
                                                        createCarDto.Model,
                                                        createCarDto.Engine,
                                                        createCarDto.Doors,
                                                        createCarDto.Wheels,
                                                        createCarDto.BodyType);

            Car car = _factory.Create(createCarCommand);

            await _carRepository.AddAsync(car);

            await _context.SaveChangesAsync();
        }
Пример #9
0
        public async Task <CarResponse> SaveAsync(Car car)
        {
            try
            {
                await _carRepository.AddAsync(car);

                await _unitOfWork.CompleteAsync();

                return(new CarResponse(car));
            }
            catch (Exception e)
            {
                return(new CarResponse($"An error occured when saving the car: {e.Message}"));
            }
        }
Пример #10
0
        public async Task <object> PostAsync([FromBody] Car model)
        {
            var user = await GetLoginUserAsync();

            if (user is RentACarAdministrator)
            {
                if (!await carRepository.AddAsync(model))
                {
                    return(BadRequest(new { message = "Already exist" }));
                }
                return(Ok(model));
            }

            return(Forbid());
        }
Пример #11
0
        public async Task <ActionResult> CreateCar([FromBody] CreateCarDto createCarDto)
        {
            var car = _mapper.Map <Car>(createCarDto);
            await _carRepository.AddAsync(car);

            await _carRepository.Context.SaveChangesAsync();

            var carColor = new CarColor(car.Key, createCarDto.ColorId);
            await _carColorRepository.AddAsync(carColor);

            var carBrand = new CarBrand(car.Key, createCarDto.CarBrandId);
            await _carBrandRepository.AddAsync(carBrand);

            await _carColorRepository.Context.SaveChangesAsync();

            return(Ok());
        }
Пример #12
0
        public async Task <IActionResult> Add([FromBody] CarModel car)
        {
            try
            {
                var addResult = await _carRepository.AddAsync(car);

                if (addResult)
                {
                    return(Ok("Car is criated"));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message + "" + ex.InnerException));
            }
        }
Пример #13
0
        public async Task <CarResponseModel> CreateCar(CreateCarRequestModel requestModel)
        {
            _logger.LogInformation("CreateCar - params: requestModel={0}", requestModel);

            Car car = new Car()
            {
                CarCategoryId         = requestModel.CategoryId,
                CarImpactClassId      = requestModel.ImpactClassId,
                CarProbabilityClassId = requestModel.CarProbabilityClassId,
                DateCreated           = DateTime.UtcNow,
                Description           = requestModel.Description,
                Title    = requestModel.Title,
                GarageId = requestModel.GarageId,
            };

            await _carRepository.AddAsync(car);

            var result = await _carRepository.GetByIdAsync(car.Id);

            return(_mapper.Map <Car, CarResponseModel>(result));
        }
Пример #14
0
 public async Task <int> AddAsync(ICars entity)
 {
     return(await Repository.AddAsync(AutoMapper.Mapper.Map <ICars>(entity)));
 }
Пример #15
0
        public async Task <IActionResult> Index(Car car)
        {
            await _carRepository.AddAsync(car);

            return(await Task.FromResult(RedirectToAction("MyList")));
        }
Пример #16
0
 public async Task <Car> AddAsync(Car car)
 {
     return(await _carRepository.AddAsync(car));
 }
Пример #17
0
 public async Task HandleAsync(CarCreated @event)
 {
     await _carRepository.AddAsync(new Car(@event.Id));
 }
Пример #18
0
 public async Task AddAsync(CarDto obj) => await _repository.AddAsync(_mapper.Map <CarDto, Car>(obj));