本文整理汇总了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)
}
示例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)
}