Exemple #1
0
	ctx.ViewData["Title"] = "Verifying Band"
	name := ctx.Request.FormValue("name")
	loctype := ctx.Request.FormValue("loctype")
	var locationId string // for Couchbase
	errorString := "no errors"
	switch loctype {
	case "existing":
		if ctx.Request.FormValue("location_id") == "" {
			errorString = "No location selected"
		} else {
			locationId = models.ConvertToId(ctx.Request.FormValue("location_id"))
		}
		break
	case "new":
		if ctx.Request.FormValue("country") != "" {
			locationId = models.GenerateId("location")
			location := models.Location{Id: locationId, City: ctx.Request.FormValue("city"),
				State: ctx.Request.FormValue("state"), Country: ctx.Request.FormValue("country")}
			err := location.Add()
			if err != nil {
				errorString = fmt.Sprintf("Location: %s", err.Error())
			}
		} else {
			errorString = "Country is required"
		}
		break
	}
	if errorString == "no errors" {
		albums := []models.Album{}
		id := models.GenerateId("band")
		band := models.Band{Id: id, Name: name, LocationId: locationId, Albums: albums}
Exemple #2
0
	yearString := ctx.Request.FormValue("year")
	year, _ := strconv.Atoi(yearString)
	genretype := ctx.Request.FormValue("genretype")
	var genreId string // for Couchbase
	errorString := "no errors"
	switch genretype {
	case "existing":
		if ctx.Request.FormValue("genre_id") == "" {
			errorString = "No genre selected"
		} else {
			genreId = models.ConvertToId(ctx.Request.FormValue("genre_id"))
		}
		break
	case "new":
		if ctx.Request.FormValue("genre_name") != "" {
			genreId = models.GenerateId("genre")
			genre := models.Genre{Id: genreId, Name: ctx.Request.FormValue("genre_name")}
			err := genre.Add()
			if err != nil {
				errorString = fmt.Sprintf("Genre: %s", err.Error())
			}
		} else {
			errorString = "Genre name is required"
		}
		break
	}
	if errorString == "no errors" {
		bandId := models.ConvertToId(rawId)
		band := models.GetBand(bandId)
		album := models.Album{Name: name, Year: year, GenreId: genreId}
		err := band.AddAlbum(album)