Example #1
0
func (c Cmds) Operate(agentId string, id string, cmd models.Cmd) revel.Result {
	if c.IsGet() {
		if id != "" {
			if cmd = models.SelectCmdOneByCmdId(id); cmd.CmdId == "" {
				return c.ErrDataBase(MsgSeleteError)
			}
			return c.Render(cmd, agentId)
		}
		return c.Render(agentId)
	} else {
		if agentId == "" {
			return c.ErrInputData(errInputData)
		}
		cmd.AgentId = agentId
		if cmd.CmdId != "" {
			cmd.ValidateUpdate(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(cmd, agentId)
			}
			if !models.UpdateOneCmd(&cmd) {
				return c.ErrDataBase(MsgUpdateError)
			}
		} else {
			cmd.ValidateInsert(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(cmd, agentId)
			}
			if err := models.DBMap().Insert(&cmd); err != nil {
				return c.ErrDataBase(MsgInsertError)
			}
		}
		return c.Redirect(routes.Agents.List())
	}
}
Example #2
0
func (c Servers) Operate(id string, server models.Server) revel.Result {
	if c.IsGet() {
		if id != "" {
			if server = models.SelectServerOneByServerId(id); server.ServerId == "" {
				return c.ErrDataBase(MsgSeleteError)
			}
			return c.Render(server)
		}
		return c.Render()
	} else {
		if server.ServerId != "" {
			server.ValidateUpdate(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(server)
			}
			if !models.UpdateServerOne(&server) {
				return c.ErrDataBase(MsgUpdateError)
			}
		} else {
			server.UserId = c.SessionGetUser().UserId
			server.ValidateInsert(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(server)
			}
			if err := models.DBMap().Insert(&server); err != nil {
				return c.ErrDataBase(MsgInsertError)
			}
		}
		return c.Redirect(routes.Servers.Index(server.ServerId))
	}
}
Example #3
0
func (c Tasks) TaskOperate(id string, task models.Task) revel.Result {
	group := models.SelectTaskGroupListByUserId(c.SessionGetUser().UserId)
	if c.IsGet() {
		if id != "" {
			if task = models.SelectTaskOneById(id); task.TaskId == "" {
				return c.ErrDataBase(MsgSeleteError)
			}
			return c.Render(task, group)
		}
		return c.Render(group)
	} else {
		if task.TaskId != "" {
			task.ValidateUpdate(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(task, group)
			}
			if !models.UpdateTaskOne(&task) {
				return c.ErrDataBase(MsgUpdateError)
			}
		} else {
			task.UserId = c.SessionGetUser().UserId
			task.ValidateInsert(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(task, group)
			}
			if err := models.DBMap().Insert(&task); err != nil {
				return c.ErrDataBase(MsgInsertError)
			}
		}
		return c.Redirect(routes.Tasks.TaskList(task.GroupId))
	}
}
Example #4
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())
	}
}