Exemple #1
0
        public async Task <BookingResponse> CreateInView(BookingDTO newBooking, Guid viewId)
        {
            var isAdmin = _aadService.IsAdmin();
            var booking = BookingMapper.Map(newBooking);

            if (!await _itemRepository.CheckIfAvailableToBook(booking))
            {
                string errorMessage = "Too many concurrent bookings";
                Log.Error(errorMessage);
                return(new BookingResponse(errorMessage));
            }
            if (!isAdmin && !_viewRepository.CheckIfAllowedToBook(booking.ItemId, viewId))
            {
                string errorMessage = $"Item {booking.Item.Name} can't be booked.";
                Log.Error(errorMessage);
                return(new BookingResponse(errorMessage));
            }
            try
            {
                await _bookingRepository.Create(booking);

                await _context.SaveChangesAsync();

                var showNames = _aadService.IsAdmin() || _viewRepository.GetShowNamesById(viewId);
                return(new BookingResponse(BookingMapper.Map(booking, showNames)));
            }
            catch (Exception ex)
            {
                string errorMessage = $"An error occured when creating the booking: {ex.Message}";
                Log.Error <string>(ex, "An error occured when creating the booking: {booking}", JsonSerializer.Serialize(booking));
                return(new BookingResponse(errorMessage));
            }
        }
Exemple #2
0
        public async Task UpdateStatus(Guid id, BookingState newStatus, string declineReason)
        {
            var bookingRequest = await GetById(id);

            if (newStatus == BookingState.Approved)
            {
                var booking = BookingMapper.Map(bookingRequest);
                await _bookingRepository.Create(booking);
            }
            else
            {
                bookingRequest.DeclineReason = declineReason;
            }

            bookingRequest.Status = newStatus;

            _repository.Update(bookingRequest);
            await _context.SaveChangesAsync();
        }
Exemple #3
0
        public async Task <IActionResult> Update([FromBody] BookingModel data)
        {
            var dataUpdate = await _bookingService.Update(BookingMapper.Map(data));

            return(Ok());
        }
Exemple #4
0
        public async Task <IActionResult> Add([FromBody] BookingModel data)
        {
            var dataEntity = await _bookingService.Add(BookingMapper.Map(data));

            return(Ok(dataEntity));
        }
Exemple #5
0
        public async Task <Booking> UpdateBooking(Booking booking)
        {
            var updated = await _bookinRepository.Update(BookingMapper.Map(booking));

            return(BookingMapper.Map(updated));
        }
Exemple #6
0
        public async Task <Booking> AddBooking(Booking booking)
        {
            var addedEntity = await _bookinRepository.Add(BookingMapper.Map(booking));

            return(BookingMapper.Map(addedEntity));
        }
Exemple #7
0
        public async Task <Booking> GetBooking(int id)
        {
            var entity = await _bookinRepository.Get(id);

            return(BookingMapper.Map(entity));
        }
Exemple #8
0
        public async Task <IActionResult> UpdateBooking([FromBody] BookingModel booking)
        {
            var updatedBooking = await _bookingService.UpdateBooking(BookingMapper.Map(booking));

            return(Ok(updatedBooking));
        }
Exemple #9
0
        public async Task <IActionResult> AddBooking([FromBody] BookingModel booking)
        {
            var newBooking = await _bookingService.AddBooking(BookingMapper.Map(booking));

            return(Ok(newBooking));
        }
Exemple #10
0
        public async Task <IEnumerable <BookingDTO> > GetByView(Guid viewId)
        {
            var showNames = _aadService.IsAdmin() || _viewRepository.GetShowNamesById(viewId);

            return((await _bookingRepository.GetByView(viewId)).Select(booking => BookingMapper.Map(booking, showNames)));
        }
Exemple #11
0
 public async Task <IEnumerable <BookingDTO> > GetByCategory(Guid id)
 {
     return((await _bookingRepository.GetByCategory(id)).Select(booking => BookingMapper.Map(booking)).ToList());
 }
Exemple #12
0
        public async Task <Booking> Update(Booking booking)
        {
            var data = await _bookingRepository.Update(BookingMapper.Map(booking));

            return(booking);
        }
Exemple #13
0
        public async Task <Booking> Get(int id)
        {
            var data = await _bookingRepository.Get(id);

            return(BookingMapper.Map(data));
        }