示例#1
0
文件: blog.go 项目: HYQMartin/star
func NDel(b *NewemployeeBlog) error {
	num, err := Blogs().Filter("Id", b.Id).Delete()
	if err != nil {
		return err
	}

	if num > 0 {
		g.NBlogCacheDel(fmt.Sprintf("article_ids_of_%d", b.CatalogId))
		NBlogContents().Filter("Id", b.BlogContentId).Delete()
	}

	return nil
}
示例#2
0
文件: blog.go 项目: HYQMartin/star
func NUpdate(b *NewemployeeBlog, content string) error {
	if b.Id == 0 {
		return fmt.Errorf("primary key:id not set")
	}

	bc := NReadBlogContent(b)
	if content != "" && bc.Content != content {
		bc.Content = content
		_, e := orm.NewOrm().Update(bc)
		if e != nil {
			return e
		}
		b.BlogContentLastUpdate = time.Now().Unix()
	}

	_, err := orm.NewOrm().Update(b)
	if err == nil {
		g.NBlogCacheDel(fmt.Sprintf("%d", b.Id))
	}
	return err
}
示例#3
0
文件: blog.go 项目: HYQMartin/star
func NSave(this *NewemployeeBlog, blogContent string) (int64, error) {
	if NIdentExists(this.Ident) {
		return 0, fmt.Errorf("blog english identity exists")
	}

	bc := &NewemployeeBlogContent{Content: blogContent}
	or := orm.NewOrm()
	blogContentId, e := or.Insert(bc)
	if e != nil {
		return 0, e
	}

	this.BlogContentId = blogContentId
	this.BlogContentLastUpdate = time.Now().Unix()

	id, err := or.Insert(this)
	if err == nil {
		g.NBlogCacheDel(fmt.Sprintf("article_ids_of_%d", this.CatalogId))
	}

	return id, err
}