Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit 7b71fe7

Browse files
author
Tim Hess
committed
final version for demo
1 parent c5d0a99 commit 7b71fe7

File tree

17 files changed

+234
-136
lines changed

17 files changed

+234
-136
lines changed

src/funstore.service.cart/Startup.fs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open Microsoft.Extensions.Configuration
77
open Microsoft.Extensions.DependencyInjection
88
open Steeltoe.Management.CloudFoundry
99
open Pivotal.Discovery.Client
10+
open System
1011

1112
type Startup private () =
1213
new (configuration: IConfiguration) as this =
@@ -18,6 +19,7 @@ type Startup private () =
1819
// Add framework services.
1920
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) |> ignore
2021
services.AddCloudFoundryActuators(this.Configuration) |> ignore
22+
Console.WriteLine (this.Configuration.GetSection "eureka")
2123
services.AddDiscoveryClient(this.Configuration) |> ignore
2224

2325
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

src/funstore.service.cart/appsettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Warning"
4+
"Default": "Trace"
55
}
66
},
77
"spring": {

src/funstore.service.order/Controllers/OrderController.cs

+30-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public class OrderController : Controller
1111
{
1212
private static List<Shared.csharp.Order> Orders = new List<Shared.csharp.Order>();
1313

14+
[HttpGet]
15+
public IEnumerable<Shared.csharp.Order> Get()
16+
{
17+
return Orders;
18+
}
19+
1420
// GET api/values
1521
[HttpGet("history/{cartId}")]
1622
public IEnumerable<Shared.csharp.Order> History(Guid cartId)
@@ -29,21 +35,36 @@ public Shared.csharp.Order Get(int id)
2935
[HttpPost]
3036
public ActionResult Post([FromBody] Shared.csharp.Order request)
3137
{
32-
var newOrder = new Shared.csharp.Order { CartId = request.CartId, Items = request.Items, OrderPlaced = DateTime.Now, Id = Orders.Count + 1 };
38+
var newOrder = new Shared.csharp.Order {
39+
CartId = request.CartId,
40+
Items = request.Items,
41+
OrderPlaced = DateTime.Now,
42+
Id = Orders.Count + 1,
43+
Status = "Received"
44+
};
3345
Orders.Add(newOrder);
3446
return Json(newOrder);
3547
}
3648

3749
// PUT api/values/5
38-
[HttpPut("{id}")]
39-
public void Put(int id, [FromBody] string value)
40-
{
41-
}
42-
43-
// DELETE api/values/5
44-
[HttpDelete("{id}")]
45-
public void Delete(int id)
50+
[HttpPut("{id}/{status}")]
51+
public ActionResult Put(int id, string status)
4652
{
53+
var order = Orders.First(o => o.Id == id);
54+
if (order == null)
55+
{
56+
return NotFound();
57+
}
58+
else if (order.Status != "Received")
59+
{
60+
return BadRequest();
61+
}
62+
else
63+
{
64+
order.Status = status;
65+
order.LastUpdate = DateTime.Now;
66+
return Ok(order);
67+
}
4768
}
4869
}
4970
}

src/funstore.shared.csharp/Services/OrderProcessingService.cs

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using Microsoft.Extensions.Logging;
2+
using Steeltoe.Common.Discovery;
23
using System;
34
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
65
using System.Net.Http;
7-
using Steeltoe.Common.Discovery;
6+
using System.Threading.Tasks;
87

98
namespace Funstore.Shared.csharp
109
{
@@ -40,5 +39,35 @@ public async Task<List<Order>> GetOrderHistory(Guid cartId)
4039
var result = await Invoke<List<Order>>(request);
4140
return result;
4241
}
42+
43+
public async Task<Order> CancelOrderAsync(int id)
44+
{
45+
var orderUrl = $"{ORDER_URL}/{id}/Cancelled" ;
46+
var request = new HttpRequestMessage(HttpMethod.Put, orderUrl);
47+
var result = await Invoke<Order>(request);
48+
return result;
49+
}
50+
51+
public async Task<List<Order>> GetAllOrders()
52+
{
53+
var request = new HttpRequestMessage(HttpMethod.Get, ORDER_URL);
54+
var result = await Invoke<List<Order>>(request);
55+
return result;
56+
}
57+
58+
/// <summary>
59+
/// This should be an admin-only function
60+
/// </summary>
61+
/// <param name="id"></param>
62+
/// <param name="status"></param>
63+
/// <returns></returns>
64+
public async Task<Order> UpdateOrderAsync(int id, string status)
65+
{
66+
var orderUrl = $"{ORDER_URL}/{id}/{status}";
67+
var request = new HttpRequestMessage(HttpMethod.Put, orderUrl);
68+
var result = await Invoke<Order>(request);
69+
return result;
70+
}
71+
4372
}
4473
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace funstore.web.admin.Controllers
8+
{
9+
public class CartController : Controller
10+
{
11+
public IActionResult Index()
12+
{
13+
return View();
14+
}
15+
}
16+
}

