Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Services.Optimization.Web/Controllers/BaseController.cs @ 17578

Last change on this file since 17578 was 9586, checked in by fschoepp, 12 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: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HeuristicLab.Services.Optimization.Web.Helpers;
7using HeuristicLab.Services.Optimization.Billing.Interfaces;
8using System.Web.Security;
9using HeuristicLab.Services.Optimization.Billing;
10using HeuristicLab.Services.Optimization.Billing.Business;
11
12namespace HeuristicLab.Services.Optimization.Web.Controllers
13{
14    public class BaseController : Controller
15    {
16      private IOptimizationBilling billing = BillingServiceProvider.Instance;
17
18      protected ControllerServiceHelper ControllerService {
19        get {
20          var helper = new ControllerServiceHelper(Session["pw"] as string);
21          RedirectToLoginIfNecessary();
22          return helper;
23        }
24      }
25
26      protected string UserName {
27        get { MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */); return currentUser.UserName; }
28      }
29
30      protected bool RedirectToLoginIfNecessary(string destination="%2fOptimization", bool orderNecessary=true) {
31        var pw = Session["pw"] as string;
32        if (pw == null) {
33          Response.Redirect("/Account/Logon?ReturnUrl=" + destination);
34          return true;
35        }
36        if (orderNecessary && BillingComponent.Enabled)
37          return RedirectToCreateOrderIfNecessary();
38        return false;
39      }
40
41      protected bool RedirectToCreateOrderIfNecessary() {
42        MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
43        var activeOrderOfUser = (from order in billing.GetOrdersByState(Billing.Model.OrderState.Active) where order.User.Name == currentUser.UserName select order).FirstOrDefault();
44        if (activeOrderOfUser == null) {
45          // create a new order if there is no active order available
46          Response.Redirect("/Order/Overview");
47        }
48        return false;
49      }
50    }
51}
Note: See TracBrowser for help on using the repository browser.