Пример #1
0
 public async Task <int> Post([FromBody] Car car)
 {
     using (_logger.BeginScope($"creating car. {car.Name}"))
     {
         return(await _carService.AddAsync(car));
     }
 }
Пример #2
0
        public async Task <ActionResult> Add([Bind(Include = "CarId,CarModel,CarMaker,CarYearOfProduction,CarKilometers,CarPrice,CarDescription")] CarViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                await Service.AddAsync(AutoMapper.Mapper.Map <ICars>(viewModel));

                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
Пример #3
0
        public async Task <IActionResult> Add(CarAddDto addDto)
        {
            var result = await _carService.AddAsync(_mapper.Map <Car>(addDto));

            if (result.Success)
            {
                return(Created("", result));
            }
            return(BadRequest(result));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Brand,Model,Color,Billede")] CarViewModel car)
        {
            if (ModelState.IsValid)
            {
                await _carService.AddAsync(Mapper.Map(car)).ConfigureAwait(false);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(car));
        }
Пример #5
0
        public async Task <IActionResult> AddAsync(CarAddDto carAddDto)
        {
            var result = await _carService.AddAsync(carAddDto);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Пример #6
0
        public async Task <IActionResult> Create(Car car)
        {
            if (ModelState.IsValid)
            {
                car.UserId = new Guid(_userManager.GetUserId(HttpContext.User));
                await _carService.AddAsync(car);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(car));
        }
Пример #7
0
        public async Task <ActionResult <Car> > Post([FromBody] Car Car)
        {
            if (ModelState.IsValid)
            {
                var result = await _carService.AddAsync(Car);

                return(CreatedAtAction(nameof(Get), new { id = result.Id }, result));
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #8
0
        public async Task <ActionResult> Post([FromBody] CarDto carDto)
        {
            try
            {
                if (carDto == null)
                {
                    return(BadRequest($"{nameof(carDto)} can not not be null!"));
                }
                await _carService.AddAsync(carDto);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Пример #9
0
        public async Task HandleAsync(AddVehicle command)
        {
            if (command.Images != null)
            {
                AddImageToCar.Add(_hostingEnvironment, command.Images, command.Car);
            }

            if (!command.Car.Milage.Contains("km"))
            {
                command.Car.Milage += " km";
            }
            if (!command.Car.Power.Contains("KM"))
            {
                command.Car.Power += " KM";
            }

            await _carService.AddAsync(command.Car);
        }
Пример #10
0
        public async Task <IHttpActionResult> PostCar(CarDto carDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Car car = new Car();

            Mapper.Map(carDto, car);

            car.ApplicationUserId = User.Identity.GetUserId();

            car = await _carService.AddAsync(car);

            carDto.CarId = car.Id;

            return(CreatedAtRoute("ApiRoute", new { id = carDto.CarId }, carDto));
        }
Пример #11
0
        public async Task <IActionResult> Save(CarDto carDto)
        {
            var car = await _carService.AddAsync(_mapper.Map <Car>(carDto));

            return(Created(string.Empty, _mapper.Map <CarDto>(car)));
        }