public HttpResponseMessage AddToExistingBlock([FromBody] List <int> Ids)
        {
            Trader <Order>       obj  = new Trader <Order>(ctx);
            Trader <Block>       obj1 = new Trader <Block>(ctx);
            Trader <OrderDetail> obj2 = new Trader <OrderDetail>(ctx);
            OrderDetail          o    = new OrderDetail();

            try
            {
                //Block bl = new Block();
                var a = ctx.Blocks.Find(Ids[0]);

                for (int i = 1; i < Ids.Count; i++)
                {
                    var x = ctx.Orders.Find(Ids[i]);

                    if (a.orderType == x.orderType && a.symbol == x.symbol && a.side == x.side)
                    {
                        if (a.orderType == "Market")
                        {
                            a.price = a.price;
                        }
                        else if (a.orderType == "Limit")
                        {
                            if (x.side == "Buy")
                            {
                                if (a.price > x.price)
                                {
                                    a.price = x.price;
                                }

                                if (a.stopPrice < x.stopPrice)
                                {
                                    a.stopPrice = x.stopPrice;
                                }
                            }
                            else if (x.side == "Sell")
                            {
                                if (a.price < x.price)
                                {
                                    a.price = x.price;
                                }

                                if (a.stopPrice > x.stopPrice)
                                {
                                    a.stopPrice = x.stopPrice;
                                }
                            }
                        }
                        a.totalQuantity += x.totalQuantity;
                        a.openQuantity   = a.totalQuantity;
                    }
                    else
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }
                }

                obj1.Edit(a);
                for (int i = 1; i < Ids.Count; i++)
                {
                    o.blockId = a.blockId;
                    o.orderId = Ids[i];
                    obj2.Add(o);
                    Order ord = new Order();
                    ord             = ctx.Orders.Find(Ids[i]);
                    ord.orderStatus = "Blocked";
                    obj.Edit(ord);
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
        public HttpResponseMessage AddToNewBlock([FromBody] List <int> orderID)
        {
            Trader <Block>       t  = new Trader <Block>(ctx);
            Trader <OrderDetail> od = new Trader <OrderDetail>(ctx);
            Trader <Order>       o1 = new Trader <Order>(ctx);
            OrderDetail          o  = new OrderDetail();

            try
            {
                Block bl    = new Block();
                int   count = 0;
                var   b     = ctx.Orders.Find(orderID[0]);
                var   c     = b.orderType;

                foreach (var item in orderID)
                {
                    var x = ctx.Orders.Find(item);

                    if (count == 0)
                    {
                        bl.price            = x.price;
                        bl.userName         = x.userName;
                        bl.symbol           = x.symbol;
                        bl.side             = x.side;
                        bl.stopPrice        = x.stopPrice;
                        bl.totalQuantity    = x.totalQuantity;
                        bl.openQuantity     = x.openQuantity;
                        bl.executedQuantity = 0;
                        bl.blockStatus      = "Open";
                        bl.createTStamp     = DateTime.Now;
                        bl.orderType        = x.orderType;

                        count++;
                    }
                    else if (x.orderType == bl.orderType && bl.symbol == x.symbol && bl.side == x.side)
                    {
                        if (x.orderType == "Market")
                        {
                            bl.price = x.price;
                        }
                        else if (x.orderType == "Limit")
                        {
                            if (x.side == "Buy")
                            {
                                if (bl.price > x.price)
                                {
                                    bl.price = x.price;
                                }

                                if (bl.stopPrice < x.stopPrice)
                                {
                                    bl.stopPrice = x.stopPrice;
                                }
                            }
                            else if (x.side == "Sell")
                            {
                                if (bl.price < x.price)
                                {
                                    bl.price = x.price;
                                }

                                if (bl.stopPrice > x.stopPrice)
                                {
                                    bl.stopPrice = x.stopPrice;
                                }
                            }
                        }
                        bl.totalQuantity += x.totalQuantity;
                        bl.openQuantity   = bl.totalQuantity;
                    }
                    else
                    {
                        throw new HttpResponseException(HttpStatusCode.BadRequest);
                    }
                }

                t.Add(bl);
                int id = ctx.Blocks.Max(x => x.blockId);
                foreach (var item in orderID)
                {
                    o.blockId = id;
                    o.orderId = item;
                    od.Add(o);
                    Order obj = new Order();
                    obj             = ctx.Orders.Find(item);
                    obj.orderStatus = "Blocked";
                    o1.Edit(obj);
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }