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) fmt.Println(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.RenderError(err) } newEmail := new(models.EmailObj) newEmail.Email = message.Email dao.InsertEmail(newEmail) 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() fmt.Println(c.Validation) 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) } newEmail := new(models.EmailObj) newEmail.Email = blog.Email dao.InsertEmail(newEmail) return c.Redirect(App.Index) }
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/%d", id, rcnt) } err = dao.InsertComment(comment) if err != nil { c.Response.Status = 500 return c.RenderError(err) } blog.CommentCnt++ dao.UpdateBlogById(id, blog) newEmail := new(models.EmailObj) newEmail.Email = comment.Email dao.InsertEmail(newEmail) return c.Redirect("/bloginfor/%s/%d", id, rcnt) }