public async Task ReadyToTrade(int orderId, int moderatorId)
        {
            var order = await OrderService.Get(orderId);

            if (order == null)
            {
                throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order");
            }

            if ((await GetCurrentState(orderId)).Status != OrderStatus.Accepted)
            {
                throw new OrderStatusException("Only accepted orders can be read for trade");
            }

            if (!await ModeratorService.IsExist(moderatorId))
            {
                throw new EntityNotFoundException($"ModeratorId:{moderatorId} not found", "Moderator");
            }

            if (!order.ModeratorId.Equals(moderatorId))
            {
                throw new AccessViolationException($"Only a order moderator can change the order state. Order moderatorId:{order.ModeratorId}, function moderatorId:{moderatorId}");
            }

            await SetCurrentStatus(orderId, OrderStatus.ReadyForTrade);
        }
示例#2
0
        public async Task AssignModerator(int orderId, int moderatorId)
        {
            var order = await Get(orderId);

            if (order == null)
            {
                throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order");
            }

            if (!await ModeratorService.IsExist(moderatorId))
            {
                throw new EntityNotFoundException($"ModeratorId:{moderatorId} not found", "Moderator");
            }

            order.ModeratorId = moderatorId;
            await Repository.Update(order);

            await Repository.Save();
        }
        public async Task Accept(int orderId, int moderatorId)
        {
            var order = await OrderService.Get(orderId);

            if (order == null)
            {
                throw new EntityNotFoundException($"OrderId:{orderId} not found", "Order");
            }

            if (!await ModeratorService.IsExist(moderatorId))
            {
                throw new EntityNotFoundException($"ModeratorId:{moderatorId} not found", "Moderator");
            }

            if ((await GetCurrentState(orderId)).Status != OrderStatus.New)
            {
                throw new OrderStatusException("Only new orders can be accepted");
            }

            await SetCurrentStatus(orderId, OrderStatus.Accepted);

            await OrderService.AssignModerator(orderId, moderatorId);
        }