public IActionResult AddCar([FromBody] CarRequest carRequest)
        {
            var car = _mapper.Map <Car>(carRequest);

            _carServices.Add(car);
            var carResponse = _mapper.Map <CarResponse>(car);

            return(Ok(carResponse));
        }
Beispiel #2
0
        public IActionResult Add(Car car)
        {
            var result = _carServices.Add(car);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public async Task <IActionResult> Add(Car car)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest));
                }

                await _carServices.Add(car);

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Beispiel #4
0
        public ActionResult <string> Post([FromBody] Car car)
        {
            try
            {
                _logger.LogInformation("Received get request");
                if (ModelState.IsValid)
                {
                    _carServices.Add(car);

                    return(Ok("Success"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, exception.Message);
                return(new StatusCodeResult(500));
            }
        }