當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.Booking類代碼示例

本文整理匯總了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)
}
開發者ID:cocoa-alex,項目名稱:revel,代碼行數:29,代碼來源:hotels.go

示例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)
}
開發者ID:na-lan,項目名稱:revel,代碼行數:41,代碼來源:hotels.go


注:本文中的github.com/robfig/revel/samples/booking/app/models.Booking類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。