예제 #1
0
        private Order CreateOrder(DateTime orderDate)
        {
            DateTime estimatedTakeOff = orderDate.AddDays(new Random().Next(7));
            DateTime estimatedLanding = estimatedTakeOff.AddHours(new Random().Next(7));

            var orderLineItems = new List<OrderLineItemDto>();
            int items = new Random().Next(30);
            if (items == 0) items++;
            for (int i = 0; i < items; i++)
            {
                var lineItemDto = new OrderLineItemDto();
                lineItemDto.ItemId = _itemIds[new Random(i).Next(_itemIds.Length)];
                lineItemDto.CurrencyId = _currencyIds[new Random(i).Next(_currencyIds.Length)];
                lineItemDto.Units = new Random(i).Next(1, 20);
                lineItemDto.Instructions = "Psylum Huft.....";
                if (!IsItemExists(orderLineItems, lineItemDto.ItemId))
                    orderLineItems.Add(lineItemDto);
            }

            // The 3rd parameter is the buyer index in the contract. It could be 0 or 1.
            int buyerIndex = new Random().Next(0, 2);
            if (buyerIndex != 0 && buyerIndex != 1)
                buyerIndex = 1;

            return
                _ordersRepository.Create(new OrderSettings(orderDate,
                                                           _contractIds[new Random(items).Next(_contractIds.Length)],
                                                           buyerIndex, // Should be 0 or 1
                                                           null, null,
                                                           _airportIds[new Random(items).Next(_airportIds.Length)],
                                                           _airportIds[new Random(items).Next(_airportIds.Length)],
                                                           _aircraftIds[new Random(items).Next(_aircraftIds.Length)],
                                                           _operators[new Random(items).Next(_operators.Length)],
                                                           Utilities.GenerateRandomNumber(4).ToUpper(), estimatedTakeOff,
                                                           estimatedLanding, orderLineItems));
        }
예제 #2
0
        private void QuoteOrder(Order order, DateTime quoteDate)
        {
            var lineItemDtos = new List<OrderLineItemDto>();
            foreach (OrderLineItem lineItem in order.LineItems)
            {
                var lineItemDto = new OrderLineItemDto();
                lineItemDto.ItemId = lineItem.Item.Id;
                lineItemDto.Units = lineItem.Units;
                lineItemDto.CurrencyId = lineItem.Currency.Id;
                lineItemDto.PricePerUnit = Utilities.GenerateRandomAmount(lineItemDto.ItemId, 500);
                lineItemDtos.Add(lineItemDto);
            }

            _ordersRepository.Quote(order.Id, quoteDate, lineItemDtos);
        }
예제 #3
0
        public OrderViewModel(int traderId, Order order)
        {
            Id = order.Id;
            OrderDate = order.OrderDate;
            QuotationDate = order.QuotationDate;
            ApprovalDate = order.ApprovalDate;
            FulfilmentDate = order.FulfilmentDate;

            Status = "Submitted";
            if (order.Status == Order.Submitted)
                Status = "Submitted";
            else if (order.Status == Order.Quoted)
                Status = "Quoted";
            else if (order.Status == Order.Approved)
                Status = "Approved";
            else if (order.Status == Order.Fulfilled)
                Status = "Fulfilled";

            Amount = order.Amount / order.GlobalPivotExchangeRate;
            AdminFee = order.AdminFee / order.GlobalPivotExchangeRate;

            TakeoffAirport = order.TakeoffAirport.Name;
            LandingAirport = order.LandingAirport.Name;
            Aircraft = order.Aircraft.Manufacturer;
            Operator = order.Operator;
            FlightNumber = order.FlightNumber;
            EstimatedTakeoffTime = order.EstimatedTakeoffTime;
            EstimatedLandingTime = order.EstimatedLandingTime;

            AircraftId = order.Aircraft.Id;
            TakeoffAirportId = order.TakeoffAirport.Id;
            LandingAirportId = order.LandingAirport.Id;

            BuyerId = order.Buyer.Id;
            Buyer = order.Buyer.Name;
            SellerId = order.Seller.Id;
            Seller = order.Seller.Name;

            IsSeller = order.Seller.Id == traderId;
            IsViewed = false; // Please see comments above

            IsQuoted = order.IsQuoted;
            IsApproved = order.IsApproved;
            IsFulfilled = order.IsFulfilled;

            Contract = new ContractViewModel(traderId, order.Contract);

            LineItems = new List<OrderLineItemDto>();
            foreach (OrderLineItem lineItem in order.LineItems)
            {
                var dto = new OrderLineItemDto();
                dto.ItemId = lineItem.Item.Id;
                dto.Category = lineItem.Item.Category;
                dto.SubCategory = lineItem.Item.SubCategory;
                dto.Item = lineItem.Item.Name;
                dto.Units = lineItem.Units;
                dto.Unit = lineItem.Item.Unit;
                dto.CurrencyId = lineItem.Currency.Id;
                dto.PricePerUnit = lineItem.PricePerUnit / lineItem.GlobalPivotExchangeRate;
                dto.Amount = dto.PricePerUnit * dto.Units;
                dto.Instructions = lineItem.Instructions;
                LineItems.Add(dto);
            }
        }