protected void Page_Load(object sender, EventArgs e) { this.ltlUserName.Text = CookieUtilities.GetCookieValue("username"); using (var context = new MemberContext()) { VelocityEngine ve = new VelocityEngine(); ve.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file"); ve.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, Server.MapPath("~/html_template")); ve.Init(); VelocityContext vContext = new VelocityContext(); var entities = context.RoleFunctions.Where(a => a.RoleId == RoleId && a.ParentID.EndsWith("_0")).Select(a => a).ToList(); List <Item> items = new List <Item>(); foreach (var entity in entities) { var item = new Item(); item.Name = entity.Name; item.IconClass = entity.IconClass; item.Url = entity.Url; item.Items = context.RoleFunctions.Where(a => a.RoleId == RoleId && a.ParentID.StartsWith(entity.ParentID.Substring(0, 2))).Where(a => a.Name != entity.Name).Select(a => new Item { Name = a.Name, Url = a.Url }).ToList <Item>(); items.Add(item); } vContext.Put("items", items); Template template = ve.GetTemplate("menu.html"); StringWriter writer = new StringWriter(); template.Merge(vContext, writer); MenuString = writer.GetStringBuilder().ToString(); } }
public ActionResult SetAllert(string price, Guid productId) { Guid userId = CookieUtilities.GetUserIdFromCookie(Request); ProductFollowUtilities.AddProductAllert(productId, userId, price); return(RedirectToAction("MyProducts", "MyProducts")); }
public RevisitedCart RetrieveCart(string cartCookie) { if (CookieUtilities.IsCartCookie(cartCookie)) { return(_siteOrderData.RetrieveCart(cartCookie)); } return(null); }
public ActionResult RemoveAlert(Guid productId) { var userId = CookieUtilities.GetUserIdFromCookie(Request); ProductFollowUtilities.RemoveProductAlert(userId, productId); return(RedirectToAction("MyProducts", "MyProducts")); }
private List <Produs> GetProducts() { var userId = CookieUtilities.GetUserIdFromCookie(Request); var products = ProductFollowUtilities.GetFollowedProducts(userId); return(products); }
protected void btnSendEmail_Click(object sender, EventArgs e) { string receiver = this.txtReceiver.Text.Trim(); string subject = this.txtSubject.Text.Trim(); MailMessage mailMessage = new MailMessage(); string content = this.hideMailContent.Value; mailMessage.From = "*****@*****.**"; mailMessage.Subject = subject; mailMessage.IsBodyHtml = true; mailMessage.HtmlBody = content; string[] users = receiver.Split(','); foreach (string user in users) { int startIndex = user.IndexOf('<') + 1; int length = user.Length; string email = user.Substring(startIndex, length - startIndex - 1); mailMessage.To.Add(email); } //创建附件 if (Session["tempTable"] != null) { DataTable table = (DataTable)Session["tempTable"]; foreach (DataRow row in table.Rows) { mailMessage.Attachments.Add(new Attachment(row["FilePath"].ToString())); } } SmtpClient client = AsposeUtilities.GetSmtpClient(this.Request.ApplicationPath); try { client.Send(mailMessage); using (var context = new EmailContext()) { var entity = new SendLog { Sender = CookieUtilities.GetCookieValue("username"), Receiver = receiver, SendTime = DateTime.Now, SendType = "Email" }; context.SendLogs.Add(entity); context.SaveChanges(); } ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('邮件发送成功')", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('邮件发送失败!" + ex.Message + "')", true); } }
public ActionResult ItemSelected(int?productId, int quant, decimal unitPrice, string memberCookie, int cartId) { var createdCart = _service.ItemSelected(productId.Value, quant, unitPrice, "http://thedatafarm.com", memberCookie, cartId); ControllerContext.HttpContext.Response.Cookies.Add( CookieUtilities.BuildCartCookie(createdCart.CartCookie, createdCart.CartCookieExpires)); TempData["CartCount"] = createdCart.TotalItems; TempData["CartId"] = createdCart.CartId; return(RedirectToAction("../ProductList")); }
protected void btnSendWeiXin_Click(object sender, EventArgs e) { string content = this.txtWeiXinContent.Text; try { int count = 0; foreach (RepeaterItem item in this.Repeater3.Items) { HtmlInputCheckBox checkBox = (HtmlInputCheckBox)item.FindControl("inlineCheckbox1"); if (checkBox.Checked) { count++; } } if (count == 0) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('请选择接收用户')", true); return; } StringBuilder receiverBuilder = new StringBuilder(); foreach (RepeaterItem item in this.Repeater3.Items) { HtmlInputCheckBox checkBox = (HtmlInputCheckBox)item.FindControl("inlineCheckbox1"); } string receiver = receiverBuilder.ToString().TrimEnd(','); using (var context = new EmailContext()) { var entity = new SendLog { Sender = CookieUtilities.GetCookieValue("username"), Receiver = receiver, SendTime = DateTime.Now, SendType = "WeiXin" }; context.SendLogs.Add(entity); context.SaveChanges(); } ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('微信发送成功')", true); } catch (Exception) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('微信发送可能,可能部分用户我发收到微信内容!')", true); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (IsValid) { // 验证用户密码 var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>(); // 这不会计入到为执行帐户锁定而统计的登录失败次数中 // 若要在多次输入错误密码的情况下触发锁定,请更改为 shouldLockout: true var result = signinManager.PasswordSignIn(this.txtUserName.Text, this.txtPassword.Text, this.chkRememberMe.Checked, shouldLockout: false); switch (result) { case SignInStatus.Success: CookieUtilities.SetCookie("username", this.txtUserName.Text.Trim(), DateTime.Now.AddDays(15)); IdentityHelper.RedirectToReturnUrl("/Manage/HomePage.aspx", Response); break; case SignInStatus.LockedOut: MessageBox.Show(this, "用户被锁定,请联系管理员解除锁定"); break; case SignInStatus.RequiresVerification: Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}", Request.QueryString["ReturnUrl"], this.chkRememberMe.Checked), true); break; case SignInStatus.Failure: default: MessageBox.Show(this, "登录失败,请确认用户名和密码是否正确"); break; } } }