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 }
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 }
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 }