Пример #1
0
	case "existing":
		if ctx.Request.FormValue("location_id") == "" {
			errorString = "No location was selected"
		} else {
			locationId = ctx.Request.FormValue("location_id")
		}
		break
	case "new":
		if ctx.Request.FormValue("country") != "" {
			locationId = models2.GenerateId(gocbweb.LOCTYPE)
			location := models2.Location{
				City:    ctx.Request.FormValue("city"),
				State:   ctx.Request.FormValue("state"),
				Country: ctx.Request.FormValue("country")}
			doc := models2.MyDoc{Id: locationId, Type: gocbweb.LOCTYPE, Value: location}
			added, err := models2.AddDoc(doc, gocbweb.LOCTYPE)
			if err != nil {
				errorString = "error on location add: " + err.Error()
			}
			if added == false {
				errorString = "Duplicate id: " + locationId
			}
		} else {
			errorString = "Country is required"
		}
		break
	}
	if errorString == "no errors" {
		var albums []models2.Album
		id := models2.GenerateId(gocbweb.BANDTYPE)
		band := models2.Band{Name: name, LocationId: locationId, Albums: albums}
Пример #2
0
	errorString := "no errors"
	switch genretype {
	case "existing":
		if ctx.Request.FormValue("genre_id") == "" {
			errorString = "No genre was selected"
		} else {
			genreId = ctx.Request.FormValue("genre_id")
		}
		break
	case "new":
		if ctx.Request.FormValue("genre_name") != "" {
			genreId = models2.GenerateId(gocbweb.GENRETYPE)
			genre := models2.Genre{Name: ctx.Request.FormValue("genre_name")}
			doc := models2.MyDoc{Id: genreId, Type: gocbweb.GENRETYPE,
				Value: genre}
			added, err := models2.AddDoc(doc, gocbweb.GENRETYPE)
			if err != nil {
				errorString = fmt.Sprintf("Genre: %s", err.Error())
			}
			if added == false {
				errorString = "Duplicate id: " + genreId
			}
		} else {
			errorString = "Genre name is required"
		}
		break
	}

	if errorString == "no errors" {
		bandId := rawId
		bandDoc := models2.GetDoc(bandId)