本文整理匯總了Golang中github.com/robfig/revel/samples/booking/app/models.Booking類的典型用法代碼示例。如果您正苦於以下問題:Golang Booking類的具體用法?Golang Booking怎麽用?Golang Booking使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Booking類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConfirmBooking
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: ConfirmBooking
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)
}