예제 #1
0
        public async Task <CarConfirmation> UpdateCarAsync(Guid carOwnerId, Guid updateCarId, CarPutBody putCarBody)
        {
            var carToUpdate = await _context.Set <Car>()
                              .Where(e => e.CarOwnerId == carOwnerId)
                              .FirstOrDefaultAsync(e => e.Id == updateCarId);

            if (carToUpdate == null)
            {
                return(null);
            }

            carToUpdate.Mark  = putCarBody.Mark;
            carToUpdate.Model = putCarBody.Model;
            carToUpdate.DateOfManufacturing = putCarBody.DateOfManufacturing;
            carToUpdate.KW          = putCarBody.KW;
            carToUpdate.Cm3         = putCarBody.Cm3;
            carToUpdate.ChassisMark = putCarBody.ChassisMark;
            carToUpdate.EngineMark  = putCarBody.EngineMark;
            carToUpdate.FuelType    = putCarBody.FuelType;
            carToUpdate.CarBodyType = putCarBody.CarBodyType;

            await _context.SaveChangesAsync();

            _logger.LogInformation("UpdateCarsAsync() Executed!");
            return(await Task.FromResult(_mapper.Map <CarConfirmation>(carToUpdate)));
        }
예제 #2
0
        public async Task <ActionResult <CarConfirmation> > PutCar(Guid carOwnerId, Guid carUpdateId, [FromBody] CarPutBody carToPutBody)
        {
            var updateCarConfirmation = await _service.UpdateCarAsync(carOwnerId, carUpdateId, carToPutBody);

            if (updateCarConfirmation == null)
            {
                return(BadRequest());
            }
            return(Ok(updateCarConfirmation));
        }