-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommentHandler.ashx
49 lines (45 loc) · 1.44 KB
/
CommentHandler.ashx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<%@ WebHandler Language="C#" Class="CommentHandler" %>
using System;
using System.Web;
using System.Linq;
public class CommentHandler : IHttpHandler {
book_storeDataContext db = new book_storeDataContext();
public void ProcessRequest (HttpContext context) {
if(null==context.Request.UrlReferrer){
context.Response.Write("");
return;
}
//获取订单号
int orderId;
int.TryParse(context.Request["orderId"],out orderId);
var order = (from r in db.Order
where r.Id == orderId&&r.CommentState==false
select r).FirstOrDefault();
if (order == null)
{
return;
}
var books = from r in db.OrderDetail
where r.OrderId == order.Id
select r;
if (books.Count()==0) { return; }
foreach (var book in books) {
Comment com = new Comment();
com.UserName = order.UserName;
com.BookId = book.BookId;
com.Content = context.Request["comment"];
com.Time = DateTime.Now;
db.Comment.InsertOnSubmit(com);
db.SubmitChanges();
}
order.CommentState = true;
db.SubmitChanges();
context.Response.ContentType = "text/html";
context.Response.Write("1");
}
public bool IsReusable {
get {
return false;
}
}
}