Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9654


Ignore:
Timestamp:
06/24/13 14:11:05 (11 years ago)
Author:
spimming
Message:

#1888:

  • Added model and view for contact information
  • Insert contact information on SaveOrder page
  • Set correct entity state
Location:
branches/OaaS/HeuristicLab.Services.Optimization.Web
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/OrderController.cs

    r9586 r9654  
    66using HeuristicLab.Services.Optimization.Billing.Interfaces;
    77using HeuristicLab.Services.Optimization.Billing.Model;
     8using HeuristicLab.Services.Optimization.Web.Helpers;
    89using HeuristicLab.Services.Optimization.Web.Models;
    9 using HeuristicLab.Services.Optimization.Web.Helpers;
    1010
    1111namespace HeuristicLab.Services.Optimization.Web.Controllers {
     
    1818    // GET: /Order/
    1919
    20         public ActionResult Index()
    21         {
    22           if (RedirectToLoginIfNecessary("Order", false))
    23             return View();
    24           return CreateOrder(new OrderModel()); //View();
    25         }
     20    public ActionResult Index() {
     21      if (RedirectToLoginIfNecessary("Order", false))
     22        return View();
     23      return CreateOrder(new OrderModel()); //View();
     24    }
    2625
    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         }
     26    public ActionResult Overview() {
     27      if (RedirectToLoginIfNecessary("Order", false))
     28        return View();
     29      MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
     30      var orders = billing.GetOrders(currentUser.UserName);
     31      return View(new OverviewModel() { Orders = orders });
     32    }
    3433
    3534
    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         }
     35    [HttpPost]
     36    public ActionResult CreateOrder(OrderModel model) {
     37      if (RedirectToLoginIfNecessary("Order", false))
     38        return View();
     39      Session["order"] = model;
     40      var currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
     41      if (billing.GetUser(currentUser.UserName) == null) {
     42        billing.SaveUser(new User() { Name = currentUser.UserName, PaymentInformation = new List<PaymentInformation>() });
     43      }
     44      model.User = billing.GetUser(currentUser.UserName);
     45      return AddProduct();
     46    }
    4847
    4948    public ActionResult AddProduct() {
     
    7372    [ActionName("SaveOrder")]
    7473    public ActionResult SaveOrderPost(OrderModel orderModel) {
     74      var user = billing.GetUser(UserName);
    7575      var orderProductModel = Session["order"] as OrderModel;
    7676      //TODO: Save order via back-end
    7777      var order = new Order() {
    7878        State = OrderState.Created,
    79         User = new User() { Name = Membership.GetUser().UserName },
     79        User = user,
    8080        BillingType = orderModel.BillingType,
    8181        BillingPeriod = orderModel.BillingPeriod
     
    110110        oldInfo.AdditionalInformation = model.AdditionalInformation;
    111111        oldInfo.PaymentMethod = model.Method;
    112         billing.SaveUser(user);
    113       }
    114       else {
     112        oldInfo.EntityState = State.Modified;
     113      } else {
    115114        user.PaymentInformation.Add(new PaymentInformation() { CardNumber = model.CardNumber, AdditionalInformation = model.AdditionalInformation, PaymentMethod = model.Method });
     115        user.EntityState = State.Modified;
    116116      }
    117117
     118      billing.SaveUser(user);
    118119      return RedirectToAction("SaveOrder");
    119120    }
     
    122123      return View();
    123124    }
     125
     126    public ActionResult ContactInformation() {
     127      var user = billing.GetUser(UserName);
     128      var userCi = user.ContactInformation;
     129      ContactInformationModel contactInformationModel = null;
     130
     131      if (userCi == null) {
     132        contactInformationModel = new ContactInformationModel();
     133      } else {
     134        contactInformationModel = new ContactInformationModel() {
     135          ContactInformationId = userCi.ContactInformationId,
     136          FirstName = userCi.FirstName,
     137          LastName = userCi.LastName,
     138          Email = userCi.Email,
     139          OrganizationName = userCi.OrganizationName,
     140          Street = userCi.Street,
     141          PostalCode = userCi.PostalCode,
     142          City = userCi.City,
     143          State = userCi.State
     144        };
     145      }
     146      return View(contactInformationModel);
     147    }
     148
     149    [HttpPost]
     150    public ActionResult SaveContactInformation(ContactInformationModel model) {
     151      var user = billing.GetUser(UserName);
     152      var userCi = user.ContactInformation;
     153      if (userCi != null) {
     154        userCi.City = model.City;
     155        userCi.Email = model.Email;
     156        userCi.FirstName = model.FirstName;
     157        userCi.LastName = model.LastName;
     158        userCi.OrganizationName = model.OrganizationName;
     159        userCi.PostalCode = model.PostalCode;
     160        userCi.State = model.State;
     161        userCi.Street = model.Street;
     162        userCi.EntityState = State.Modified;
     163      } else {
     164        user.ContactInformation = new ContactInformation() {
     165          City = model.City,
     166          Email = model.Email,
     167          FirstName = model.FirstName,
     168          LastName = model.LastName,
     169          OrganizationName = model.OrganizationName,
     170          PostalCode = model.PostalCode,
     171          State = model.State,
     172          Street = model.Street
     173        };
     174        user.EntityState = State.Modified;
     175      }
     176
     177      billing.SaveUser(user);
     178
     179      return RedirectToAction("SaveOrder");
     180    }
    124181  }
    125182}
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/HeuristicLab.Services.Optimization.Web.csproj

    r9586 r9654  
    305305    <Content Include="HeuristicLab 3.3.exe" />
    306306    <Content Include="Mappings\tsp.xml" />
    307     <Content Include="Scripts\jquery-1.4.4-vsdoc.js" />
    308     <Content Include="Scripts\jquery-1.4.4.js" />
    309     <Content Include="Scripts\jquery-1.4.4.min.js" />
    310307    <Content Include="Scripts\jquery-1.5.1-vsdoc.js" />
    311308    <Content Include="Scripts\jquery-ui-1.8.11.js" />
     
    408405    <Content Include="Views\Usage\Index.cshtml" />
    409406    <Content Include="Views\Invoice\Index.cshtml" />
     407    <Content Include="Views\Order\ContactInformation.cshtml" />
    410408  </ItemGroup>
    411409  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Models/OrderModel.cs

    r9582 r9654  
    11using System;
    22using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Web;
    53using HeuristicLab.Services.Optimization.Billing.Model;
    64
     
    97  public class OrderModel {
    108    public BillingType BillingType { get; set; }
    11     public BillingPeriod BillingPeriod { get; set; }   
     9    public BillingPeriod BillingPeriod { get; set; }
    1210    public DateTime? ActiveSince { get; set; }
    1311    public DateTime? ActiveUntil { get; set; }
     
    4341  }
    4442
     43  public class ContactInformationModel {
     44    public long ContactInformationId { get; set; }
     45    public string OrganizationName { get; set; }
     46    public string Street { get; set; }
     47    public string City { get; set; }
     48    public string State { get; set; }
     49    public string PostalCode { get; set; }
     50    public string LastName { get; set; }
     51    public string FirstName { get; set; }
     52    public string Email { get; set; }
     53  }
     54
    4555  public class ProductsModel {
    4656    public IList<Product> Products { get; set; }
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Views/Order/SaveOrder.cshtml

    r9586 r9654  
    2525
    2626@if (Model.User.PaymentInformation == null || Model.User.PaymentInformation.Count == 0) {
    27   <h2>You didn't specify any payment information yet. Please click @Html.ActionLink("here", "Payment") to enter the information.</h2>
     27  <h2>You didn't specify any payment information yet. Please click @Html.ActionLink("here", "Payment")
     28    to enter the information.</h2>
     29} else {
     30  <h2>Choose one of your payment options:</h2>
     31  foreach (var pi in Model.User.PaymentInformation) {
     32  <p>
     33    @Html.Label("PaymentInformationId", string.Format("{0} ({1})", pi.PaymentMethod, pi.CardNumber))
     34    @Html.RadioButton("PaymentInformationId", pi.PaymentInformationId)
     35  </p>
     36  }
     37  <h3>Or add payment information by clicking @Html.ActionLink("here", "Payment").</h3>
    2838}
    29 else {
    30     <h2>Choose one of your payment options:</h2>
    31     foreach (var pi in Model.User.PaymentInformation) {
    32         <p>
    33          @Html.Label("PaymentInformationId", string.Format("{0} ({1})", pi.PaymentMethod, pi.CardNumber))
    34          @Html.RadioButton("PaymentInformationId", pi.PaymentInformationId)
    35         </p>
    36     }
    37     <h3>Or add payment information by clicking @Html.ActionLink("here", "Payment").</h3>
    38    
    39     using (Html.BeginForm("SaveOrder", "Order")) {
    40     <h2>How often would you like to be billed?</h2>
    41     <p>
    42     @Html.RadioButtonForEnum(m => m.BillingPeriod)
    43     </p>
    44     <h2>Would you like to pay upfront or at the end of the period?</h2>
    45     <p>
    46     @Html.RadioButtonForEnum(m => m.BillingType)
    47     </p>
    48      <p>
    49         <input type="submit" value="Save order" />
    50     </p>
     39
     40@if (Model.User.ContactInformation == null) {
     41  <h2>You didn't specify any contact information yet. Please click @Html.ActionLink("here", "ContactInformation")
     42  to enter the information.</h2>
     43} else {
     44  <h2>Contact Information</h2>
     45 
     46  <table>
     47    <tbody>
     48      <tr>
     49        <td>@Html.LabelFor(m => m.User.ContactInformation.FirstName)</td>
     50        <td>@Model.User.ContactInformation.FirstName</td>
     51      </tr>
     52      <tr>
     53        <td>@Html.LabelFor(m => m.User.ContactInformation.LastName)</td>
     54        <td>@Model.User.ContactInformation.LastName</td>
     55      </tr>
     56      <tr>
     57        <td>@Html.LabelFor(m => m.User.ContactInformation.FirstName)</td>
     58        <td>@Model.User.ContactInformation.FirstName</td>
     59      </tr>
     60      <tr>
     61        <td>@Html.LabelFor(m => m.User.ContactInformation.Email)</td>
     62        <td>@Model.User.ContactInformation.Email</td>
     63      </tr>
     64      <tr>
     65        <td>@Html.LabelFor(m => m.User.ContactInformation.OrganizationName)</td>
     66        <td>@Model.User.ContactInformation.OrganizationName</td>
     67      </tr>
     68      <tr>
     69        <td>@Html.LabelFor(m => m.User.ContactInformation.Street)</td>
     70        <td>@Model.User.ContactInformation.Street</td>
     71      </tr>
     72      <tr>
     73        <td>@Html.LabelFor(m => m.User.ContactInformation.PostalCode)</td>
     74        <td>@Model.User.ContactInformation.PostalCode</td>
     75      </tr>
     76      <tr>
     77        <td>@Html.LabelFor(m => m.User.ContactInformation.City)</td>
     78        <td>@Model.User.ContactInformation.City</td>
     79      </tr>
     80      <tr>
     81        <td>@Html.LabelFor(m => m.User.ContactInformation.State)</td>
     82        <td>@Model.User.ContactInformation.State</td>
     83      </tr>
     84    </tbody>
     85  </table>
     86 
     87  <h3>Edit contact information by clicking @Html.ActionLink("here", "ContactInformation")</h3>
    5188}
     89
     90@if ((Model.User.PaymentInformation != null && Model.User.PaymentInformation.Count != 0) && (Model.User.ContactInformation != null)) {
     91  using (Html.BeginForm("SaveOrder", "Order")) {
     92  <h2>How often would you like to be billed?</h2>
     93  <p>@Html.RadioButtonForEnum(m => m.BillingPeriod)</p>
     94 
     95  <h2>Would you like to pay upfront or at the end of the period?</h2>
     96  <p>@Html.RadioButtonForEnum(m => m.BillingType)</p>
     97 
     98  <p><input type="submit" value="Save order" /></p>
     99  }
    52100}
Note: See TracChangeset for help on using the changeset viewer.