You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.2 KiB
125 lines
4.2 KiB
using AutoMapper;
|
|
using Kean.Application.Command.Interfaces;
|
|
using Kean.Application.Command.ViewModels;
|
|
using Kean.Domain;
|
|
using Kean.Domain.Order.Commands;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Application.Command.Implements
|
|
{
|
|
/// <summary>
|
|
/// 订单命令服务实现
|
|
/// </summary>
|
|
public class OrderService : IOrderService
|
|
{
|
|
private readonly ICommandBus _bus; // 命令总线
|
|
private readonly IMapper _mapper; // 模型映射
|
|
private readonly INotification _notifications; // 总线通知
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public OrderService(
|
|
ICommandBus bus,
|
|
IMapper mapper,
|
|
INotification notifications)
|
|
{
|
|
_bus = bus;
|
|
_mapper = mapper;
|
|
_notifications = notifications;
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.CreateType 方法
|
|
*/
|
|
public async Task<(int Id, Failure Failure)> CreateType(Ordtyp type)
|
|
{
|
|
var command = _mapper.Map<CreateTypeCommand>(type);
|
|
await _bus.Execute(command);
|
|
return (command.Id, _notifications.FirstOrDefault());
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.ModifyType 方法
|
|
*/
|
|
public async Task<(bool Success, Failure Failure)> ModifyType(Ordtyp type)
|
|
{
|
|
await _bus.Execute(_mapper.Map<ModifyTypeCommand>(type));
|
|
var failure = _notifications.FirstOrDefault();
|
|
return (failure == null, failure);
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.DeleteType 方法
|
|
*/
|
|
public async Task<(bool Success, Failure Failure)> DeleteType(int id)
|
|
{
|
|
await _bus.Execute(new DeleteTypeCommand { Id = id });
|
|
var failure = _notifications.FirstOrDefault();
|
|
return (failure == null, failure);
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.CreateFlow 方法
|
|
*/
|
|
public async Task<(int Id, Failure Failure)> CreateFlow(Flow flow)
|
|
{
|
|
var command = _mapper.Map<CreateFlowCommand>(flow);
|
|
await _bus.Execute(command);
|
|
return (command.Id, _notifications.FirstOrDefault());
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.ModifyFlow 方法
|
|
*/
|
|
public async Task<(bool Success, Failure Failure)> ModifyFlow(Flow flow)
|
|
{
|
|
await _bus.Execute(_mapper.Map<ModifyFlowCommand>(flow));
|
|
var failure = _notifications.FirstOrDefault();
|
|
return (failure == null, failure);
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.DeleteFlow 方法
|
|
*/
|
|
public async Task<(bool Success, Failure Failure)> DeleteFlow(int id)
|
|
{
|
|
await _bus.Execute(new DeleteFlowCommand { Id = id });
|
|
var failure = _notifications.FirstOrDefault();
|
|
return (failure == null, failure);
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.CreateOrder 方法
|
|
*/
|
|
public async Task<(int Id, Failure Failure)> CreateOrder(Order order)
|
|
{
|
|
var command = _mapper.Map<CreateOrderCommand>(order);
|
|
await _bus.Execute(command);
|
|
return (command.Id, _notifications.FirstOrDefault());
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.ModifyOrder 方法
|
|
*/
|
|
public async Task<(bool Success, Failure Failure)> ModifyOrder(Order order)
|
|
{
|
|
await _bus.Execute(_mapper.Map<ModifyOrderCommand>(order));
|
|
var failure = _notifications.FirstOrDefault();
|
|
return (failure == null, failure);
|
|
}
|
|
|
|
/*
|
|
* 实现 Kean.Application.Command.Interfaces.IOrderService.DeleteOrder 方法
|
|
*/
|
|
public async System.Threading.Tasks.Task DeleteOrder(int id, bool state)
|
|
{
|
|
await _bus.Execute(new DeleteOrderCommand
|
|
{
|
|
Id = id,
|
|
State = state
|
|
});
|
|
}
|
|
}
|
|
}
|