func CreateSubject(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	redirected, _ := ensureLoggedIn(w, r)
	if redirected {
		return
	}

	// Parse and validate.
	short, name, splitClass := parseSubjectData(r)
	valid, message := validateSubjectData(short, name, splitClass)
	if valid {
		subject := model.Subject{Short: short}
		if subject.Exists() {
			message = fmt.Sprintf("Es gibt bereits ein Fach mit dem Kürzel %s.", short)
			valid = false
		}
	}

	// Render message if the data is not valid.
	if !valid {
		template, err := template.ParseFiles("templates/base.html", "templates/subject/new.html")
		if err != nil {
			log.Printf("error: %v\n", err)
		}

		err = template.Execute(w, simpleMessage(message, false))
		if err != nil {
			log.Printf("error: %v\n", err)
		}
		return
	}

	// Create the subject.
	subject := model.Subject{Short: short, Name: name, SplitClass: splitClass}
	subject.Create()

	unknown := model.UnknownSubject{Short: short}
	unknown.Delete()

	// Render all subjects
	message = fmt.Sprintf("%s wurde gespeichert.", name)
	showSubjects(w, r, message)
}
// CreateSubject creates a new subject and serves the list of all subjects.
CreateSubject creates a new subject and serves the list of all subjects.
// CreateSubject creates a new subject and serves the list of all subjects .
func CreateSubject(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	redirected, _ := ensureLoggedIn(w, r)
	if redirected {
		return
	}
	short, name, splitClass := parseSubjectData(r)
	valid, message := validateSubjectData(short, name, splitClass)
	if valid {
		subject := model.Subject{Short: short}
		if subject.Exists() {
			message = fmt.Sprintf("Es gibt bereits ein Fach mit dem Kürzel %s.", short)
			valid = false
		}
	}
	if !valid {
		template, err := template.ParseFiles("templates/base.html", "templates/subject/new.html")
		if err != nil {
			log.Printf("error: %v\n", err)
		}
		err = template.Execute(w, simpleMessage(message, false))
		if err != nil {
			log.Printf("error: %v\n", err)
		}
		return
	}
	subject := model.Subject{Short: short, Name: name, SplitClass: splitClass}
	subject.Create()
	unknown := model.UnknownSubject{Short: short}
	unknown.Delete()
	message = fmt.Sprintf("%s wurde gespeichert.", name)
	showSubjects(w, r, message)
}
func CreateSubject ( w http . ResponseWriter , r * http . Request , _ httprouter . Params ) { redirected , _ := ensureLoggedIn ( w , r ) if redirected { return } short , name , splitClass := parseSubjectData ( r ) valid , message := validateSubjectData ( short , name , splitClass ) if valid { subject := model . Subject { Short : short } if subject . Exists ( ) { message = fmt . Sprintf ( " , hort) valid = false } } if ! valid { template , err := template . ParseFiles ( " " , " " ) if err != nil { log . Printf ( " \n " , err ) } err = template . Execute ( w , simpleMessage ( message , false ) ) if err != nil { log . Printf ( " \n " , err ) } return } subject := model . Subject { Short : short , Name : name , SplitClass : splitClass } subject . Create ( ) unknown := model . UnknownSubject { Short : short } unknown . Delete ( ) message = fmt . Sprintf ( " " , name ) showSubjects ( w , r , message ) }
CreateSubject creates a new subject and serves the list of all subjects.
CreateSubject creates a new subject and serves the list of all subjects .
// Parse and validate. // Render message if the data is not valid. // Create the subject. // Render all subjects