コード例 #1
0
ファイル: hotels.go プロジェクト: cocoa-alex/revel
func (c Hotels) ConfirmBooking(id int, booking models.Booking) revel.Result {
	hotel := c.loadHotelById(id)
	if hotel == nil {
		return c.NotFound("Hotel %d does not exist", id)
	}

	title := fmt.Sprintf("Confirm %s booking", hotel.Name)
	booking.Hotel = hotel
	booking.User = c.connected()
	booking.Validate(c.Validation)

	if c.Validation.HasErrors() || c.Params.Get("revise") != "" {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect("/hotels/%d/booking", id)
	}

	if c.Params.Get("confirm") != "" {
		err := c.Txn.Insert(&booking)
		if err != nil {
			panic(err)
		}
		c.Flash.Success("Thank you, %s, your confirmation number for %s is %d",
			booking.User.Name, hotel.Name, booking.BookingId)
		return c.Redirect(Hotels.Index)
	}

	return c.Render(title, hotel, booking)
}
コード例 #2
0
ファイル: hotels.go プロジェクト: na-lan/revel
func (c Hotels) ConfirmBooking(id int, booking models.Booking) rev.Result {
	hotel := c.loadHotelById(id)
	title := fmt.Sprintf("Confirm %s booking", hotel.Name)
	booking.Hotel = hotel
	booking.User = connected(c.Controller)
	booking.Validate(c.Validation)

	if c.Validation.HasErrors() || c.Params.Get("revise") != "" {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect("/hotels/%d/booking", id)
	}

	if c.Params.Get("confirm") != "" {
		result, err := c.Txn.Exec(`
insert into Booking (
  UserId, HotelId, CheckInDate, CheckOutDate,
  CardNumber, NameOnCard, CardExpMonth, CardExpYear,
  Smoking, Beds
) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
			booking.User.UserId,
			booking.Hotel.HotelId,
			booking.CheckInDate.Format("2006-01-02"),
			booking.CheckOutDate.Format("2006-01-02"),
			booking.CardNumber,
			booking.NameOnCard,
			booking.CardExpMonth,
			booking.CardExpYear,
			booking.Smoking,
			booking.Beds)
		if err != nil {
			panic(err)
		}
		bookingId, _ := result.LastInsertId()
		c.Flash.Success("Thank you, %s, your confirmation number for %s is %d",
			booking.User.Name, hotel.Name, bookingId)
		return c.Redirect(Hotels.Index)
	}

	return c.Render(title, hotel, booking)
}