本文整理汇总了C#中MvcMusicStore.Models.Order类的典型用法代码示例。如果您正苦于以下问题:C# Order类的具体用法?C# Order怎么用?C# Order使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Order类属于MvcMusicStore.Models命名空间,在下文中一共展示了Order类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddressAndPayment
public ActionResult AddressAndPayment(FormCollection values)
{
var order = new Order();
TryUpdateModel(order);
string promoCode = values["PromoCode"];
if (!String.IsNullOrEmpty(promoCode) && !string.Equals(promoCode, PromoCode, StringComparison.OrdinalIgnoreCase))
{
ModelState.AddModelError("", "Promo code is not valid.");
//Invalid - redisplay with errors
return View(order);
}
string userName = User.Identity.Name;
var cart = ShoppingCart.GetCart(this.HttpContext);
order.Username = userName;
order.OrderDate = DateTime.Now;
//Save Order
_entities.Orders.Add(order);
_entities.SaveChanges();
//Process the order
cart.CreateOrder(order);
return RedirectToAction("Complete",
new { id = order.OrderId });
}
示例2: CreateOrder
public int CreateOrder(Order order)
{
decimal orderTotal = 0;
var cartItems = GetCartItems();
//add order details for each item in cart
foreach (var item in cartItems)
{
var orderDetail = new OrderDetail
{
AlbumId = item.AlbumId,
OrderId = order.OrderId,
UnitPrice = item.Album.Price,
Quantity = item.Count
};
//set the order total of the shopping cart
orderTotal += (item.Count * item.Album.Price);
storeDB.OrderDetails.Add(orderDetail);
}
// set the order's total to the orderTotal count
order.Total = orderTotal;
//save the order and finish up
storeDB.SaveChanges();
EmptyCart();
return order.OrderId;
}
示例3: AddressAndPayment
public ActionResult AddressAndPayment(FormCollection values)
{
var order = new Order();
TryUpdateModel(order);
try
{
if (string.Equals(values["PromoCode"], PromoCode,
StringComparison.OrdinalIgnoreCase) == false)
{
return View(order);
}
else
{
order.Username = User.Identity.Name;
order.OrderDate = DateTime.Now;
//Save Order
storeContext.Session.Save(order);
//Process the order
var cart = ShoppingCart.GetCart(this.HttpContext, storeContext);
cart.CreateOrder(order);
return RedirectToAction("Complete",
new { id = order.OrderId });
}
}
catch
{
//Invalid - redisplay with errors
return View(order);
}
}
示例4: CreateOrder
public int CreateOrder(Order order)
{
decimal orderTotal = 0;
foreach (var item in GetCartItems())
{
var orderDetail = new OrderDetail
{
AlbumId = item.AlbumId,
OrderId = order.OrderId,
UnitPrice = item.Album.Price,
Quantity = item.Count
};
orderTotal += (item.Count * item.Album.Price);
storeDB.OrderDetails.Add(orderDetail);
}
order.Total = orderTotal;
storeDB.SaveChanges();
EmptyCart();
return order.OrderId;
}
示例5: CreateOrder
public int CreateOrder(Order order)
{
using (var tx = storeContext.Session.BeginTransaction())
{
var cartItems = GetCartItems();
//Iterate the items in the cart, adding Order Details for each
foreach (var cartItem in cartItems)
{
var orderDetail = new OrderDetail
{
Album = cartItem.Album,
Order = order,
UnitPrice = cartItem.Album.Price
};
order.OrderDetails.Add(orderDetail);
}
//Save the order
storeContext.Session.Save(order);
tx.Commit();
}
//Empty the shopping cart
EmptyCart();
//Return the OrderId as a confirmation number
return order.OrderId;
}
示例6: CreateOrder
public int CreateOrder(Order order)
{
decimal orderTotal = 0;
var cartItems = GetCartItems();
//Iterate the items in the cart, adding Order Details for each
foreach (var cartItem in cartItems)
{
var orderDetails = new OrderDetail
{
AlbumId = cartItem.AlbumId,
OrderId = order.OrderId,
UnitPrice = cartItem.Album.Price
};
storeDB.OrderDetails.AddObject(orderDetails);
orderTotal += (cartItem.Count * cartItem.Album.Price);
}
//Save the order
storeDB.SaveChanges();
//Empty the shopping cart
EmptyCart();
//Return the OrderId as a confirmation number
return order.OrderId;
}
示例7: AddressAndPayment
public ActionResult AddressAndPayment(FormCollection values)
{
var order = new Order();
TryUpdateModel(order);
try
{
if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false)
{
return View(order);
}
else
{
order.Username = User.Identity.Name;
order.OrderDate = DateTime.Now;
storeDB.Orders.Add(order);
storeDB.SaveChanges();
var cart = ShoppingCart.GetCart(this.HttpContext);
cart.CreateOrder(order);
return RedirectToAction("Complete", new { id = order.OrderId });
}
}
catch
{
return View(order);
}
}
示例8: Edit
public ActionResult Edit(Order order)
{
if (ModelState.IsValid)
{
db.Entry(order).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(order);
}
示例9: Create
public ActionResult Create(Order order)
{
if (ModelState.IsValid)
{
db.Orders.Add(order);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(order);
}
示例10: AddressAndPaymentAsync
public void AddressAndPaymentAsync(FormCollection values)
{
AsyncManager.OutstandingOperations.Increment();
var worker = new BackgroundWorker();
var order = new Order();
bool success = true;
TryUpdateModel(order);
string promoCode = values["PromoCode"];
if (!String.IsNullOrEmpty(promoCode) && !string.Equals(promoCode, PromoCode, StringComparison.OrdinalIgnoreCase))
{
ModelState.AddModelError("", "Promo code is not valid.");
success = false;
}
string userName = User.Identity.Name;
var cart = ShoppingCart.GetCart(this.HttpContext);
worker.DoWork += (sender, args) =>
{
if (!success)
return;
try
{
order.Username = userName;
order.OrderDate = DateTime.Now;
//Save Order
_entities.Orders.Add(order);
_entities.SaveChanges();
//Process the order
cart.CreateOrder(order);
success = true;
}
catch
{
success = false;
}
};
worker.RunWorkerCompleted += (o, e) =>
{
AsyncManager.Parameters["order"] = order;
AsyncManager.Parameters["success"] = success;
AsyncManager.OutstandingOperations.Decrement();
};
worker.RunWorkerAsync(null);
}
示例11: CreateOrder
public void CreateOrder(Order order)
{
order.Lines = new List<Order.OrderLine>(
Lines.Select(line => new Order.OrderLine
{
Album = new Order.OrderLine.OrderAlbum
{
Id = line.Album.Id,
Title = line.Album.Title
},
Price = line.Price,
Quantity = line.Quantity
}));
Lines.Clear();
}
示例12: AddressAndPayment
public ActionResult AddressAndPayment(FormCollection values)
{
var order = new Order();
TryUpdateModel(order);
try
{
if (string.Equals(values["PromoCode"], PromoCode,
StringComparison.OrdinalIgnoreCase) == false)
{
return View(order);
}
else
{
order.Username = User.Identity.Name;
order.OrderDate = DateTime.Now;
//Save Order
storeDB.Orders.Add(order);
storeDB.SaveChanges();
//Process the order
var cart = ShoppingCart.GetCart(this.HttpContext);
cart.CreateOrder(order);
//Add SMS notification here
if (order.SendSmsNotifications)
{
var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken);
client.SendSmsMessage(
ConfigurationManager.AppSettings["PhoneNumber"],
order.Phone,
string.Format("Thank you for ordering. You can check the status anytime by replying to this with the text 'status {0}'", order.OrderId)
);
}
return RedirectToAction("Complete",
new { id = order.OrderId });
}
}
catch
{
//Invalid - redisplay with errors
return View(order);
}
}
示例13: CreateShippingInfo
public static Order CreateShippingInfo()
{
var shippingInfo = new Order
{
FirstName = "Homer",
LastName = "Simpson",
Address = "742 Evergreen Terrace",
City = "Springfield",
State = "Kentucky",
PostalCode = "123456",
Country = "United States",
Phone = "2341231241",
Email = "[email protected]"
};
return shippingInfo;
}
示例14: AddressAndPayment
public ActionResult AddressAndPayment(FormCollection values)
{
var order = new Order();
try
{
// Updat the model
UpdateModel(order);
if (string.Equals(values["PromoCode"],
PromoCode,
StringComparison.OrdinalIgnoreCase) == false)
{
return View(order);
}
else
{
if (ModelState.IsValid)
{
// Promo Code supplied
order.Username = User.Identity.Name;
order.OrderDate = DateTime.Now;
// Save Order
storeDB.Orders.Add(order);
storeDB.SaveChanges();
// Process the order
var cart = ShoppingCart.GetCart(this);
cart.CreateOrder(order);
return RedirectToAction("Complete", new { id = order.OrderId });
}
else
{
throw new Exception("Model State is not valid!");
}
}
}
catch
{
// Invalid -- redisplay with errors
return View(order);
}
}
示例15: Create
public ActionResult Create(FormCollection values)
{
var order = new Order();
TryUpdateModel(order);
if (string.Equals(values["PromoCode"], PromoCode,
StringComparison.OrdinalIgnoreCase) == false)
{
return View(order);
}
else
{
order.Username = User.Identity.Name;
order.OrderDate = DateTime.Now;
//Save Order
db.Orders.Add(order);
//Process the order
var cart = ShoppingCart.GetCart(db, this.HttpContext);
cart.CreateOrder(order);
//add a note
order.Notes = new List<OrderNote>();
order.Transactions = new List<Transaction>();
order.Notes.Add(new OrderNote { Note = "Preparing Order", CreatedOn = DateTime.Now});
//auth the charge...
order.Transactions.Add(new Transaction { Processor = "coupon", Authorization = PromoCode, Amount = cart.GetTotal(), CreatedOn = DateTime.Now, Discount = 0, OrderId = order.OrderId });
order.Notes.Add(new OrderNote { Note = "Transaction Authorized by Coupon: " + PromoCode, CreatedOn = DateTime.Now});
//send a thank you note via email
order.Notes.Add(new OrderNote { Note = "Thank You Invoice Email Sent", CreatedOn = DateTime.Now});
//set the status as paid. Simplistic, but will work for now
order.Status = "paid";
//flush it since we need the new id
db.SaveChanges();
//save it down
return RedirectToAction("Details",
new { id = order.OrderId });
}
}