public async Task <ActionResult <CarOwnerConfirmation> > PutCarOwner(Guid carOwnerUpdateId, [FromBody] CarOwnerPutBody carOwnerToPutBody)
        {
            var updateCarOwnerConfirmation = await _service.UpdateCarOwnerAsync(carOwnerUpdateId, carOwnerToPutBody);

            if (updateCarOwnerConfirmation == null)
            {
                return(BadRequest());
            }

            return(Ok(updateCarOwnerConfirmation));
        }
예제 #2
0
        public async Task <CarOwnerConfirmation> UpdateCarOwnerAsync(Guid updateCarOwnerId, CarOwnerPutBody putCarOwnerBody)
        {
            var carOwnerToUpdate = await _context.Set <CarOwner>().FirstOrDefaultAsync(e => e.Id == updateCarOwnerId);

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

            carOwnerToUpdate.Name     = putCarOwnerBody.Name;
            carOwnerToUpdate.LastName = putCarOwnerBody.LastName;
            carOwnerToUpdate.City     = putCarOwnerBody.City;
            carOwnerToUpdate.Contact  = putCarOwnerBody.Contact;
            carOwnerToUpdate.Email    = putCarOwnerBody.Email;
            carOwnerToUpdate.Password = putCarOwnerBody.Password;
            await _context.SaveChangesAsync();

            _logger.LogInformation("UpdateCarOwnerAsync() Executed!");
            return(await Task.FromResult(_mapper.Map <CarOwnerConfirmation>(carOwnerToUpdate)));
        }