-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrderController.cs
46 lines (42 loc) · 1.46 KB
/
OrderController.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MassTransit;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using order_ms.Repository;
using order_ms.ViewModel;
using rabbitmq_bus;
using rabbitmq_msg;
namespace order_ms.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class OrderController : ControllerBase
{
private readonly ISendEndpointProvider _sendEndpointProvider;
private readonly IOrderDataAccess _orderDataAccess;
public OrderController(ISendEndpointProvider sendEndpointProvider, IOrderDataAccess orderDataAccess)
{
_sendEndpointProvider = sendEndpointProvider;
_orderDataAccess = orderDataAccess;
}
[HttpPost]
[Route("createorder")]
public async Task<IActionResult> CreateOrder(OrderModel orderModel)
{
orderModel.OrderId = new Guid();
_orderDataAccess.SaveOrder(orderModel);
var endPoint = await _sendEndpointProvider.
GetSendEndpoint(new Uri("queue:" + BusConstants.OrderQueue));
await endPoint.Send<IOrderMessage>(new
{
OrderId = orderModel.OrderId,
ProductName = orderModel.ProductName,
PaymentCardNumber = orderModel.CardNumber
});
return Ok("success");
}
}
}