public async Task Win(int lotId, int dispatcherId) { var lot = await Get(lotId); if (lot == null) { throw new EntityNotFoundException($"LotrId:{lotId} not found", "Lot"); } if (lot.Status != LotStatus.Traded) { throw new LotStatusException("Only traded lots can be won"); } if ((await OrderStateService.GetCurrentState(lot.OrderId)).Status != OrderStatus.SentToTrading) { throw new LotStatusException("Only traded orders can be won"); } if (!await DispatcherService.IsExist(dispatcherId)) { throw new EntityNotFoundException($"DispatcherId:{dispatcherId} not found", "Dispatcher"); } lot.WinnerDispatcherId = dispatcherId; lot.Status = LotStatus.Won; await Repository.Update(lot); await Repository.Save(); await OrderStateService.AssignToDispatcher(lot.OrderId, lot.WinnerDispatcherId); }
public async Task <ICollection <OrderGroupAM> > GetOrderGroupsByStatuses(OrderStatus[] statuses) { var result = new List <OrderGroupAM>(); var exceptions = new ConcurrentQueue <Exception>(); await statuses.ParallelForEachAsync( async status => { try { var stateOrderCount = await OrderStateService.GetCountByCurrentStatus(status); var group = new OrderGroupAM { Status = status, Count = stateOrderCount }; result.Add(group); } catch (Exception e) { exceptions.Enqueue(e); } } ); if (exceptions.Any()) { throw new AggregateException(exceptions); } result = result.OrderBy(o => Array.IndexOf(statuses, o.Status)).ToList(); return(result); }
public async Task <ICollection <Order> > GetDomainOrdersByStatus(OrderStatus status) { var ordersStates = await OrderStateService.GetByCurrentStatus(status); var ordersIdArray = ordersStates.Select(s => s.OrderId).ToArray(); return(await DomainOrderService.Get(ordersIdArray)); }
public GetPizzaViewModel(HttpClient httpClient, OrderStateService orderStateService) { this.httpClient = httpClient; this.orderStateService = orderStateService; ConfiguringPizzaDialog = new ConfigurePizzaDialogViewModel(httpClient); ConfiguringPizzaDialog.OnConfigured += AddPizza; }
protected override async Task <bool> DoVerifyEntity(Lot entity) { if (!await OrderStateService.IsExist(entity.OrderId)) { throw new EntityNotFoundException($"OrderId:{entity.OrderId} not found", "Order"); } return(true); }
public OrderStateServiceTestSuite() { OrderStateRepositoryMock = new Mock <IOrderStateRepository>(); OrderServiceMock = new Mock <IOrderService>(); ModeratorServiceMock = new Mock <IModeratorService>(); DispatcherServiceMock = new Mock <IDispatcherService>(); DriverServiceMock = new Mock <IDriverService>(); OrderStateService = new OrderStateService( OrderStateRepositoryMock.Object, OrderServiceMock.Object, ModeratorServiceMock.Object, DispatcherServiceMock.Object, DriverServiceMock.Object); }
public async Task Trade(int lotId) { var lot = await Get(lotId); if (lot == null) { throw new EntityNotFoundException($"LotrId:{lotId} not found", "Lot"); } if ((lot.Status != LotStatus.New) && (lot.Status != LotStatus.Expired)) { throw new LotStatusException("Only active or expired lots can be traded"); } await OrderStateService.Trade(lot.OrderId); lot.Status = LotStatus.Traded; await Repository.Update(lot); await Repository.Save(); }
protected async Task <Lot> Create(int orderId) { var lot = new Lot { OrderId = orderId }; await Verify(lot); if ((await OrderStateService.GetCurrentState(orderId)).Status != OrderStatus.ReadyForTrade) { throw new LotStatusException("Only for ready for trade orders can be created a lot"); } lot.Status = LotStatus.New; await Repository.Add(lot); await Repository.Save(); return(lot); }
public async Task <Order> CreateOrder(BookingAM booking) { using (var transaction = await TransactionService.BeginTransaction()) { try { var domainCustomer = await CustomerService.GetDomainCustomer(booking.Customer); var domainCargo = await CargoService.CreateDomainCargo(booking.Cargo); var domainBill = await BillService.CreateDomainBill(booking.BillInfo, booking.Basket); var route = await RouteService.GetRoute(booking.RootAddress, booking.Waypoints); var domainRoute = await RouteService.CreateDomainRoute(route); var result = await DomainOrderService.Create( booking.OrderTime, domainCustomer.Id, domainCargo.Id, domainRoute.Id, domainBill.Id); await OrderStateService.New(result.Id); transaction.Commit(); return(result); } catch { transaction.Rollback(); throw; } } }
public CheckoutViewModel(HttpClient httpClient, OrderStateService orderStateService) { this.httpClient = httpClient; this.orderStateService = orderStateService; }
public async Task LaunchTrading() { var ordersState = await OrderStateService.GetByCurrentStatus(OrderStatus.ReadyForTrade); await Task.WhenAll(ordersState.Select(state => Trade(state.OrderId))); }