Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1888:

  • Billing Component may now be deactivated by setting the BillingEnabled flag within the OaaS service configuration.
  • Added views for invoices and usage data.
  • Changed appearance of the SaveOrder view.
File size: 4.6 KB
RevLine 
[9576]1using System.Collections.Generic;
[9556]2using System.Linq;
3using System.Web.Mvc;
[9576]4using System.Web.Security;
5using HeuristicLab.Services.Optimization.Billing.Business;
6using HeuristicLab.Services.Optimization.Billing.Interfaces;
7using HeuristicLab.Services.Optimization.Billing.Model;
[9556]8using HeuristicLab.Services.Optimization.Web.Models;
[9586]9using HeuristicLab.Services.Optimization.Web.Helpers;
[9556]10
[9576]11namespace HeuristicLab.Services.Optimization.Web.Controllers {
12  [Authorize(Roles = "Web User")]
[9586]13  [BillingFilterActionAttribute]
[9582]14  public class OrderController : BaseController {
[9576]15    private IOptimizationBilling billing = BillingServiceProvider.Instance;
[9556]16
[9576]17    //
18    // GET: /Order/
[9556]19
[9582]20        public ActionResult Index()
21        {
22          if (RedirectToLoginIfNecessary("Order", false))
23            return View();
24          return CreateOrder(new OrderModel()); //View();
25        }
[9556]26
[9582]27        public ActionResult Overview() {
28          if (RedirectToLoginIfNecessary("Order", false))
29            return View();
30          MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
31          var orders = billing.GetOrders(currentUser.UserName);
32          return View(new OverviewModel() { Orders = orders });
33        }
[9556]34
35
[9582]36        [HttpPost]
37        public ActionResult CreateOrder(OrderModel model) {
38          if (RedirectToLoginIfNecessary("Order", false))
39            return View();
40          Session["order"] = model;
41          var currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
42          if (billing.GetUser(currentUser.UserName) == null) {
43            billing.SaveUser(new User() { Name = currentUser.UserName, PaymentInformation = new List<PaymentInformation>() });
44          }
45          model.User = billing.GetUser(currentUser.UserName);
46          return AddProduct();
47        }
48
[9576]49    public ActionResult AddProduct() {
50      return View("AddProduct", new ProductsModel() { Products = billing.GetProducts() });
51    }
[9556]52
[9576]53    [HttpPost]
54    public ActionResult AddProduct(ProductsModel product) {
55      var order = Session["order"] as OrderModel;
56      var prod = (from b in billing.GetProducts()
57                  where b.ProductId == product.ProductId
58                  select b).FirstOrDefault();
59      order.ProductQuantities[prod.ProductId] = product.Quantity;
60      return AddProduct();
61    }
[9556]62
[9576]63    public ActionResult SaveOrder() {
64      var orderModel = Session["order"] as OrderModel;
65      foreach (var key in orderModel.ProductQuantities.Keys) {
66        var product = (from p in billing.GetProducts() where p.ProductId == key select p).FirstOrDefault();
67        orderModel.Products[key] = product;
68      }
69      return View(orderModel);
70    }
[9556]71
[9576]72    [HttpPost]
73    [ActionName("SaveOrder")]
[9582]74    public ActionResult SaveOrderPost(OrderModel orderModel) {
75      var orderProductModel = Session["order"] as OrderModel;
[9576]76      //TODO: Save order via back-end
77      var order = new Order() {
78        State = OrderState.Created,
79        User = new User() { Name = Membership.GetUser().UserName },
80        BillingType = orderModel.BillingType,
81        BillingPeriod = orderModel.BillingPeriod
82      };
[9556]83
[9576]84      var orderLines = new List<OrderLine>();
85      var products = billing.GetProducts();
[9582]86      foreach (var key in orderProductModel.ProductQuantities.Keys) {
[9576]87        var product = (from p in products where p.ProductId == key select p).FirstOrDefault();
88        orderLines.Add(new OrderLine() {
89          Order = order,
90          Product = product,
91          ProductPrice = product.Price,
[9582]92          Quantity = orderProductModel.ProductQuantities[key]
[9576]93        });
94      }
95      order.OrderLines = orderLines;
96      billing.SaveOrder(order);
97      return RedirectToAction("OrderSaved");
[9556]98    }
[9576]99
[9582]100    public ActionResult Payment() {
101      var paymentModel = new PaymentModel();
102      return View(paymentModel);
103    }
104
105    [HttpPost]
106    public ActionResult SavePayment(PaymentModel model) {
107      var user = billing.GetUser(UserName);
108      var oldInfo = (from pi in user.PaymentInformation where pi.CardNumber == model.CardNumber select pi).FirstOrDefault();
109      if (oldInfo != null) {
110        oldInfo.AdditionalInformation = model.AdditionalInformation;
111        oldInfo.PaymentMethod = model.Method;
112        billing.SaveUser(user);
113      }
114      else {
115        user.PaymentInformation.Add(new PaymentInformation() { CardNumber = model.CardNumber, AdditionalInformation = model.AdditionalInformation, PaymentMethod = model.Method });
116      }
117
118      return RedirectToAction("SaveOrder");
119    }
120
[9576]121    public ActionResult OrderSaved() {
122      return View();
123    }
124  }
[9556]125}
Note: See TracBrowser for help on using the repository browser.