src/funstore.web.admin/Controllers/HomeController.cs

-15
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,6 @@ public IActionResult Index()
1919
return View();
2020
}
2121

22-
public IActionResult Orders()
23-
{
24-
ViewData["Message"] = "View and Process Orders";
25-
26-
return View();
27-
}
28-
29-
public IActionResult Carts()
30-
{
31-
32-
ViewData["Message"] = "View Live Shopping Carts";
33-
34-
return View();
35-
}
36-
3722
public IActionResult Error()
3823
{
3924
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });

src/funstore.web.admin/Controllers/InventoryController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Funstore.Web.Admin.Controllers
66
{
77
public class InventoryController : Controller
88
{
9-
private static List<InventoryItem> items = new List<InventoryItem> {
9+
internal static List<InventoryItem> items = new List<InventoryItem> {
1010
new InventoryItem { Id = 1, Name = "Snowstorm in April", Description = "Enjoy this classic outpouring of snow in the middle of spring time", FontAwesomeIcon = "snowflake" },
1111
new InventoryItem { Id = 2, Name = "Old School Bomb", Description = "Is it a bowling ball with a string attached, or is it a bomb? Order yours today to find out!", FontAwesomeIcon = "bomb" },
1212
new InventoryItem { Id = 3, Name = "git Jokes", Description = "A random assortment of git-related jokes. Free samples include: 'git-fetch: no training required' and 'git happens'", FontAwesomeIcon = "code-branch"},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Funstore.Shared.csharp;
6+
using Funstore.Web.Admin.Controllers;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.Extensions.Logging;
9+
using Steeltoe.Common.Discovery;
10+
11+
namespace funstore.web.admin.Controllers
12+
{
13+
public class OrderController : Controller
14+
{
15+
private OrderProcessingService _orders;
16+
17+
public OrderController(IDiscoveryClient discoClient, ILoggerFactory logFactory)
18+
{
19+
_orders = new OrderProcessingService(discoClient, logFactory);
20+
}
21+
22+
public async Task<IActionResult> Index()
23+
{
24+
ViewData["Message"] = "View and Process Orders";
25+
26+
return View(await _orders.GetAllOrders());
27+
}
28+
29+
[Route("[controller]/[action]/{id}/{status}")]
30+
public async Task<IActionResult> Update(int id, string status)
31+
{
32+
var updated = await _orders.UpdateOrderAsync(id, status);
33+
return RedirectToAction("Index");
34+
}
35+
36+
public async Task<IActionResult> View(int id)
37+
{
38+
var order = await _orders.GetOrderAsync(id);
39+
foreach(var i in order.Items)
40+
{
41+
i.Item = InventoryController.items.First(ii => ii.Id == i.ItemId);
42+
}
43+
return View(order);
44+
}
45+
}
46+
}
+5-103
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,8 @@
11
@{
2-
ViewData["Title"] = "Home Page";
2+
ViewData["Title"] = "Admin Home Page";
33
}
4-
5-
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="6000">
6-
<ol class="carousel-indicators">
7-
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
8-
<li data-target="#myCarousel" data-slide-to="1"></li>
9-
<li data-target="#myCarousel" data-slide-to="2"></li>
10-
<li data-target="#myCarousel" data-slide-to="3"></li>
11-
</ol>
12-
<div class="carousel-inner" role="listbox">
13-
<div class="item active">
14-
<img src="~/images/banner1.svg" alt="ASP.NET" class="img-responsive" />
15-
<div class="carousel-caption" role="option">
16-
<p>
17-
Learn how to build ASP.NET apps that can run anywhere.
18-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525028&clcid=0x409">
19-
Learn More
20-
</a>
21-
</p>
22-
</div>
23-
</div>
24-
<div class="item">
25-
<img src="~/images/banner2.svg" alt="Visual Studio" class="img-responsive" />
26-
<div class="carousel-caption" role="option">
27-
<p>
28-
There are powerful new features in Visual Studio for building modern web apps.
29-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525030&clcid=0x409">
30-
Learn More
31-
</a>
32-
</p>
33-
</div>
34-
</div>
35-
<div class="item">
36-
<img src="~/images/banner3.svg" alt="Package Management" class="img-responsive" />
37-
<div class="carousel-caption" role="option">
38-
<p>
39-
Bring in libraries from NuGet and npm, and automate tasks using Grunt or Gulp.
40-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525029&clcid=0x409">
41-
Learn More
42-
</a>
43-
</p>
44-
</div>
45-
</div>
46-
<div class="item">
47-
<img src="~/images/banner4.svg" alt="Microsoft Azure" class="img-responsive" />
48-
<div class="carousel-caption" role="option">
49-
<p>
50-
Learn how Microsoft's Azure cloud platform allows you to build, deploy, and scale web apps.
51-
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525027&clcid=0x409">
52-
Learn More
53-
</a>
54-
</p>
55-
</div>
56-
</div>
57-
</div>
58-
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
59-
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
60-
<span class="sr-only">Previous</span>
61-
</a>
62-
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
63-
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
64-
<span class="sr-only">Next</span>
65-
</a>
66-
</div>
67-
4+
<h2>@ViewData["Title"].</h2>
685
<div class="row">
69-
<div class="col-md-3">
70-
<h2>Application uses</h2>
71-
<ul>
72-
<li>Sample pages using ASP.NET Core MVC</li>
73-
<li>Theming using <a href="https://go.microsoft.com/fwlink/?LinkID=398939">Bootstrap</a></li>
74-
</ul>
75-
</div>
76-
<div class="col-md-3">
77-
<h2>How to</h2>
78-
<ul>
79-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=398600">Add a Controller and View</a></li>
80-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699315">Manage User Secrets using Secret Manager.</a></li>
81-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699316">Use logging to log a message.</a></li>
82-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699317">Add packages using NuGet.</a></li>
83-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699319">Target development, staging or production environment.</a></li>
84-
</ul>
85-
</div>
86-
<div class="col-md-3">
87-
<h2>Overview</h2>
88-
<ul>
89-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=518008">Conceptual overview of what is ASP.NET Core</a></li>
90-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699320">Fundamentals of ASP.NET Core such as Startup and middleware.</a></li>
91-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=398602">Working with Data</a></li>
92-
<li><a href="https://go.microsoft.com/fwlink/?LinkId=398603">Security</a></li>
93-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699321">Client side development</a></li>
94-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699322">Develop on different platforms</a></li>
95-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699323">Read more on the documentation site</a></li>
96-
</ul>
97-
</div>
98-
<div class="col-md-3">
99-
<h2>Run &amp; Deploy</h2>
100-
<ul>
101-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=517851">Run your app</a></li>
102-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=517853">Run tools such as EF migrations and more</a></li>
103-
<li><a href="https://go.microsoft.com/fwlink/?LinkID=398609">Publish to Microsoft Azure Web Apps</a></li>
104-
</ul>
105-
</div>
106-
</div>
6+
<div class="col-sm-6 text-center"><a asp-controller="order" asp-action="index" class="btn btn-default">View Orders</a></div>
7+
<div class="col-sm-6 text-center"><a asp-controller="inventory" asp-action="index" class="btn btn-default">Manage Inventory</a></div>
8+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@model List<InventoryItem>
2+
@{
3+
ViewData["Title"] = "Inventory Management";
4+
}
5+
<h2>@ViewData["Title"].</h2>
6+
<table class="table">
7+
<thead>
8+
<tr><th>Item Id</th><th>Name</th><th>Description</th><th>Font Awesome Icon</th></tr>
9+
</thead>
10+
<tbody>
11+
@foreach(var i in Model)
12+
{
13+
<tr><td>@i.Id</td><td>@i.Name</td><td>@i.Description</td><td>@i.FontAwesomeIcon <i class="fa [email protected]"></i></td></tr>
14+
}
15+
</tbody>
16+
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@model List<Order>
2+
@{
3+
ViewData["Title"] = "Orders";
4+
}
5+
<h2>@ViewData["Title"].</h2>
6+
<h3>@ViewData["Message"]</h3>
7+
8+
<table class="table table-striped">
9+
<thead>
10+
<th>Order Id</th>
11+
<th>Order Date</th>
12+
<th>Status</th>
13+
<th></th>
14+
</thead>
15+
<tbody>
16+
@if(Model?.Count > 0) {
17+
foreach(var i in Model){
18+
<tr>
19+
<td>@i.Id</td>
20+
<td>@i.OrderPlaced</td>
21+
<td>@i.Status</td>
22+
<td class="text-center">
23+
<a asp-controller="order" asp-action="view" asp-route-id="@i.Id" class="btn btn-primary">View</a>
24+
</td>
25+
</tr>
26+
}
27+
} else {
28+
<tr><td colspan="4">No orders yet, go have some fun!</td></tr>
29+
}
30+
</tbody>
31+
</table>

0 commit comments

Comments
 (0)