コード例 #1
0
func (this *ProblemController) SaveTestCase() {
	if !this.isLoggedIn() {
		this.Redirect("/user/login", 302)
		return
	}

	//Redirect if user doesnt hold editor rights
	uid := this.GetSession("id")
	user := models.User{Uid: uid.(int)}
	if !user.IsEditor() {
		this.Redirect("/", 302)
		return
	}

	pid := this.Ctx.Input.Param(":id")
	id, _ := strconv.Atoi(pid)

	timeout, _ := strconv.Atoi(this.GetString("timeout"))
	//remove string replace
	input := strings.Replace(this.GetString("input"), "\r", "", -1)
	output := strings.Replace(this.GetString("output"), "\r", "", -1)
	testcase := models.Testcases{
		Pid: id,
		//Input:   this.GetString("input"),
		//Output:  this.GetString("output"),
		Timeout: timeout,
	}
	testcase.Input = input
	testcase.Output = output
	done := testcase.Create()
	if done == true {
		this.Redirect("/problem/"+pid, 302)
	}
	this.Redirect("/problem/"+pid+"/addtest", 302)
}