Esempio n. 1
0
File: user.go Progetto: zbzzbd/beego
func (c *UserController) Edit() {
	c.GetViewData()

	uid := c.Ctx.Input.Param(":id")
	id, _ := strconv.Atoi(uid)
	user, err := user.NewUserWithId(uint(id))

	if err != nil {
		c.Data["error"] = "用户不存在"
	}

	c.Data["user"] = user.GetUser()

	c.TplNames = "users/edit.tpl"
}
Esempio n. 2
0
File: user.go Progetto: zbzzbd/beego
func (c *UserController) Delete() {
	uid := c.Ctx.Input.Param(":id")
	id, _ := strconv.Atoi(uid)
	user, err := user.NewUserWithId(uint(id))
	if err != nil {
		c.SetJsonResponse("error", err.Error())
	} else {
		saveUser := user.GetUser()
		saveUser.Deleted = time.Now()
		err = saveUser.Update("deleted")
	}

	if err != nil {
		c.SetJsonResponse("error", err.Error())
	}

	c.GetJsonResponse().ServeJson()
}
Esempio n. 3
0
func (c *ProjectController) HandleFilter() map[string]interface{} {
	filter := make(map[string]interface{})
	filter["limit"] = 10
	filter["offset"] = 0
	id := c.GetString("project_name")
	if id != "" {
		filter["id"] = id
		p, _ := project.NewProject().GetOne(id)
		c.Data["project_default"] = p.GetModelProject()
	}
	bussiness_user := c.GetString("bussiness_user")
	if bussiness_user != "" {
		filter["bussiness_user_id"] = bussiness_user
		user_id, _ := strconv.Atoi(bussiness_user)
		user, _ := user.NewUserWithId(uint(user_id))
		c.Data["bussiness_user_default"] = user.GetUser()
	}

	progress_filter := c.GetString("progress")
	if progress_filter != "" {
		filter["progress"] = progress_filter
		progress, _ := project.NewProgress().GetProgressById(progress_filter)
		c.Data["progress_default"] = progress.GetModelProgress()
	}

	start_date := c.GetString("start_date")
	if start_date != "" {
		filter["start_date"] = start_date
		c.Data["start_date_default"] = start_date
	}

	end_date := c.GetString("end_date")
	if end_date != "" {
		filter["end_date"] = end_date
		c.Data["end_date_default"] = end_date
	}

	p, _ := c.GetInt("p")
	if p > 1 {
		filter["offset"] = (p - 1) * filter["limit"].(int)
	}
	return filter
}
Esempio n. 4
0
File: user.go Progetto: zbzzbd/beego
func (c *UserController) PostEdit() {
	uid, _ := c.GetInt("id")
	companyId, _ := c.GetInt("company")
	user, err := user.NewUserWithId(uint(uid))
	saveUser := user.GetUser()
	if err != nil {
		c.SetJsonResponse("error", err.Error())
	} else {
		saveUser.Company = &models.Company{Id: uint(companyId)}
		saveUser.Roles = c.GetString("role")
		saveUser.Name = c.GetString("name")
		saveUser.Email = c.GetString("email")
		saveUser.Mobile = c.GetString("mobile")
		err = saveUser.Update("company_id", "Roles", "name", "email", "mobile")
	}

	if err != nil {
		c.SetJsonResponse("error", err.Error())
	}

	c.GetJsonResponse().ServeJson()
}