public async Task AssignToDispatcher(int orderId, int dispatcherId) { var order = await OrderService.Get(orderId); if (order == null) { throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order"); } if (!await DispatcherService.IsExist(dispatcherId)) { throw new EntityNotFoundException($"DispatcherId:{dispatcherId} not found", "Dispatcher"); } var currentState = await GetCurrentState(orderId); if ((currentState.Status != OrderStatus.Accepted) && (currentState.Status != OrderStatus.SentToTrading)) { throw new OrderStatusException("Only accepted or traded orders can be assigned to dispatcher"); } await SetCurrentStatus(orderId, OrderStatus.AssignedDispatcher); await OrderService.AssignDispatcher(orderId, dispatcherId); }
public async Task AssignToDriver(int orderId, int dispatcherId, int driverId) { var order = await OrderService.Get(orderId); if (order == null) { throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order"); } if (!await DispatcherService.IsExist(dispatcherId)) { throw new EntityNotFoundException($"DispatcherId:{dispatcherId} not found", "Dispatcher"); } if (order.DispatcherId != dispatcherId) { throw new AccessViolationException("Only a order dispatcher can assign a order to driver"); } if (!await DriverService.IsExist(driverId)) { throw new EntityNotFoundException($"DriverId:{driverId} not found", "Driver"); } if ((await GetCurrentState(orderId)).Status != OrderStatus.AssignedDispatcher) { throw new OrderStatusException("Only assigned to dispatcher orders can be assigned to driver"); } await SetCurrentStatus(orderId, OrderStatus.AssignedDriver); await OrderService.AssignDriver(orderId, driverId); }
public async Task AssignDispatcher(int orderId, int dispatcherId) { var order = await Get(orderId); if (order == null) { throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order"); } if (!await DispatcherService.IsExist(dispatcherId)) { throw new EntityNotFoundException($"DispatcherId:{dispatcherId} not found", "Dispatcher"); } order.DispatcherId = dispatcherId; await Repository.Update(order); await Repository.Save(); }