1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.Mvc;
|
---|
6 | using HeuristicLab.Services.Optimization.Web.Helpers;
|
---|
7 | using HeuristicLab.Services.Optimization.Billing.Interfaces;
|
---|
8 | using System.Web.Security;
|
---|
9 | using HeuristicLab.Services.Optimization.Billing;
|
---|
10 | using HeuristicLab.Services.Optimization.Billing.Business;
|
---|
11 |
|
---|
12 | namespace 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 | }
|
---|