Repository navigation
Expand file tree
/
Copy pathManageShipsController.cs
More file actions
79 lines (67 loc) · 2.57 KB
/
Copy pathManageShipsController.cs
File metadata and controls
79 lines (67 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Diagnostics;
using System.Threading.Tasks;
using AspNetCoreMvcApp.BusRequestSenders;
using AspNetCoreMvcApp.Models;
using CoreDdd.Commands;
using CoreDdd.Queries;
using CoreDddShared.Commands;
using CoreDddShared.Dtos;
using CoreDddShared.Queries;
using Microsoft.AspNetCore.Mvc;
namespace AspNetCoreMvcApp.Controllers
{
public class ManageShipsController : Controller
{
private readonly ICommandExecutor _commandExecutor;
private readonly IQueryExecutor _queryExecutor;
private readonly IBusRequestSender _busRequestSender;
public ManageShipsController(
ICommandExecutor commandExecutor,
IQueryExecutor queryExecutor,
IBusRequestSender busRequestSender
)
{
_queryExecutor = queryExecutor;
_commandExecutor = commandExecutor;
_busRequestSender = busRequestSender;
}
public async Task<IActionResult> Index()
{
var shipDtos = await _queryExecutor.ExecuteAsync<GetAllShipsQuery, ShipDto>(new GetAllShipsQuery());
return View(shipDtos);
}
public IActionResult CreateNewShip()
{
return View();
}
[HttpPost]
public async Task<IActionResult> CreateNewShip(CreateNewShipCommand createNewShipCommand)
{
var createdShipId = 0;
_commandExecutor.CommandExecuted += args => createdShipId = (int) args.Args;
await _commandExecutor.ExecuteAsync(createNewShipCommand);
return RedirectToAction("CreateNewShip", new { lastCreatedShipId = createdShipId });
}
public IActionResult UpdateShip()
{
return View();
}
[HttpPost]
public async Task<IActionResult> UpdateShip(UpdateShipCommand updateShipCommand)
{
await _commandExecutor.ExecuteAsync(updateShipCommand);
return RedirectToAction("UpdateShip");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
[HttpPost]
public async Task<IActionResult> CreateNewShipReliably(CreateNewShipCommand createNewShipCommand)
{
var reply = await _busRequestSender.SendRequest<CreateNewShipCommandReply>(createNewShipCommand);
return RedirectToAction("CreateNewShip", new { lastCreatedShipId = reply.CreatedShipId });
}
}
}