package message

import "spaceofcheng/services/models/model"

// GetCmsCase 获取项目列表
func (c *MessageController) GetCmsCase() {
	caseids := c.GetString("caseid")
	if caseids == "" {
		cases := c.Context.Get("cases").([]model.SysUserCase)
		caseids = c.GetCaseIDs(cases)
	}
	page, _ := c.GetInt("page")
	pageSize, _ := c.GetInt("pagesize")
	name := c.GetString("name")
	list, err := c.dao.GetCmsCasesList(name, caseids, page, pageSize)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(list)
}

// GetCmsCaseList 项目列表
func (c *MessageController) GetCmsCaseList() {
	orgid := c.GetString("orgid")
	list, err := c.dao.GetCmsCaseByOrg(orgid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(list)
}

// GetCmsCaseByID 获取明细
func (c *MessageController) GetCmsCaseByID() {
	cmscaseid := c.GetString(":cmscaseid")
	cmscase, err := c.dao.GetCmsCasesByID(cmscaseid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(cmscase)
}

// SaveCmsCase 保存项目
func (c *MessageController) SaveCmsCase() {
	cmscase := model.TaCmsCase{}
	if err := c.ParseForm(&cmscase); err != nil {
		c.ResponseError(err)
	}
	courseids := c.GetString("courseids")
	imgs := c.GetString("imgs")
	detailimgs := c.GetString("detailimgs")
	newInfo, err := c.dao.SaveCmsCase(cmscase, courseids, imgs, detailimgs)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON(newInfo)
}

// DelCmsCase 删除项目
func (c *MessageController) DelCmsCase() {
	cmscaseid := c.GetString(":cmscaseid")
	err := c.dao.DelCmsCase(cmscaseid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("删除成功！")
}

// CmsCaseShow 前台展示
func (c *MessageController) CmsCaseShow() {
	cmscaseid := c.GetString(":cmscaseid")
	err := c.dao.CmsCaseShow(cmscaseid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("操作成功！")
}

// CmsCaseHide 前台隐藏
func (c *MessageController) CmsCaseHide() {
	cmscaseid := c.GetString(":cmscaseid")
	err := c.dao.CmsCaseHide(cmscaseid)
	if err != nil {
		c.ResponseError(err)
	}
	c.ResponseJSON("操作成功！")
}
