public async Task AddCarTestAsync(string make, string model, short year, int expected) { var car = new Car { Make = make, Model = model, Year = year }; var carId = await _carService.AddCarAsync(car); Assert.Equal(expected, carId); }
public async Task <IActionResult> AddCarAsync([FromBody] CarInputDto carInputDto) { if (ModelState.IsValid) { await _carService.AddCarAsync(carInputDto); return(Ok()); } return(BadRequest()); }
public async Task <IActionResult> AddCarAsync([FromBody] AddCarRequestDto dto, CancellationToken cancellationToken = default(CancellationToken)) { var result = await _carService.AddCarAsync(dto, cancellationToken); if (result == null) { return(BadRequest(new ApiResponse(StatusCodes.Status400BadRequest))); } var response = new ApiOkResponse(result); return(Ok(response)); }
public async Task <ActionResult <CarModel> > Post(CarModel car, CancellationToken ct = default) { try { if (car != null) { return(StatusCode(CreatedCode, await carService.AddCarAsync(car, ct))); } } catch (Exception ex) { return(StatusCode(InternalServerErrorCode, ex)); } return(BadRequest()); }
public async Task <IActionResult> AddCarAsync(CarDto carDto) { try { var car = _mapper.Map <Car>(carDto); var carId = await _carService.AddCarAsync(car); if (carId == 0) { return(BadRequest($"Car with the combination(Make: {carDto.Make}, Model: {carDto.Model}, Year: {carDto.Year}) already exists in DB.")); } return(Ok(car)); } catch (Exception ex) { var result = StatusCode(StatusCodes.Status500InternalServerError, ex.Message); return(result); } }
public async Task <IActionResult> AddCar(CarForAddDto model) { //if (!User.Identity.IsAuthenticated) // return Unauthorized(); //if (!User.IsInRole("Admin")) // return Unauthorized(); if (!ModelState.IsValid) { return(BadRequest("Something went wrong while adding the car")); } var car = new Car { CarNumber = model.CarNumber, BrandId = model.BrandId, ModelId = model.ModelId, ModelYear = model.ModelYear, FuelTypeId = model.FuelTypeId, TransmisionTypeId = model.TransmisionTypeId, NumberOfDoors = model.NumberOfDoors, CarCapacity = model.CarCapacity, CarColor = model.CarColor, PriceForDay = model.PriceForDay, CarLocationId = model.CarLocationId, Description = model.Description, CreateByUserId = _userManager.GetUserId(User), }; await _carService.AddCarAsync(car); if (model.Image != null && model.Image.Length > 0) { await _carService.UploadImage(model.Image, car.Id); } return(Ok(new { message = "Car added successfully" })); }
public async Task <IActionResult> Post([FromBody] CarDto carDto) { if (!await CheckIfClientAsync()) { return(StatusCode(StatusCodes.Status403Forbidden, "No client account has been found.")); } var id = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); var model = await _carService.AddCarAsync(id, carDto); if (model == null) { return(Conflict(new { Error = "Request unsuccessfull." })); } _logger.LogInformation("User {User} added Car Model to db", HttpContext.User.Identity.Name); return(Ok(model)); }
public async Task <IActionResult> AddCar(Car newCar) { var car = await _carService.AddCarAsync(newCar); return(Ok(car)); }
public async Task <ActionResult <AddCarCommandResult> > CreateCarAsync([FromBody] AddCarDto request) { var result = await _carService.AddCarAsync(request); return(Ok(result)); }
public async Task <ActionResult <SingleCar> > AddCar(SingleCar singleCar) { return(Ok(await _service.AddCarAsync(singleCar).ConfigureAwait(false))); }