Exemplo n.º 1
0
        public void OrderHasReturnDocumentFailNotShipped()
        {
            _orderManagerQuery.Setup(s => s.GetOrder(_orderId)).Returns(new Order {
                OrderId = _orderId, CustomerId = _customerId
            });
            _customerManager.Setup(s => s.GetCustomer(_customerId)).Returns(new Customer {
                ShippingCountry = "US United States"
            });
            _manager = new ReturnsManager(_orderManagerQuery.Object, _customerManager.Object);

            var historyOrder = new HistoryOrder
            {
                OrderID     = _orderId,
                OrderStatus = "Processing",
                Shipments   = new List <HistoryOrderShipment>
                {
                    new HistoryOrderShipment {
                        DateShipped = DateTime.Now.AddDays(-1)
                    }
                }
            };

            var flag = _manager.OrderHasReturnDocument(historyOrder);

            Assert.IsFalse(flag);
        }
        public IHttpActionResult PutHistoryOrder(int id, HistoryOrder historyOrder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != historyOrder.HistId)
            {
                return(BadRequest());
            }

            db.Entry(historyOrder).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HistoryOrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetHistoryOrder(int id)
        {
            HistoryOrder historyOrder = db.HistoryOrders.Find(id);

            if (historyOrder == null)
            {
                return(NotFound());
            }

            return(Ok(historyOrder));
        }
        public IHttpActionResult PostHistoryOrder(HistoryOrder historyOrder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.HistoryOrders.Add(historyOrder);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = historyOrder.HistId }, historyOrder));
        }
        public IHttpActionResult DeleteHistoryOrder(int id)
        {
            HistoryOrder historyOrder = db.HistoryOrders.Find(id);

            if (historyOrder == null)
            {
                return(NotFound());
            }

            db.HistoryOrders.Remove(historyOrder);
            db.SaveChanges();

            return(Ok(historyOrder));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Used to retrieve your order history for a specific market.
        /// </summary>
        /// <param name="market">a string literal for the market (ie. BTC-LTC).</param>
        /// <returns></returns>
        public static List <HistoryOrder> GetOrderHistory(string market)
        {
            List <HistoryOrder> historyOrdersList = new List <HistoryOrder>();

            string url = Constants.baseUrl + "account/getorderhistory?apikey=" + Constants.ApiKey + "&market=" + market + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    Console.WriteLine("*Unable to get balances" + "\n" +
                                      "Error: " + response.message + "\n"
                                      );
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            foreach (var item in response.result)
            {
                string orderUuid         = item.OrderUuid.ToString();
                string exchange          = item.Exchange.ToString();
                string timeStamp         = item.TimeStamp.ToString();
                string ordertype         = item.OrderType.ToString();
                string limit             = item.Limit.ToString();
                string quantity          = item.Quantity.ToString();
                string quantityRemaining = item.QuantityRemaining.ToString();
                string commission        = item.Commission.ToString();
                string price             = item.Price.ToString();
                string pricePerUnit      = item.PricePerUnit.ToString();
                string isConditional     = item.IsConditional.ToString();
                string condition         = item.Condition.ToString();
                string conditionTarget   = item.ConditionTarget.ToString();
                string immediateOrCancel = item.ImmediateOrCancel.ToString();

                HistoryOrder order = new HistoryOrder(orderUuid, exchange, timeStamp, ordertype, limit, quantity, quantityRemaining, commission, price, pricePerUnit, isConditional, condition, conditionTarget,
                                                      immediateOrCancel);

                historyOrdersList.Add(order);
            }

            return(historyOrdersList);
        }
Exemplo n.º 7
0
        public void OrderHasReturnDocumentFailNoShipments()
        {
            _orderManagerQuery.Setup(s => s.GetOrder(_orderId)).Returns(new Order {
                OrderId = _orderId, CustomerId = _customerId
            });
            _customerManager.Setup(s => s.GetCustomer(_customerId)).Returns(new Customer {
                ShippingCountry = "US United States"
            });
            _manager = new ReturnsManager(_orderManagerQuery.Object, _customerManager.Object);

            var historyOrder = new HistoryOrder
            {
                OrderID     = _orderId,
                OrderStatus = "Shipped"
            };

            var flag = _manager.OrderHasReturnDocument(historyOrder);

            Assert.IsFalse(flag);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes the tasks.
        /// </summary>
        /// <param name='version'>
        /// The version containing the tasks.
        /// </param>
        /// <param name='sortOrder'>
        /// The order to write the tasks in.
        /// </param>
        private void WriteTasks(VersionBase version, HistoryOrder sortOrder)
        {
            IEnumerable <Task> sortedTasks;

            if (sortOrder == HistoryOrder.asc || sortOrder == HistoryOrder.Ascending)
            {
                sortedTasks = version.Tasks.OrderBy(t => t.ExecutionOrder);
            }
            else
            {
                sortedTasks = version.Tasks.OrderByDescending(t => t.ExecutionOrder);
            }

            foreach (var task in sortedTasks)
            {
                string taskString = string.Format(
                    "  {0} - {1}",
                    task.Name,
                    task.UpdatedOnLocal);

                this.MessageService.WriteLine(taskString);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// This method checks to see if an order in the history should have a Return Document.
        /// Business Rules Are: order has shipped within USA and shipped within 45 days
        /// </summary>
        /// <param name="historyOrder"></param>
        /// <returns></returns>
        public bool OrderHasReturnDocument(HistoryOrder historyOrder)
        {
            var hasReturnPdf = false;

            if (!historyOrder.Wholesale && !historyOrder.Dropship)
            {
                var shipped = (historyOrder.OrderStatus.ToLower() == "shipped") && historyOrder.Shipments != null &&
                              historyOrder.Shipments.Count > 0;
                if (shipped)
                {
                    var shipment = historyOrder.Shipments.FirstOrDefault();
                    if (shipment != null)
                    {
                        var daysSinceShipped = (DateTime.Now - shipment.DateShipped).Days;
                        if (daysSinceShipped <= 45)
                        {
                            var order = _orderManagerQuery.GetOrder(historyOrder.OrderID);
                            if (order != null)
                            {
                                var customer = _customerManager.GetCustomer(order.CustomerId);
                                if (customer != null)
                                {
                                    var shippingCountry = customer.ShippingCountry.Substring(0, 2);
                                    //if (shippingCountry == "US")
                                    if (shippingCountry == CountryType.UnitedStates.ToString())
                                    {
                                        hasReturnPdf = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return hasReturnPdf;
        }
 internal void AddHistory(HistoryOrder historyOrder)
 {
     context.HistoryOrders.Add(historyOrder);
     context.SaveChanges();
 }
 public HistoryOrderItemVM(HistoryOrder order)
 {
     Order = order;
 }
Exemplo n.º 12
0
        private static string CreateExpectedOutput(IEnumerable <ClassicVersion> versions, HistoryOrder sortOrder = HistoryOrder.Descending, bool showTasks = false)
        {
            StringBuilder builder = new StringBuilder();

            IEnumerable <ClassicVersion> sortedVersions;

            if (sortOrder == HistoryOrder.asc || sortOrder == HistoryOrder.Ascending)
            {
                sortedVersions = versions.OrderBy(v => v.Version);
            }
            else
            {
                sortedVersions = versions.OrderByDescending(v => v.Version);
            }

            foreach (var version in sortedVersions)
            {
                builder.AppendLine(
                    string.Format(
                        "{0} Installed - {1}, Updated - {2}",
                        version.VersionText,
                        version.CreatedOnLocal,
                        version.UpdatedOnLocal));

                if (showTasks)
                {
                    IEnumerable <Task> sortedTasks;
                    if (sortOrder == HistoryOrder.asc || sortOrder == HistoryOrder.Ascending)
                    {
                        sortedTasks = version.Tasks.OrderBy(t => t.ExecutionOrder);
                    }
                    else
                    {
                        sortedTasks = version.Tasks.OrderByDescending(t => t.ExecutionOrder);
                    }

                    foreach (var task in sortedTasks)
                    {
                        builder.AppendLine(
                            string.Format(
                                "  {0} - {1}",
                                task.Name,
                                task.UpdatedOnLocal));
                    }
                }
            }

            return(builder.ToString());
        }
Exemplo n.º 13
0
        internal void AddHistory(string key, string idConmpany, string idOrder, string idVech, string idDriver, string action)
        {
            HistoryOrder historyOrder = new HistoryOrder();
            int          idUser       = _sqlEntityFramworke.GetUserIdByKey(key);

            if (action == "Assign")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //string fullNameDriver = _sqlEntityFramworke.GetFullNameDriverById(idDriver);
                //historyOrder.Action = $"{fullNameUser} assign the driver ordered {fullNameDriver}";
                historyOrder.TypeAction = "Assign";
            }
            else if (action == "Unassign")
            {
                idDriver = _sqlEntityFramworke.GetDriverIdByIdOrder(idOrder);
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //string fullNameDriver = _sqlEntityFramworke.GetFullNameDriverById(idDriver);
                //historyOrder.Action = $"{fullNameUser} withdrew an order from {fullNameDriver} driver";
                historyOrder.TypeAction = "Unassign";
            }
            else if (action == "Solved")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //historyOrder.Action = $"{fullNameUser} clicked on the \"Solved\" button";
                historyOrder.TypeAction = "Solved";
            }
            else if (action == "ArchivedOrder")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //historyOrder.Action = $"{fullNameUser} transferred the order to the archive";
                historyOrder.TypeAction = "ArchivedOrder";
            }
            else if (action == "DeletedOrder")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //historyOrder.Action = $"{fullNameUser} transferred the order to deleted orders";
                historyOrder.TypeAction = "DeletedOrder";
            }
            else if (action == "Creat")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //historyOrder.Action = $"{fullNameUser} created an order";
                historyOrder.TypeAction = "Creat";
            }
            else if (action == "SavaOrder")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //historyOrder.Action = $"{fullNameUser} edited the order";
                historyOrder.TypeAction = "SavaOrder";
            }
            else if (action == "SavaVech")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                idOrder = _sqlEntityFramworke.GetIdOrderByIdVech(idVech);
                //VehiclwInformation vehiclwInformation = _sqlEntityFramworke.GetVechById(idVech);
                //historyOrder.Action = $"{fullNameUser} edited the vehicle {vehiclwInformation.Year} {vehiclwInformation.Make} {vehiclwInformation.Make}";
                historyOrder.TypeAction = "SavaVech";
            }
            else if (action == "RemoveVech")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                idOrder = _sqlEntityFramworke.GetIdOrderByIdVech(idVech);
                //VehiclwInformation vehiclwInformation = _sqlEntityFramworke.GetVechById(idVech);
                //historyOrder.Action = $"{fullNameUser} removed the vehicle {vehiclwInformation.Year} {vehiclwInformation.Make} {vehiclwInformation.Make}";
                historyOrder.TypeAction = "RemoveVech";
            }
            else if (action == "AddVech")
            {
                //string fullNameUser = _sqlEntityFramworke.GetFullNameUserByKey(key);
                //historyOrder.Action = $"{fullNameUser} created a vehicle";
                historyOrder.TypeAction = "AddVech";
            }

            historyOrder.IdConmpany = Convert.ToInt32(idConmpany);
            historyOrder.IdDriver   = Convert.ToInt32(idDriver);
            historyOrder.IdOreder   = Convert.ToInt32(idOrder);
            historyOrder.IdVech     = Convert.ToInt32(idVech);
            historyOrder.IdUser     = idUser;
            historyOrder.DateAction = DateTime.Now.ToString();
            _sqlEntityFramworke.AddHistory(historyOrder);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Record the current state of the simulation for analysis purposes
        /// </summary>
        private void RecordSimulationStep()
        {
            var simHistoryStep = new SimulationHistoryStep()
            {
                SimulationStep = SimulationStep,
                Vehicles       = new List <VehicleStepState>(),
                OpenOrders     = new List <HistoryOrder>(),
                ClosedOrders   = new List <HistoryCompletedOrder>()
            };

            foreach (var vehicle in Vehicles)
            {
                if (vehicle != null)
                {
                    var vehicleState = new VehicleStepState(vehicle.Vehicle)
                    {
                        State                 = vehicle.State,
                        PathToTarget          = vehicle.PathToTarget?.Select(p => p.Info.Name).ToList(),
                        CurrentVertexPosition = vehicle.CurrentVertexPosition?.Info?.Name,
                        CurrentTarget         = vehicle.CurrentTarget?.Info?.Name,
                        CurrentOrders         = new List <HistoryCompletedOrder>(vehicle.CurrentOrders?.Select(o =>
                                                                                                               new HistoryCompletedOrder(new HistoryOrder
                        {
                            Start         = o?.Start?.Info?.Name,
                            Target        = o?.Target?.Info?.Name,
                            PayloadWeight = o?.PayloadWeight
                        },
                                                                                                                                         o?.DeliveryTime,
                                                                                                                                         o?.DeliveryDistance,
                                                                                                                                         o?.DeliveryCost,
                                                                                                                                         o?.PickupTime,
                                                                                                                                         o?.PickupDistance,
                                                                                                                                         o?.PickupCost,
                                                                                                                                         o?.DeliveryPath?.Select(p => p.Info.Name).ToList())) ??
                                                                                 Array.Empty <HistoryCompletedOrder>()),
                        DistanceToCurrentTarget = vehicle.DistanceToCurrentTarget,
                        TimeToCurrentTarget     = vehicle.TimeToCurrentTarget,
                        DistanceTraveled        = vehicle.DistanceTraveled,
                        TotalTravelDistance     = vehicle.TotalTravelDistance,
                        TotalTravelTime         = vehicle.TotalTravelTime,
                        TotalIdleTime           = vehicle.TotalIdleTime,
                        CurrentFuelLoaded       = vehicle.CurrentFuelLoaded
                    };

                    simHistoryStep.Vehicles.Add(vehicleState);
                }
            }

            foreach (var openOrder in OpenOrders)
            {
                if (openOrder != null)
                {
                    var order = new HistoryOrder()
                    {
                        Start         = openOrder.Start?.Info.Name,
                        Target        = openOrder.Target?.Info.Name,
                        PayloadWeight = openOrder.PayloadWeight
                    };

                    simHistoryStep.OpenOrders.Add(order);
                }
            }

            foreach (var closedOrder in ClosedOrders)
            {
                if (closedOrder != null)
                {
                    var order = new HistoryCompletedOrder(new HistoryOrder(closedOrder.Order?.Start?.Info.Name, closedOrder.Order?.Target?.Info.Name, closedOrder.Order?.PayloadWeight))
                    {
                        DeliveryDistance = closedOrder.DeliveryDistance,
                        DeliveryTime     = closedOrder.DeliveryTime,
                        DeliveryPath     = closedOrder.DeliveryPath?.Select(p => p.Info.Name).ToList(),
                        DeliveryCost     = closedOrder.DeliveryCost,
                        PickupTime       = closedOrder.PickupTime,
                        PickupDistance   = closedOrder.PickupDistance,
                        PickupCost       = closedOrder.PickupCost
                    };

                    simHistoryStep.ClosedOrders.Add(order);
                }
            }

            SimulationHistory.Steps.Add(simHistoryStep);
        }
Exemplo n.º 15
0
 public HistoryOrder(HistoryOrder order)
 {
     Start         = order.Start;
     Target        = order.Target;
     PayloadWeight = order.PayloadWeight;
 }