Beispiel #1
0
func (c Agents) SshOne(agentId string) revel.Result {
	agent := models.SelectAgentOneByAgentId(agentId)
	if agent.AgentId == "" {
		return c.ErrDataBase(MsgSeleteError)
	}
	return c.Render(agent)
}
Beispiel #2
0
func (c Agents) Operate(id string, agent models.Agent) revel.Result {
	if c.IsGet() {
		if id != "" {
			if agent = models.SelectAgentOneByAgentId(id); agent.AgentId == "" {
				return c.ErrDataBase(MsgSeleteError)
			}
			return c.Render(agent)
		}
		return c.Render()
	} else {
		if agent.AgentId != "" {
			agent.ValidateUpdate(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(agent)
			}
			if !models.UpdateOneAgent(&agent) {
				return c.ErrDataBase(MsgUpdateError)
			}
		} else {
			agent.UserId = c.SessionGetUser().UserId
			agent.ValidateInsert(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(agent)
			}
			if err := models.DBMap().Insert(&agent); err != nil {
				return c.ErrDataBase(MsgInsertError)
			}
		}
		return c.Redirect(routes.Agents.List())
	}
}