Exemplo n.º 1
0
        public static Order GetViewOrder(this Core.Model.Order o)
        {
            if (o == null)
            {
                throw new ArgumentNullException(nameof(o));
            }

            return(new Order
            {
                Symbol = o.Symbol,
                Exchange = o.Exchange,
                Id = o.Id,
                ClientOrderId = o.ClientOrderId,
                Price = o.Price,
                OriginalQuantity = o.OriginalQuantity,
                ExecutedQuantity = o.ExecutedQuantity,
                Status = o.Status.GetOrderStatusName(),
                TimeInForce = o.TimeInForce.GetTimeInForceName(),
                Type = o.Type.GetOrderTypeName(),
                Side = o.Side.GetOrderSideName(),
                StopPrice = o.StopPrice,
                IcebergQuantity = o.IcebergQuantity,
                Time = o.Time,
                IsWorking = o.IsWorking
            });
        }
Exemplo n.º 2
0
        public IHttpActionResult AddItemToOrder(long userId, long productId)
        {
            var cart = db.Orders.FirstOrDefault(it => it.StatusUpdates.Count == 1 && it.UserID == userId);

            if (cart == null)
            {
                var user = db.Users.FirstOrDefault(it => it.UserID == userId);
                if (user == null)
                {
                    return(NotFound());
                }

                var status = new StatusUpdate
                {
                    Date   = DateTime.Now,
                    Status = Status.Cart
                };

                var newOrder = new Core.Model.Order {
                    User = user
                };
                newOrder.StatusUpdates.Add(status);
                db.Orders.Add(newOrder);
                db.SaveChanges();

                cart = db.Orders.FirstOrDefault(it => it.StatusUpdates.Count == 1 && it.UserID == userId);
            }

            if (cart.ConvertToDTO().Status != Status.Cart)
            {
                return(Ok("Order is already completed"));
            }

            var product = db.Products.FirstOrDefault(it => it.ProductId == productId);

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

            var orderItem = cart.OrderItems.FirstOrDefault(it => it.ProductId == productId);

            if (orderItem != null)
            {
                orderItem.Count++;
                db.SaveChanges();
                return(Ok(new { order = cart.ConvertToDTO() }));
            }

            var newOrderItem = new BB.Core.Model.OrderItem();

            newOrderItem.Order        = cart;
            newOrderItem.Product      = product;
            newOrderItem.Count        = 1;
            newOrderItem.PricePerItem = product.Price;
            db.OrderItems.Add(newOrderItem);
            db.SaveChanges();

            return(Ok(new { order = cart.ConvertToDTO() }));
        }
Exemplo n.º 3
0
        public ServiceResult <Core.Model.Order> ChangeOrderStatus(int id, Core.Enum.OrderStatus currentStatus)
        {
            Core.Model.Order order = new Core.Model.Order();
            ServiceResult <Core.Model.Order> result = new ServiceResult <Core.Model.Order>();

            result.Data = new Core.Model.Order();

            try
            {
                order.Id            = id;
                order.CurrentStatus = currentStatus;

                var status = _orderBO.UpdateOrder(order);

                result.HasError = false;
            }
            catch (Exception ex)
            {
                result.HasError     = true;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }