Exemplo n.º 1
0
        /// <summary>
        /// Update booking
        /// </summary>
        /// <param name="bookingContract"></param>
        /// <param name="cancellationToken"></param>
        public async Task <bool> UpdateBooking(
            BookingUpdateContract bookingContract,
            CancellationToken cancellationToken)
        {
            var checkNull = await _dbContext.Bookings.FirstOrDefaultAsync(x => x.Id == bookingContract.Id, cancellationToken);

            if (checkNull == null)
            {
                _logger.LogInformation($"Booking with id {bookingContract.Id} are not found");
                return(false);
            }

            var booking = BookingMapping.BookingMapFromUpdateContractToModel(bookingContract, checkNull);

            try
            {
                _dbContext.Update(booking);
                await _dbContext.SaveChangesAsync(cancellationToken);
            }
            catch (Exception e)
            {
                _logger.LogInformation($"Booking with id {booking.Id} is not found");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public async Task UpdateBooking()
        {
            Setup();
            var bookings = new List <Booking>()
            {
                new() { Id = 1, ClientId = 1 },
                new() { Id = 2, ClientId = 2 },
                new() { Id = 3, ClientId = 1 }
            };

            _applicationContextMock.Setup(x => x.Bookings).ReturnsDbSet(bookings);

            _testedService = new BookingService(Logger, _applicationContextMock.Object);

            var bookingDto = new BookingUpdateContract()
            {
                Id          = 1,
                ClientId    = 1,
                ResultPrice = 500,
                ServiceId   = 1,
            };

            var result = await _testedService.UpdateBooking(bookingDto, CancellationToken.None);

            Assert.True(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// update mapp
 /// </summary>
 /// <param name="returnContract"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public static Booking BookingMapFromUpdateContractToModel(BookingUpdateContract returnContract, Booking model)
 {
     if (returnContract == null)
     {
         return(null);
     }
     model.ServiceId   = returnContract.ServiceId;
     model.ClientId    = returnContract.ClientId;
     model.ResultPrice = returnContract.ResultPrice;
     return(model);
 }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateBook(
            BookingUpdateContract newBookingReturn,
            CancellationToken cancellationToken)
        {
            var update = await _bookingService.UpdateBooking(newBookingReturn, cancellationToken);

            if (update)
            {
                return(Ok());
            }

            return(NotFound("No Booking "));
        }