func UpdatePlant(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) { id, _ := strconv.ParseInt(params["id"], 10, 64) plant := entity.NewPlant() plant.Populate(getPlantMap(r, params["id"])) val, errors := validation.ValidateDefaultEntity(plant, db, PLANT) if val { _, err := repository.UpdatePlant(plant, db, params["id"]) if err != nil { log.Println(err) sessionMessages.AddDanger("Failed to update plant.") } else { sessionMessages.AddSuccess("Successfully update plant.") updatePopularNames(db, id, PLANT, plant.GetPopularNames().GetValues()) createMedia(r, mediaManager, db, sessionMessages, PLANT, id) } ren.Redirect("/plant/") } else { for k, msg := range errors { sessionMessages.AddDanger(k + ": " + msg) } ren.Redirect("/plant/" + params["id"]) } }
func UpdateInvertebrate(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) { id, _ := strconv.ParseInt(params["id"], 10, 64) invertebrate := entity.NewInvertebrate() invertebrate.Populate(getInvertebrateMap(r, params["id"])) val, errors := validation.ValidateDefaultEntity(invertebrate, db, INVERTEBRATE) if val { _, err := repository.UpdateInvertebrate(invertebrate, db, params["id"]) if err != nil { log.Println(err) sessionMessages.AddDanger("Failed to upload invertebrate.") } else { sessionMessages.AddSuccess("Successfully upload invertebrate.") updatePopularNames(db, id, INVERTEBRATE, invertebrate.GetPopularNames().GetValues()) createMedia(r, mediaManager, db, sessionMessages, INVERTEBRATE, id) } ren.Redirect("/invertebrate") } else { for k, msg := range errors { sessionMessages.AddDanger(k + ": " + msg) } ren.Redirect("/invertebrate/" + params["id"]) } }
func CreatePlant(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) { plant := entity.NewPlant() plant.Populate(getPlantMap(r, "")) val, errors := validation.ValidateDefaultEntity(plant, db, PLANT) if val { res, err := repository.InsertPlant(plant, db) if err != nil { log.Println(err) sessionMessages.AddDanger("Failed to create plant.") } else { sessionMessages.AddSuccess("Successfully created plant.") id, _ := res.LastInsertId() insertPopularNames(db, id, PLANT, plant.GetPopularNames().GetValues()) createMedia(r, mediaManager, db, sessionMessages, PLANT, id) } ren.Redirect("/plant") } else { for k, msg := range errors { sessionMessages.AddDanger(k + ": " + msg) } ren.Redirect("/plant/new") } }
func CreateInvertebrate(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) { invertebrate := entity.NewInvertebrate() invertebrate.Populate(getInvertebrateMap(r, "")) val, errors := validation.ValidateDefaultEntity(invertebrate, db, INVERTEBRATE) if val { res, err := repository.InsertInvertebrate(invertebrate, db) if err != nil { log.Println(err) sessionMessages.AddDanger("Failed to create invertebrate.") } else { sessionMessages.AddSuccess("Successfully created invertebrate.") id, _ := res.LastInsertId() insertPopularNames(db, id, INVERTEBRATE, invertebrate.GetPopularNames().GetValues()) createMedia(r, mediaManager, db, sessionMessages, INVERTEBRATE, id) } ren.Redirect("/invertebrate") } else { for k, msg := range errors { sessionMessages.AddDanger(k + ": " + msg) } ren.Redirect("/invertebrate/new") } }