This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 313
/
Order.cshtml
128 lines (115 loc) · 5.21 KB
/
Order.cshtml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@section Scripts {
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
}
@{
Page.Title = "Place Your Order";
var db = Database.Open("bakery");
var productId = UrlData[0].AsInt();
var product = db.QuerySingle("SELECT * FROM PRODUCTS WHERE ID = @0", productId);
if (product == null) {
Response.Redirect("~/");
}
// Setup validation
Validation.RequireField("orderEmail", "You must specify an email address.");
Validation.RequireField("orderShipping", "You must specify a shipping address.");
if (IsPost && Validation.IsValid()) {
var email = Request["orderEmail"];
var shipping = Request["orderShipping"];
//If there is no error try to process order
var body = "Thank you, we have received your order for " + Request["orderQty"] + " unit(s) of " + product.Name + "!<br/>";
var orderShipping = Request["orderShipping"];
var customerEmail = Request["orderEmail"];
if (!orderShipping.IsEmpty()) {
//Replace carriage returns with HTML breaks for HTML mail
var formattedOrder = orderShipping.Replace("\r\n", "<br/>");
body += "Your address is: <br/>" + formattedOrder + "<br/>";
}
body += "Your total is $" + product.Price * Request["orderQty"].AsDecimal() +".<br/>";
body += "We will contact you if we have questions about your order. Thanks!<br/>";
//SMTP Configuration for Hotmail
WebMail.SmtpServer = "smtp.live.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = true;
//Enter your Hotmail credentials for UserName/Password and a "From" address for the e-mail
WebMail.UserName = "";
WebMail.Password = "";
WebMail.From = "";
if (WebMail.UserName.IsEmpty() || WebMail.Password.IsEmpty() || WebMail.From.IsEmpty()) {
Response.Redirect("~/OrderSuccess?NoEmail=1");
}
else {
try {
WebMail.Send(to: customerEmail, subject: "Fourth Coffee - New Order", body: body);
Response.Redirect("~/OrderSuccess");
} catch {
ModelState.AddFormError("There was an error and your order could not be processed at this time");
}
}
}
}
<ol id="orderProcess">
<li><span class="step-number">1</span>Choose Item</li>
<li class="current"><span class="step-number">2</span>Details & Submit</li>
<li><span class="step-number">3</span>Receipt</li>
</ol>
<h1>Place Your Order: @product.Name</h1>
<form action="" method="post">
@Html.ValidationSummary(excludeFieldErrors: true)
<fieldset class="no-legend">
<legend>Place Your Order</legend>
<img class="product-image order-image" src="~/Images/Products/Thumbnails/@product.ImageName" alt="Image of @product.Name"/>
<ul class="orderPageList" data-role="listview">
<li>
<div>
<p class="description">@product.Description</p>
</div>
</li>
<li class="email">
<div class="fieldcontainer" data-role="fieldcontain">
<label for="orderEmail">Your Email Address</label>
<input type="text" id="orderEmail" name="orderEmail" @Validation.For("orderEmail")/>
<div>@Html.ValidationMessage("orderEmail")</div>
</div>
</li>
<li class="shiping">
<div class="fieldcontainer" data-role="fieldcontain">
<label for="orderShipping">Shipping Address</label>
<textarea rows="4" id="orderShipping" name="orderShipping" @Validation.For("orderShipping")></textarea>
<div>@Html.ValidationMessage("orderShipping")</div>
</div>
</li>
<li class="quantity">
<div class="fieldcontainer" data-role="fieldcontain">
<label for="orderQty">Quantity</label>
<input type="text" id="orderQty" name="orderQty" value="1"/>
x
<span id="orderPrice">@string.Format("{0:f}", product.Price)</span>
=
<span id="orderTotal">@string.Format("{0:f}", product.Price)</span>
</div>
</li>
</ul>
<p class="actions">
<input type="hidden" name="ProductId" value="@product.Id" />
<input type="submit" value="Place Order" data-role="none" data-inline="true"/>
</p>
</fieldset>
</form>
<script type="text/javascript">
$(function () {
var price = parseFloat($("#orderPrice").text()).toFixed(2),
total = $("#orderTotal"),
orderQty = $("#orderQty");
orderQty.change(function () {
var quantity = parseInt(orderQty.val());
if (!quantity || quantity < 1) {
orderQty.val(1);
quantity = 1;
} else if (quantity.toString() !== orderQty.val()) {
orderQty.val(quantity);
}
total.text("$" + (price * quantity).toFixed(2));
});
});
</script>