Ejemplo n.º 1
0
        public async Task <IActionResult> GetVenueByIdAsync(Guid id)
        {
            VenueInventoryViewModel selectedVenue = await _venueService.GetVenueByIdAsync(id);

            if (selectedVenue == null)
            {
                return(NotFound(new { message = "No such venue found" }));
            }

            return(Ok(selectedVenue));
        }
Ejemplo n.º 2
0
        public async Task <VenueInventoryViewModel> GetVenueByIdAsync(Guid VenueID)
        {
            try
            {
                VenueDetail selectedVenue = await _venueInventoryRepository.GetByIdAsync(VenueID);

                VenueInventoryViewModel selectedVenueDetails = new VenueInventoryViewModel
                {
                    VenueID                         = selectedVenue.VenueID,
                    VenueName                       = selectedVenue.VenueName,
                    AirConditioningType             = selectedVenue.InventoryDetails.AirConditioningType,
                    VenueState                      = selectedVenue.VenueState,
                    VenueCity                       = selectedVenue.VenueCity,
                    ContactNumber                   = selectedVenue.ContactNumber,
                    Description                     = selectedVenue.InventoryDetails.Description,
                    IsCoffeeVendingMachineAvailable = selectedVenue.InventoryDetails.IsCoffeeVendingMachineAvailable,
                    IsWaterVendingMachineAvailable  = selectedVenue.InventoryDetails.IsWaterVendingMachineAvailable,
                    WirelessNetworkType             = selectedVenue.InventoryDetails.WirelessNetworkType,
                    HourlyRate                      = selectedVenue.InventoryDetails.HourlyRate,
                    IsActive                        = selectedVenue.IsActive,
                    IsFoodVendingMachineAvailable   = selectedVenue.InventoryDetails.IsFoodVendingMachineAvailable,
                    NumberOfMicroPhones             = selectedVenue.InventoryDetails.NumberOfMicroPhones,
                    NumberOfPhones                  = selectedVenue.InventoryDetails.NumberOfPhones,
                    NumberOfProjectors              = selectedVenue.InventoryDetails.NumberOfProjectors,
                    RoomType                        = selectedVenue.InventoryDetails.RoomType,
                    SeatCapacity                    = selectedVenue.InventoryDetails.SeatCapacity,
                    VenueImages                     = selectedVenue.VenueImages
                };


                Guard.Against.NullItem <VenueDetail>(selectedVenue);
                return(selectedVenueDetails);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddBookingAsync([FromBody] BookingModelDTO BookingModelDTO)
        {
            Guard.Against.Null(BookingModelDTO, nameof(BookingModelDTO));

            bool refCodeDiscount = false;

            if (!string.IsNullOrEmpty(BookingModelDTO.ReferralCode))
            {
                (bool HasReferralCodeTransactionCountExceeded, bool IsDuplicateTransaction, bool IsReferralCodeSelfUsed) = await _bookingManager.CheckReferralCodeAsync(BookingModelDTO.ReferralCode, Guid.Parse(BookingModelDTO.UserID));

                if (HasReferralCodeTransactionCountExceeded)
                {
                    return(BadRequest(new { message = "Referral Code provided cannot be used, as it has been used 3 times." }));
                }
                if (IsDuplicateTransaction)
                {
                    return(BadRequest(new { message = "Referral Code shared to you cannot be used more than once, please apply with a fresh one." }));
                }
                if (IsReferralCodeSelfUsed)
                {
                    return(BadRequest(new { message = "Referral Code provider and the beneficiary cannot be same!" }));
                }

                refCodeDiscount = true;
            }

            DateTime bookingFromDate = DateTime.Parse(BookingModelDTO.BookedFrom, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
            DateTime bookingToDate   = DateTime.Parse(BookingModelDTO.BookedTo, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);

            bool availabilityOfVenue = await _bookingManager.CheckBookingAvailabilityAsync(bookingFromDate, bookingToDate, BookingModelDTO.VenueID);

            if (!availabilityOfVenue)
            {
                return(BadRequest(new { message = "Sorry, try to book for some other slot, the current selected slot is already booked by someone else." }));
            }

            Guid     bookingId       = Guid.NewGuid();
            TimeSpan bookingTimeSpan = (bookingToDate - bookingFromDate);

            VenueInventoryViewModel selectedVenueDetail = await _venueService.GetVenueByIdAsync(BookingModelDTO.VenueID);

            double calculatedPrice = bookingTimeSpan.TotalHours * selectedVenueDetail.HourlyRate;

            if (refCodeDiscount)
            {
                calculatedPrice = calculatedPrice - (0.1 * calculatedPrice);
            }
            //Entity Model
            Booking newBooking = new Booking
            {
                BookingID       = bookingId,
                VenueID         = BookingModelDTO.VenueID,
                BookingFromDate = bookingFromDate,
                BookingToDate   = bookingToDate,
                UserID          = Guid.Parse(BookingModelDTO.UserID),
                Price           = calculatedPrice,
                BookingStatus   = BookingStatus.ACTIVE.ToString()
            };

            await _bookingManager.AddNewBookingAsync(newBooking, BookingModelDTO.ReferralCode, BookingModelDTO.TimeZoneId);

            return(StatusCode(201, new { message = $"Successfully booked the venue {selectedVenueDetail.VenueName}." }));
        }