func (c WMessage) Putup(message *models.Message) revel.Result { message.Email = strings.TrimSpace(message.Email) message.Url = strings.TrimSpace(message.Url) message.Content = strings.TrimSpace(message.Content) message.QQ = strings.TrimSpace(message.QQ) message.Validate(c.Validation) if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() c.Flash.Error("Errs:The email and the content should not be null, or the maxsize of email is 50.") return c.Redirect(App.Message) } dao, err := models.NewDao() if err != nil { c.Response.Status = 500 return c.RenderError(err) } defer dao.Close() err = dao.InsertMessage(message) if err != nil { c.Response.Status = 500 return c.Redirect(App.Message) } if !dao.IsEmailExists(message.Email) { dao.InsertEmail(&models.Email{message.Email, time.Now()}) } return c.Redirect(App.Message) }
func (c WBlog) Putup(blog *models.Blog) revel.Result { blog.Title = strings.TrimSpace(blog.Title) blog.Email = strings.TrimSpace(blog.Email) blog.Subject = strings.TrimSpace(blog.Subject) blog.Validate(c.Validation) if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(App.WBlog) } dao, err := models.NewDao() if err != nil { c.Response.Status = 500 return c.RenderError(err) } defer dao.Close() err = dao.CreateBlog(blog) if err != nil { c.Response.Status = 500 return c.RenderError(err) } if !dao.IsEmailExists(blog.Email) { dao.InsertEmail(&models.Email{blog.Email, time.Now()}) } return c.Redirect(App.Index) }
func (c App) Email() revel.Result { dao, err := models.NewDao() if err != nil { c.Response.Status = 500 c.RenderError(err) } defer dao.Close() emails := dao.FindEmails() return c.Render(emails) }
func (c App) Message() revel.Result { dao, err := models.NewDao() if err != nil { c.Response.Status = 500 return c.RenderError(err) } defer dao.Close() messages := dao.FindAllMessages() return c.Render(messages) }
func (c App) Index() revel.Result { dao, err := models.NewDao() if err != nil { c.Response.Status = 500 return c.RenderError(err) } defer dao.Close() blogs := dao.FindBlogs() now := time.Now().Add(-1 * time.Hour) recentCnt := dao.FindBlogsByDate(now) return c.Render(blogs, recentCnt) }
func (c App) History() revel.Result { dao, err := models.NewDao() if err != nil { c.Response.Status = 500 return c.RenderError(err) } defer dao.Close() dao.CreateAllHistory() historys := dao.FindHistory() for i, _ := range historys { historys[i].Blogs = dao.FindBlogsByYear(historys[i].Year) } return c.Render(historys) }
func (c App) BlogInfor(id string, rcnt int) revel.Result { dao, err := models.NewDao() if err != nil { c.Response.Status = 500 return c.RenderError(err) } defer dao.Close() blog := dao.FindBlogById(id) if blog.ReadCnt == rcnt { blog.ReadCnt = rcnt + 1 dao.UpdateBlogById(id, blog) } comments := dao.FindCommentsByBlogId(blog.Id) if len(comments) == 0 && blog.CommentCnt != 0 { blog.CommentCnt = 0 dao.UpdateBlogById(id, blog) } else if len(comments) != blog.CommentCnt { blog.CommentCnt = len(comments) dao.UpdateBlogById(id, blog) } return c.Render(blog, rcnt, comments) }
func (c WComment) Docomment(id string, rcnt int, comment *models.Comment) revel.Result { if len(id) == 0 { return c.Redirect(App.Index) } dao, err := models.NewDao() if err != nil { c.Response.Status = 500 return c.Redirect(App.Index) } defer dao.Close() blog := dao.FindBlogById(id) if blog == nil { return c.Redirect(App.Index) } comment.BlogId = blog.Id comment.Content = strings.TrimSpace(comment.Content) comment.Email = strings.TrimSpace(comment.Email) comment.Validate(c.Validation) if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() c.Flash.Error("Errs: The email and the content should not be null, or the maxsize of email is 50.") return c.Redirect("/bloginfor/%s/%s", id, rcnt) } err = dao.InsertComment(comment) if err != nil { c.Response.Status = 500 return c.RenderError(err) } blog.CommentCnt++ dao.UpdateBlogById(id, blog) if !dao.IsEmailExists(comment.Email) { dao.InsertEmail(&models.Email{comment.Email, time.Now()}) } return c.Redirect("/bloginfor/%s/%d", id, rcnt) }