当前位置: 首页>>代码示例>>Golang>>正文


Golang ContestModel.Update方法代码示例

本文整理汇总了Golang中GoOnlineJudge/model.ContestModel.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang ContestModel.Update方法的具体用法?Golang ContestModel.Update怎么用?Golang ContestModel.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GoOnlineJudge/model.ContestModel的用法示例。


在下文中一共展示了ContestModel.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Update

// 更新竞赛
//@URL:/admin/contests/(\d+)/ @method:POST
func (cc *AdminContest) Update(Cid string) {
	restweb.Logger.Debug("Admin Contest Update")

	cid, err := strconv.Atoi(Cid)
	if err != nil {
		cc.Error("args error", 400)
		return
	}
	contestModel := model.ContestModel{}
	old, _ := contestModel.Detail(cid)
	if old.Creator != cc.Uid {
		cc.Error("privilege error", 400)
		return
	}

	one := cc.contest()

	err = contestModel.Update(cid, one)
	if err != nil {
		cc.Error(err.Error(), 400)
		return
	}
	cc.Redirect("/admin/contests", http.StatusFound)
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:26,代码来源:contest.go

示例2: Update

// 更新竞赛,url:/admin/contest/update/,method:POST
func (this *ContestController) Update(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin Contest Update")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Update contest")
		return
	}

	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	cid, err := strconv.Atoi(args["cid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}
	Type := args["type"]

	one := model.Contest{}
	one.Title = r.FormValue("title")
	one.Type = Type
	year, _ := strconv.Atoi(r.FormValue("startTimeYear"))
	month, _ := strconv.Atoi(r.FormValue("startTimeMonth"))
	day, _ := strconv.Atoi(r.FormValue("startTimeDay"))
	hour, _ := strconv.Atoi(r.FormValue("startTimeHour"))
	min, _ := strconv.Atoi(r.FormValue("startTimeMinute"))

	start := time.Date(year, time.Month(month), day, hour, min, 0, 0, time.Local)
	one.Start = start.Unix()

	year, _ = strconv.Atoi(r.FormValue("endTimeYear"))
	month, _ = strconv.Atoi(r.FormValue("endTimeMonth"))
	day, _ = strconv.Atoi(r.FormValue("endTimeDay"))
	hour, _ = strconv.Atoi(r.FormValue("endTimeHour"))
	min, _ = strconv.Atoi(r.FormValue("endTimeMinute"))
	end := time.Date(year, time.Month(month), day, hour, min, 0, 0, time.Local)
	one.End = end.Unix()

	if start.After(end) {
		http.Error(w, "this.Query error", 400)
		return
	}

	switch r.FormValue("type") {
	case "public":
		one.Encrypt = config.EncryptPB
		one.Argument = ""
	case "private":
		one.Encrypt = config.EncryptPT
		argument := r.FormValue("userlist")
		var cr rune = 13
		crStr := string(cr)
		argument = strings.Trim(argument, crStr)
		argument = strings.Trim(argument, "\r\n")
		argument = strings.Replace(argument, "\r\n", "\n", -1)
		argument = strings.Replace(argument, crStr, "\n", -1)
		one.Argument = argument
	case "password":
		one.Encrypt = config.EncryptPW
		one.Argument = r.FormValue("password")
	default:
		http.Error(w, "args error", 400)
		return
	}
	class.Logger.Debug(one.Argument)
	problemString := r.FormValue("problemList")
	problemString = strings.Trim(problemString, " ")
	problemString = strings.Trim(problemString, ";")
	problemList := strings.Split(problemString, ";")
	var list []int
	for _, v := range problemList {
		pid, err := strconv.Atoi(v)
		if err != nil {
			http.Error(w, "conv error", 400)
			return
		}
		list = append(list, pid)
	}
	one.List = list

	contestModel := model.ContestModel{}
	err = contestModel.Update(cid, one)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	http.Redirect(w, r, "/admin/contest?list/type?"+Type, http.StatusFound)
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:88,代码来源:contest.go


注:本文中的GoOnlineJudge/model.ContestModel.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。