Beispiel #1
0
func DeleteComponent(ren render.Render, mediaManager *media.Manager, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
	var err error

	id, _ := strconv.ParseInt(params["id"], 10, 64)

	media_list := getMediaList(db, COMPONENT, id)

	if media_list != nil {
		_, errors := DeleteEntityMedia(*media_list, mediaManager, db)

		for _, err := range errors {
			log.Println(err)
		}

		_, err = repository.DeleteEntityMedia(db, id, COMPONENT)
		if err != nil {
			log.Println(err)
			sessionMessages.AddDanger("Failed to delete media for component.")
		}
	}

	_, err = repository.DeleteComponent(db, id)
	if err != nil {
		log.Println(err)
		sessionMessages.AddDanger("Failed to delete component.")
	} else {
		sessionMessages.AddSuccess("Successfully deleted component.")
	}

	ren.Redirect("/component")
}
Beispiel #2
0
func DeleteInvertebrate(ren render.Render, mediaManager *media.Manager, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
	var err error

	id, _ := strconv.ParseInt(params["id"], 10, 64)

	media_list := getMediaList(db, INVERTEBRATE, id)

	if media_list != nil {
		_, errors := DeleteEntityMedia(*media_list, mediaManager, db)

		for _, err := range errors {
			log.Println(err)
		}

		_, err = repository.DeleteEntityMedia(db, id, INVERTEBRATE)
		if err != nil {
			log.Println(err)
			sessionMessages.AddDanger("Failed to delete media for invertebrate.")
		}
	}

	_, err = repository.DeleteEntityNames(db, id, INVERTEBRATE)
	if err != nil {
		log.Println(err)
		sessionMessages.AddDanger("Failed to delete popular names for invertabrate.")
	}

	_, err = repository.DeleteInvertebrate(db, id)
	if err != nil {
		log.Println(err)
		sessionMessages.AddDanger("Failed to delete invertebrate.")
	} else {
		sessionMessages.AddSuccess("Successfully deleted invertebrate.")
	}

	ren.Redirect("/invertebrate")
}