Changeset 9582 for branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OrderController.cs
- Timestamp:
- 06/04/13 16:30:39 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OrderController.cs
r9576 r9582 10 10 namespace HeuristicLab.Services.Optimization.Web.Controllers { 11 11 [Authorize(Roles = "Web User")] 12 public class OrderController : Controller {12 public class OrderController : BaseController { 13 13 private IOptimizationBilling billing = BillingServiceProvider.Instance; 14 14 … … 16 16 // GET: /Order/ 17 17 18 public ActionResult Index() { 19 return CreateOrder(new OrderModel()); //View(); 20 } 18 public ActionResult Index() 19 { 20 if (RedirectToLoginIfNecessary("Order", false)) 21 return View(); 22 return CreateOrder(new OrderModel()); //View(); 23 } 24 25 public ActionResult Overview() { 26 if (RedirectToLoginIfNecessary("Order", false)) 27 return View(); 28 MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */); 29 var orders = billing.GetOrders(currentUser.UserName); 30 return View(new OverviewModel() { Orders = orders }); 31 } 21 32 22 33 23 [HttpPost] 24 public ActionResult CreateOrder(OrderModel model) { 25 Session["order"] = model; 26 return AddProduct(); 27 } 34 [HttpPost] 35 public ActionResult CreateOrder(OrderModel model) { 36 if (RedirectToLoginIfNecessary("Order", false)) 37 return View(); 38 Session["order"] = model; 39 var currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */); 40 if (billing.GetUser(currentUser.UserName) == null) { 41 billing.SaveUser(new User() { Name = currentUser.UserName, PaymentInformation = new List<PaymentInformation>() }); 42 } 43 model.User = billing.GetUser(currentUser.UserName); 44 return AddProduct(); 45 } 28 46 29 47 public ActionResult AddProduct() { … … 52 70 [HttpPost] 53 71 [ActionName("SaveOrder")] 54 public ActionResult SaveOrderPost( ) {55 var order Model = Session["order"] as OrderModel;72 public ActionResult SaveOrderPost(OrderModel orderModel) { 73 var orderProductModel = Session["order"] as OrderModel; 56 74 //TODO: Save order via back-end 57 75 var order = new Order() { … … 64 82 var orderLines = new List<OrderLine>(); 65 83 var products = billing.GetProducts(); 66 foreach (var key in order Model.ProductQuantities.Keys) {84 foreach (var key in orderProductModel.ProductQuantities.Keys) { 67 85 var product = (from p in products where p.ProductId == key select p).FirstOrDefault(); 68 86 orderLines.Add(new OrderLine() { … … 70 88 Product = product, 71 89 ProductPrice = product.Price, 72 Quantity = order Model.ProductQuantities[key]90 Quantity = orderProductModel.ProductQuantities[key] 73 91 }); 74 92 } … … 78 96 } 79 97 98 public ActionResult Payment() { 99 var paymentModel = new PaymentModel(); 100 return View(paymentModel); 101 } 102 103 [HttpPost] 104 public ActionResult SavePayment(PaymentModel model) { 105 var user = billing.GetUser(UserName); 106 var oldInfo = (from pi in user.PaymentInformation where pi.CardNumber == model.CardNumber select pi).FirstOrDefault(); 107 if (oldInfo != null) { 108 oldInfo.AdditionalInformation = model.AdditionalInformation; 109 oldInfo.PaymentMethod = model.Method; 110 billing.SaveUser(user); 111 } 112 else { 113 user.PaymentInformation.Add(new PaymentInformation() { CardNumber = model.CardNumber, AdditionalInformation = model.AdditionalInformation, PaymentMethod = model.Method }); 114 } 115 116 return RedirectToAction("SaveOrder"); 117 } 118 80 119 public ActionResult OrderSaved() { 81 120 return View();
Note: See TracChangeset
for help on using the changeset viewer.