Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/BaseController.cs @ 9582

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

#1888:

  • Added an overview for users to inspect their orders
  • Order Administrators may now suspend or reactivate orders
  • When creating an order, its necessary to enter payment information (paypal, credit card,...) before
  • Also, the billing period and type must be entered during the creation of an order.
File size: 1.9 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)
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.