Пример #1
0
        public OrderStatus GetOrderStatusByValue(OrderStatuses value)
        {
            var orderStatus = orderStatusesRepository.GetOrderStatusByValue(value);

            return(orderStatus);
        }
Пример #2
0
        public bool ConfirmAbortOrder(int orderId, string userId)
        {
            var order = GetOrder(orderId, i => i.CurrentStatus, i => i.StatusLogs, i => i.Transactions, i => i.Middleman, id => id.Transactions.Select(m => m.Sender), id => id.Transactions.Select(m => m.Receiver));

            if (order != null)
            {
                OrderStatus newOrderStatus = null;
                if (order.MiddlemanId == userId && order.CurrentStatus.Value == OrderStatuses.MiddlemanBackingAccount)
                {
                    newOrderStatus = orderStatusRepository.GetOrderStatusByValue(OrderStatuses.MiddlemanClosed);
                    if (newOrderStatus != null)
                    {
                        var orderTransactions = order.Transactions.ToList();

                        foreach (var transaction in orderTransactions)
                        {
                            transaction.Sender.Balance   += transaction.Amount;
                            transaction.Receiver.Balance -= transaction.Amount;

                            order.Transactions.Add(new Transaction
                            {
                                Receiver        = transaction.Sender,
                                Sender          = transaction.Receiver,
                                Amount          = transaction.Amount,
                                TransactionDate = DateTime.Now
                            });
                        }

                        order.StatusLogs.AddLast(new StatusLog()
                        {
                            OldStatus = order.CurrentStatus,
                            NewStatus = newOrderStatus,
                            TimeStamp = DateTime.Now
                        });
                        order.CurrentStatus = newOrderStatus;
                        order.BuyerChecked  = false;
                        order.SellerChecked = false;
                        return(true);
                    }
                }
            }
            return(false);
        }