Advertisement
gilmarpalega

Untitled

Dec 15th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.72 KB | None | 0 0
  1. /*
  2.  controllers/tarefas.go
  3.  ----------------------
  4. */
  5. func (c *TarefasController) Insert() {
  6.     var o models.Tarefas
  7.  
  8.     ret := retorno
  9.  
  10.     if err := c.ParseForm(&o); err != nil {
  11.         ret["erros"] = 1
  12.         ret["msg"] = "Houve um erro " + err.Error()
  13.     }
  14.  
  15.     if id, err := models.AddTarefas(&o); err == nil {
  16.         o.Id = int(id)
  17.         aud.Audit (&o, o.TableName(), 0, c.Logged_user_id())
  18.  
  19.         ret["msg"] = "Registro cadastrado com sucesso"
  20.     } else {
  21.         ret["erros"] = 1
  22.         ret["msg"] = err.Error()
  23.     }
  24.  
  25.     c.Data["json"] = ret
  26.     c.ServeJson()
  27.     c.Ctx.Redirect(302, "/tarefas")
  28. }
  29.  
  30. /*
  31. models/tarefa.go
  32. ----------------------
  33. */
  34. func AddTarefas(m *Tarefas) (id int64, err error) {
  35.     o := orm.NewOrm()
  36.     id, err = o.Insert(m)
  37.     return
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement