public void CreateHtmlePage(int id) { Model.BooksModel booksInfo = dal.GetModel(id); //获取模板文件 string template = HttpContext.Current.Request.MapPath("/Template/BookTemplate.html"); string fileContent = File.ReadAllText(template); string dir = "/HtmlPage/" + booksInfo.PublishDate.Year + "/"; Directory.CreateDirectory(Path.GetDirectoryName(HttpContext.Current.Request.MapPath(dir))); string fullDir = dir + booksInfo.Id + ".html"; fileContent = fileContent.Replace("$title", booksInfo.Title).Replace("$author", booksInfo.Author).Replace("$unitprice", booksInfo.UnitPrice.ToString("0.00")).Replace("$isbn", booksInfo.ISBN).Replace("$content", booksInfo.ContentDescription).Replace("$bookId", booksInfo.Id.ToString()).Replace("$hiddenReturnUrl", fullDir); File.WriteAllText(HttpContext.Current.Request.MapPath(fullDir), fileContent, System.Text.Encoding.UTF8); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; BLL.UsersBLL userManager = new BLL.UsersBLL(); if (userManager.ValidateUserLogin()) { int bookId = Convert.ToInt32(context.Request["bookId"]); // BLL.BooksBLL bookManger = new BLL.BooksBLL(); Model.BooksModel bookModel = bookManger.GetModel(bookId); if (bookModel != null) { int userId = ((Model.UsersModel)context.Session["userInfo"]).Id; BLL.CartBLL cartManager = new BLL.CartBLL(); Model.CartModel cartModel = cartManager.GetModel(userId, bookId); if (cartModel != null) { cartModel.Count += 1; cartManager.Update(cartModel); } else { cartModel = new Model.CartModel(); cartModel.Count = 1; cartModel.UserId = userId; cartModel.BookId = bookId; cartManager.Add(cartModel); } context.Response.Write("{\"action\":\"have\",\"message\":\"已添加到购物车\"}"); } else { context.Response.Write("{\"action\":\"notHave\",\"message\":\"无此商品\"}"); } //context.Response.Write("{\"action\":\"ok\",\"message\":\"登录成功\"}"); } else { context.Response.Write("{\"action\":\"notLogin\",\"message\":\"您还没有登陆\"}"); } }