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); }
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)); }
public async Task <int> AddAsync(Car car) { _logger.LogInformation("adding a car"); var newCar = await _carRepository.AddAsync(car); return(newCar.Id); }
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); }
public async Task CreateAsync(Car car) { var customer = await _customerRepository.FindByIdAsync(car.Customer.Id); if (customer == null) { throw new CustomerNotFoundException(); } await _carRepository.AddAsync(car); }
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); }
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(); }
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}")); } }
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()); }
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()); }
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)); } }
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)); }
public async Task <int> AddAsync(ICars entity) { return(await Repository.AddAsync(AutoMapper.Mapper.Map <ICars>(entity))); }
public async Task <IActionResult> Index(Car car) { await _carRepository.AddAsync(car); return(await Task.FromResult(RedirectToAction("MyList"))); }
public async Task <Car> AddAsync(Car car) { return(await _carRepository.AddAsync(car)); }
public async Task HandleAsync(CarCreated @event) { await _carRepository.AddAsync(new Car(@event.Id)); }
public async Task AddAsync(CarDto obj) => await _repository.AddAsync(_mapper.Map <CarDto, Car>(obj));