public GuestBookModel AddGuestBook(GuestBookModel book) { Provider.Execute(@"insert into GuestBooks(GuestBookName) values(@szGuestBookName)" , new { szGuestBookName = book.GuestBookName } , CommandType.Text); return(book); }
public GuestBookModel DeleteGuestBook(GuestBookModel book) { Provider.Execute(@"delete from GuestBooks where GuestBookId=@nGuestBookId" , new { nGuestBookId = book.GuestBookId } , CommandType.Text); return(book); }
/// <summary> /// 获取留言,分页 /// </summary> /// <param name="number"></param> /// <param name="pagesize"></param> /// <returns></returns> public static List <GuestBookModel> GetGuestBookListByLang(int lang, int number, int pagesize) { string sql = "select top " + pagesize + " * from (select top " + number + " * from [T_GuestBook] where F_Lang=" + lang + " order by ID asc) order by ID desc"; List <GuestBookModel> list = new List <GuestBookModel>(); OleDbDataReader dr = AccessorDB.ExecuteReader(sql); GuestBookModel g = null; while (dr.Read()) { g = new GuestBookModel(); g.ID = Convert.ToInt32(dr["ID"]); g.F_Contacts = dr["F_Contacts"].ToString(); g.F_Way = dr["F_Way"].ToString(); g.F_Content = dr["F_Content"].ToString(); g.F_IP = dr["F_IP"].ToString(); g.F_Date = Convert.ToDateTime(dr["F_Date"]); g.F_Replay = dr["F_Replay"].ToString(); g.F_Lang = Convert.ToInt32(dr["F_Lang"]); list.Add(g); } dr.Close(); dr.Dispose(); return(list); }
protected void Page_Load(object sender, EventArgs e) { if (this.IsHttpPost) { if (Request.Form["op"].Trim().ToString() == "add") { code = Request.Form["txtcode"].Trim().ToString(); name = Request.Form["txtName"].Trim().ToString(); way = Request.Form["txtWay"].Trim().ToString(); content = Request.Form["txtContent"].Trim().ToString(); if (code != Request.Cookies["CheckCode"].Value.ToString()) { errostr = Request.Form["hint_9001"].ToString(); } else { GuestBookModel g = new GuestBookModel(); g.F_Contacts = VerifyTool.DeleteAll(name); g.F_Way = VerifyTool.DeleteAll(way); g.F_Content = VerifyTool.DeleteAll(content); g.F_IP = WebTools.GetRealIP(); g.F_Lang = lang; int res = EispGuestBookBLL.AddGuestBook(g); if (res > 0) { errostr = Request.Form["hint_1001"].ToString(); } } ((Label)Master.FindControl("ErroStr")).Text = errostr; } } }
//Reply protected void Button1_Click(object sender, EventArgs e) { id = BasePage.GetRequestId(Request.QueryString["id"]); GuestBookModel model = new GuestBookModel(); model.ReplyTime = DateTime.Now; model.Reply = txtReply.Text; model.Contents = txtContents.Text; model.id = id; if (txtVerific.Checked) { model.Verific = 0; } else { model.Verific = 1; } bool b = new GuestBookBll().Update1(model); if (b) { BasePage.JscriptPrint(Page, "修改/回复成功!", "GuestBook.aspx"); } }
public GuestBookModel GetDefaultGuestBook(Nullable <int> guestbookId) { int tempGuestBookId = 1; GuestBookModel book = new GuestBookModel(); book.GuestBookId = guestbookId.HasValue ? guestbookId.Value : tempGuestBookId; return(book); }
public ActionResult PostComment(Comment comment) { users user = Session["User"] as users; GuestBookModel gb = new GuestBookModel(); gb.PostComment(comment.CategoryID, user.userID, user.nickname, comment.comment); return(Json(comment.comment, JsonRequestBehavior.AllowGet)); }
public ActionResult ActivityList() { int cid = Convert.ToInt32(Request.QueryString["cid"]); ActivityListModel AListModel = new ActivityListModel(); GuestBookModel GModel = new GuestBookModel(); List <Activity> alist = AListModel.GetActivityList(cid); List <GuestBook> glist = GModel.ReadComment(cid); ViewData["AList"] = alist; ViewData["GList"] = glist; ViewData["CategoryID"] = cid; return(View()); }
/// <summary> /// 添加留言 /// </summary> /// <param name="g"></param> /// <returns></returns> public static int AddGuestBook(GuestBookModel g) { string sql = "insert into T_GuestBook(F_Contacts,F_Way,F_Content,F_IP,F_Lang) values(?,?,?,?,?)"; OleDbParameter[] parameter = new OleDbParameter[5]; parameter[0] = new OleDbParameter("@F_Contacts", OleDbType.VarChar, 50); parameter[1] = new OleDbParameter("@F_Way", OleDbType.VarChar, 50); parameter[2] = new OleDbParameter("@F_Content", OleDbType.VarChar, 200); parameter[3] = new OleDbParameter("@F_IP", OleDbType.VarChar, 50); parameter[4] = new OleDbParameter("@F_Lang", OleDbType.Integer); parameter[0].Value = g.F_Contacts; parameter[1].Value = g.F_Way; parameter[2].Value = g.F_Content; parameter[3].Value = g.F_IP; parameter[4].Value = g.F_Lang; return(AccessorDB.ExecuteNonQuery(sql, parameter)); }
public ViewResult Guestbook(int id) { GuestBookModel model = new GuestBookModel(); model.project = db.projects .Include("country") .Include("user") .Include("project_guestbook") .Include("tags") .Single(p => p.ProjectID == id); model.project_guestbook = new project_guestbook() { ProjectID = id, Date = DateTime.Now, UserID = CurrentUser != null ? CurrentUser.UserID : 0 }; ViewBag.UserID = CurrentUser != null ? CurrentUser.UserID : 0; return(View(model)); }
public async Task <List<GuestBookModel>> GetEntries (bool GetAll) { var L = new List<GuestBookModel>(); return await Task.Run(() => { var Query = @"select * from GuestBook where (IsVisible = @GetAll or @GetAll = 0) and IsDeleted = 0 order by Injected desc"; SetUpRawSQL(new { @GetAll = GetAll }, Query); var Reader = SqlCommand.ExecuteReader(); while(Reader.Read()) { var I = new GuestBookModel(); MapResultsToObject<GuestBookModel>(ref Reader, ref I); L.Add(I); } return L; }); }
public async Task AddEntry (GuestBookModel GuestBook) { try { await Task.Run(() => { GuestBook.Message = Regex.Replace(GuestBook.Message, @"\p{Cs}", ""); var Query = @"insert into GuestBook (Message, Email, Name) values (@Message, @Email, @Name)"; var Params = new { @Message = GuestBook.Message, @Email = GuestBook.Email, @Name = GuestBook.Name }; SetUpRawSQL(Params, Query); SqlCommand.ExecuteNonQuery(); }); } catch (Exception Ex) { } }
public void UpdateGuestBook(GuestBookModel book) { Provider.Execute(@"update GuestBooks set GuestBookName=@szGuestBookName where GuestBookId=@nGuestBookId" , new { szGuestBookName = book.GuestBookName, nGuestBookId = book.GuestBookId } , CommandType.Text); }
/// <summary> /// 添加留言 /// </summary> /// <param name="g"></param> /// <returns></returns> public static int AddGuestBook(GuestBookModel g) { return(EispGuestBookDAL.AddGuestBook(g)); }
public ActionResult GuestbookCreate(project_guestbook model) { GuestBookModel Model = new GuestBookModel(); project project = db.projects.Single(p => p.ProjectID == model.ProjectID); model.UserID = CurrentUser.UserID; model.Date = DateTime.Now; ModelState.Remove("UserID"); ModelState.Add("UserID", new ModelState()); ModelState.SetModelValue("UserID", new ValueProviderResult(CurrentUser.UserID, CurrentUser.UserID.ToString(), null)); ModelState.Remove("Date"); ModelState.Add("Date", new ModelState()); ModelState.SetModelValue("Date", new ValueProviderResult(DateTime.Now, DateTime.Now.ToString(), null)); if (Request.Files != null && Request.Files.Count > 0) { foreach (string keyname in Request.Files) { HttpPostedFileBase file = Request.Files[keyname]; if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName)) { //file upload string ext = Path.GetExtension(file.FileName).ToLower(); if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla") { ModelState.AddModelError(keyname, "Invalid file type"); } else { try { using (Image tmp = Image.FromStream(file.InputStream)) { //resize+crop int width = int.Parse(ConfigurationManager.AppSettings["Image_Guestbook_Width"]); int height = int.Parse(ConfigurationManager.AppSettings["Image_Guestbook_Height"]); string name = getTimestamp() + ".jpg"; string filepath = string.Format("projects/{0}/guestbook/{1}", model.ProjectID, file.FileName); string address = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath; //send using (Image resized = tmp.GetResizedImage(width, height, true)) { var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath); using (MemoryStream buffer = new MemoryStream()) { resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80)); request.InputStream = buffer; AmazonS3Client s3Client = new AmazonS3Client(); s3Client.PutObject(request); } } ModelState.Remove(keyname); ModelState.Add(keyname, new ModelState()); ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null)); model.Picture = address; //return view with model Model.project = db.projects .Include("country") .Include("user") .Include("project_guestbook") .Include("tags") .Single(p => p.ProjectID == model.ProjectID); Model.project_guestbook = model; ViewBag.UserID = CurrentUser != null ? CurrentUser.UserID : 0; return(View("Guestbook", Model)); } } catch (Exception ex) { ModelState.AddModelError(keyname, "Upload error: " + ex.Message); } } } } } if (ModelState.IsValid) { Validator validator = new Validator(ConfigurationManager.AppSettings["Akismet_Key"]); bool isspam = validator.IsSpam(new Comment() { comment_author_email = CurrentUser.Email, blog = ConfigurationManager.AppSettings["Akismet_Url"], comment_author = CurrentUser.UserName, comment_content = model.Text, user_agent = Request.UserAgent, user_ip = Request.UserHostAddress, referrer = Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : "", comment_type = "comment" }); if (isspam) { string spam = string.Format("From: {0}\r\nProject: {1}\r\nProjectID: {2}\r\n\r\nGuestbook SPAM TEXT: {3}\r\n\r\nThis post was not saved.", CurrentUser.Email, project.Title, model.ProjectID, model.Text); //SendMailAwsAdmin("New Guestbook Post SPAM: " + project.Title, spam); LogStuff("SPAM", DateTime.Now, spam); } else { project.project_guestbook.Add(model); db.SaveChanges(); string body = string.Format("From: {0}\r\nProject: {1}\r\nProjectID: {2}\r\n\r\nGuestbook Post: {3}", CurrentUser.Email, project.Title, model.ProjectID, model.Text); SendMailAws(project.user.Email, "New Guestbook Post: " + project.Title, body); SendMailAwsAdmin("New Guestbook Post: " + project.Title, body); //return view with model return(RedirectToAction("Guestbook", new{ id = project.ProjectID, ts = DateTime.Now.Ticks.ToString() })); } } //return view with model Model.project = db.projects .Include("country") .Include("user") .Include("project_guestbook") .Include("tags") .Single(p => p.ProjectID == model.ProjectID); Model.project_guestbook = model; ViewBag.UserID = CurrentUser != null ? CurrentUser.UserID : 0; return(View("Guestbook", Model)); }