本文整理汇总了Golang中github.com/robfig/revel/samples/booking/app/models.Booking.Hotel方法的典型用法代码示例。如果您正苦于以下问题:Golang Booking.Hotel方法的具体用法?Golang Booking.Hotel怎么用?Golang Booking.Hotel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/robfig/revel/samples/booking/app/models.Booking
的用法示例。
在下文中一共展示了Booking.Hotel方法的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)
}