Esempio n. 1
0
        public ActionResult Create(BookingInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var booking  = this.Mapper.Map <HotelSystem.Data.Models.Booking>(model);
            var freeRoom = this.hotelRooms.FreeHotelRoom(model.HotelName, model.RoomType);

            if (freeRoom == null)
            {
                this.TempData["Error"] = "There's no available rooms!";
                return(this.View(model));
            }

            booking.HotelRoomsId = freeRoom.Id;
            this.bookings.CreateBooking(booking);

            freeRoom.Booked = true;
            this.hotelRooms.Update();

            this.TempData["Success"] = "Booking was successful!";
            return(this.RedirectToAction("Index"));
        }
        public async Task AddAsync(BookingInputModel input, string userId)
        {
            var offer = this.offersRepository.All()
                        .FirstOrDefault(o =>
                                        o.Id == input.OfferId &&
                                        o.Property.ApplicationUserId != userId &&
                                        o.Count > 0);

            if (offer == null ||
                offer.ValidFrom.AddDays(2) > input.CheckIn ||
                offer.ValidTo < input.CheckOut)
            {
                throw new Exception(GlobalConstants.ErrorMessages.BookingErrorValue);
            }

            var applicationUserOffer = new Booking
            {
                ApplicationUserId = userId,
                OfferId           = input.OfferId,
                CheckIn           = input.CheckIn,
                CheckOut          = input.CheckOut,
            };

            offer.Count--;

            offer.Bookings.Add(applicationUserOffer);
            await this.offersRepository.SaveChangesAsync();
        }
        public ActionResult Create(BookingInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var booking = this.Mapper.Map<HotelSystem.Data.Models.Booking>(model);
            var freeRoom = this.hotelRooms.FreeHotelRoom(model.HotelName, model.RoomType);

            if (freeRoom == null)
            {
                this.TempData["Error"] = "There's no available rooms!";
                return this.View(model);
            }

            booking.HotelRoomsId = freeRoom.Id;
            this.bookings.CreateBooking(booking);

            freeRoom.Booked = true;
            this.hotelRooms.Update();

            this.TempData["Success"] = "Booking was successful!";
            return this.RedirectToAction("Index");
        }
Esempio n. 4
0
        public async Task <IActionResult> PostBooking(
            [FromRoute] int year,
            [FromRoute] int month,
            [FromRoute] int day,
            [FromBody] BookingInputModel input)
        {
            var bookingMonthId = BookingMonthId.From(new DateTime(year, month, day));
            var bookingMonth   = await _repository.Find(bookingMonthId);

            if (bookingMonth == null)
            {
                bookingMonth = new BookingMonth(bookingMonthId, year, month, new Dictionary <int, BookingDay>());
            }

            var userId = UserId.With(HttpContext.GetUserId().Value);
            var slot   = (Slot)input.Slot;

            bookingMonth.AddBooking(userId, day, slot);

            await _repository.Upsert(bookingMonth);

            var responseModel = await _factory.From(bookingMonth.BookingDays[day].Bookings[slot], input.Slot);

            return(CreatedAtAction("GetBookingSlot", new { year = year, month = month, day = day, slot = input.Slot, }, responseModel));
        }
        public async Task <IActionResult> Create(string id, BookingInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var status = await this.bookingService.CreateBooking(
                id,
                input.BookingDate,
                input.FullName,
                input.CompanyName,
                input.Email,
                input.PhoneNumber,
                input.Days,
                input.HireDescription);

            // TODO Test this because Sendgrid suspended the account...
            var bookedUserEmail = await this.bookingService.GetUserEmail(id);

            // TODO Build an html email response if there is time;
            var emailContentBuilder = new StringBuilder();

            emailContentBuilder.AppendLine($"<p>Company name - {input.CompanyName}</p>");
            emailContentBuilder.AppendLine($"<br>");
            emailContentBuilder.AppendLine($"<p>Phone number - {input.PhoneNumber}</p>");
            emailContentBuilder.AppendLine($"<br>");
            emailContentBuilder.AppendLine($"<p>Approximate days for hire - {input.Days} days.</p>");
            emailContentBuilder.AppendLine($"<br>");
            emailContentBuilder.AppendLine($"<p>Description : {input.HireDescription}</p>");
            await this.emailSender.SendEmailAsync(
                input.Email,
                input.FullName,
                bookedUserEmail,
                GlobalConstants.BookingRequest,
                emailContentBuilder.ToString());

            // await this.emailSender.SendEmailAsync(
            //    input.e,
            //    model.Name,
            //    GlobalConstants.SystemEmail,
            //    model.Subject,
            //    model.Message);
            return(this.RedirectToAction("Result", new { result = status }));
        }
        public async Task <IActionResult> Book(BookingInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                this.TempData[GlobalConstants.ErrorMessages.BookingErrorKey] = GlobalConstants.ErrorMessages.BookingErrorValue;
                return(this.RedirectToAction(
                           "ById",
                           "SearchProperties",
                           new SearchedInputModel
                {
                    CheckIn = input.CheckIn,
                    CheckOut = input.CheckOut,
                    Id = input.PropertyId,
                    Members = input.Members,
                }));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            try
            {
                await this.bookingsService.AddAsync(input, user.Id);
            }
            catch (Exception ex)
            {
                this.TempData[GlobalConstants.ErrorMessages.BookingErrorKey] = ex.Message;
                return(this.RedirectToAction(
                           "ById",
                           "SearchProperties",
                           new SearchedInputModel
                {
                    CheckIn = input.CheckIn,
                    CheckOut = input.CheckOut,
                    Id = input.PropertyId,
                    Members = input.Members,
                }));
            }

            return(this.RedirectToAction(nameof(this.All)));
        }