-
Notifications
You must be signed in to change notification settings - Fork 2
/
HomeController.cs
87 lines (72 loc) · 2.37 KB
/
HomeController.cs
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
80
81
82
83
84
85
86
87
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using CQRS.MVC.Models;
using CQRS.Domain.Queries.Handler;
using CQRS.Domain.Queries;
using CQRS.Domain.Commands;
using CQRS.Domain.Queries.Query;
using System.Threading.Tasks;
using CQRS.Data;
using System.Collections.Generic;
using CQRS.Domain.Commands.Command;
using CQRS.Domain.Pipelines;
using CQRS.Domain;
namespace CQRS.MVC.Controllers
{
public class HomeController : Controller
{
Messages _messages;
CreateUserPipelineBuilder _createUserPipelineBuilder;
public HomeController(CreateUserPipelineBuilder createUserPipelineBuilder,
Messages messages)
{
_createUserPipelineBuilder = createUserPipelineBuilder;
_messages = messages;
}
[HttpGet]
public async Task<IActionResult> GetUsers()
{
var query = new AllUsersQuery();
var users = await _messages.Dispatch(query);
return Ok(users);
}
[HttpGet]
public async Task<IActionResult> GetUser(string name)
{
var query = new OneUserQuery { Name = name };
var user = await _messages.Dispatch(query);
return Ok(user);
}
[HttpPost]
public async Task<IActionResult> AddUser(string name, string password)
{
var command = new SaveUserCommand(new User { Name = name }, password);
command = await _createUserPipelineBuilder.ProcessAsync(command);
var cResponse = await _messages.Dispatch(command);
return Ok(cResponse);
}
public IActionResult Index()
{
return View();
}
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
}
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}