本文整理汇总了Golang中GoOnlineJudge/model.ContestModel.Insert方法的典型用法代码示例。如果您正苦于以下问题:Golang ContestModel.Insert方法的具体用法?Golang ContestModel.Insert怎么用?Golang ContestModel.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GoOnlineJudge/model.ContestModel
的用法示例。
在下文中一共展示了ContestModel.Insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Insert
// 插入比赛
//@URL:/admin/contests/ @method:POST
func (cc *AdminContest) Insert() {
restweb.Logger.Debug("Admin Contest Insert")
one := cc.contest()
contestModel := model.ContestModel{}
err := contestModel.Insert(one)
if err != nil {
cc.Error(err.Error(), 500)
return
}
cc.Redirect("/admin/contests", http.StatusFound) //重定向到竞赛列表页
}
示例2: Insert
// 插入比赛 url:/admin/contest?insert/type?<contest,exercise>
func (this *ContestController) Insert(w http.ResponseWriter, r *http.Request) {
class.Logger.Debug("Admin Contest Insert")
if r.Method != "POST" {
this.Err400(w, r, "Error", "Error Method to Insert contest")
return
}
this.Init(w, r)
args := this.ParseURL(r.URL.String())
Type := args["type"]
one := model.Contest{}
one.Title = r.FormValue("title")
one.Type = Type
year, err := strconv.Atoi(r.FormValue("startTimeYear"))
month, err := strconv.Atoi(r.FormValue("startTimeMonth"))
day, err := strconv.Atoi(r.FormValue("startTimeDay"))
hour, err := strconv.Atoi(r.FormValue("startTimeHour"))
min, err := strconv.Atoi(r.FormValue("startTimeMinute"))
start := time.Date(year, time.Month(month), day, hour, min, 0, 0, time.Local)
one.Start = start.Unix()
year, err = strconv.Atoi(r.FormValue("endTimeYear"))
month, err = strconv.Atoi(r.FormValue("endTimeMonth"))
day, err = strconv.Atoi(r.FormValue("endTimeDay"))
hour, err = strconv.Atoi(r.FormValue("endTimeHour"))
min, err = 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, "args error", 400)
return
}
switch r.FormValue("type") {
case "public":
one.Encrypt = config.EncryptPB
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", "", -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
}
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 //problemList 建议检查下problem是否存在,存在的将其在普通列表中不可见
contestModel := model.ContestModel{}
err = contestModel.Insert(one)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
http.Redirect(w, r, "/admin/contest?list/type?"+Type, http.StatusFound) //重定向到竞赛列表页
}