当前位置: 首页>>代码示例>>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;未经允许,请勿转载。