// turn to the inform Page, which is not used in the program // @param String reviewerId // @return the inform page public ActionResult Inform(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InformModel informModel = new InformModel(); informModel.AuthorId = id; return(View(informModel)); }
public async Task <ActionResult> Inform(InformModel model) { AspNetUser author = db.AspNetUsers.Find(model.AuthorId); if (ModelState.IsValid) { var body = "<p>Email From: {0} ({1})Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress(author.Email)); message.From = new MailAddress("*****@*****.**"); message.Subject = model.Subject; message.Body = string.Format(body, message.From, message.From, model.Message); message.IsBodyHtml = true; HttpPostedFileBase postedFile = Request.Files["upload"]; model.Upload = postedFile; if (model.Upload != null && model.Upload.ContentLength > 0) { message.Attachments.Add(new Attachment(model.Upload.InputStream, System.IO.Path.GetFileName(model.Upload.FileName))); } using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // send email account Password = "" }; smtp.Credentials = credential; smtp.Host = "smtp.monash.edu.au"; //mail server //smtp.Port = 587; // smtp.EnableSsl = true; // smtp.DeliveryMethod = SmtpDeliveryMethod.Network; await smtp.SendMailAsync(message); ViewBag.SUCCESS = true; } } return(View(model)); }
// GET: Inform public async Task <ActionResult> Index(int id) { using (ConnectionMultiplexer conn = await ConnectionMultiplexer.ConnectAsync("127.0.0.1:6379")) { //默认是访问db0数据库,可以通过方法参数指定数字访问不同的数据库 IDatabase db = conn.GetDatabase(); //以ip和新闻的id为key string hasClickKey = Inform_Prefix + Request.UserHostAddress + "_" + id; //如果之前这个ip给这篇文章贡献过点击量,则不重复计算点击量 if (db.KeyExists(hasClickKey) == false) { await db.StringIncrementAsync(Inform_Prefix + id, 1); //记录一下这个ip给这篇文章共享的点击量,有效期为1天 db.StringSet(hasClickKey, "a", TimeSpan.FromDays(1)); } RedisValue clickCount = await db.StringGetAsync(Inform_Prefix + id); InformModel model = new InformModel(); model.ClickCount = Convert.ToInt32(clickCount); return(View(model)); } }