Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OrderController.cs @ 9556

Last change on this file since 9556 was 9556, checked in by fschoepp, 11 years ago

#1888:

  • Added views for the billing component (Register users, Create orders and Activate Orders view)
  • Added a mockup for the billing back-end .
File size: 3.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HeuristicLab.Services.Optimization.Web.Models;
7using HeuristicLab.Services.Optimization.Billing.Model;
8using HeuristicLab.Services.Optimization.Billing.Interfaces;
9using HeuristicLab.Services.Optimization.Billing;
10using System.Web.Security;
11
12namespace HeuristicLab.Services.Optimization.Web.Controllers
13{
14    public class OrderController : Controller
15    {
16        private IOptimizationBilling billing = new MockupOptimizationBilling();
17
18        //
19        // GET: /Order/
20
21        public ActionResult Index()
22        {
23          return CreateOrder(new OrderModel()); //View();
24        }
25
26
27        [HttpPost]
28        public ActionResult CreateOrder(OrderModel model) {
29          Session["order"] = model;
30          return AddProduct();
31        }
32
33        public ActionResult AddProduct() {
34          return View("AddProduct", new ProductsModel() { Products = billing.GetProducts() });
35        }
36
37        [HttpPost]
38        public ActionResult AddProduct(ProductsModel product) {
39          var order = Session["order"] as OrderModel;
40          var prod = (from b in billing.GetProducts()
41                      where b.Id == product.ProductId
42                      select b).FirstOrDefault();
43          order.ProductQuantities[prod.Id] = product.Quantity;
44          return AddProduct();
45        }
46
47        public ActionResult SaveOrder() {
48          var orderModel = Session["order"] as OrderModel;
49          foreach (var key in orderModel.ProductQuantities.Keys) {
50            var product = (from p in billing.GetProducts() where p.Id == key select p).FirstOrDefault();
51            orderModel.Products[key] = product;           
52          }
53          return View(orderModel);
54        }
55
56        [HttpPost]
57        [ActionName("SaveOrder")]
58        public ActionResult SaveOrderPost() {
59          var orderModel = Session["order"] as OrderModel;
60          //TODO: Save order via back-end
61          var order = new Order() {
62            State = OrderState.Created,
63            User = new User() { Name = Membership.GetUser().UserName },
64            BillingType = orderModel.BillingType,
65            BillingPeriod = orderModel.BillingPeriod
66          };
67         
68          var orderLines = new List<OrderLine>();
69          var products = billing.GetProducts();
70          foreach (var key in orderModel.ProductQuantities.Keys) {
71            var product = (from p in products where p.Id == key select p).FirstOrDefault();
72            orderLines.Add(new OrderLine() {
73               Order = order,
74               Product = product,
75               ProductPrice = product.Price,
76               Quantity = orderModel.ProductQuantities[key]
77            });
78          }
79          order.OrderLines = orderLines;
80          billing.SaveOrder(order);
81          return RedirectToAction("OrderSaved");
82        }
83
84        public ActionResult OrderSaved() {
85          return View();
86        }
87    }
88}
Note: See TracBrowser for help on using the repository browser.