public IActionResult DeleteSaleOrder(int id)
        {
            using (var context = new MyAngularAppContext())
            {
                var SaleOrderDetail = context.SaleOrder.Find(id);
                if (SaleOrderDetail != null)
                {
                    context.SaleOrder.Remove(SaleOrderDetail);
                    context.SaveChanges();
                }

                return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Ok, "Order Deleted Successfully ", null)));
            }
        }
        public IActionResult BuyCoin(BuyOrderModel model)
        {
            using (var context = new MyAngularAppContext())
            {
                var saleData    = context.SaleOrder.Where(x => x.Rate <= model.Rate).ToList();
                var totalCoin   = model.Coin;
                var buyCoin     = 0;
                var isCompleted = false;
                foreach (var item in saleData)
                {
                    if (item.Coin <= (totalCoin - buyCoin))
                    {
                        Transaction objTransaction = new Transaction();
                        objTransaction.UserId              = 1;
                        objTransaction.TransactionType     = 1;
                        objTransaction.SaleUserId          = item.UserId;
                        objTransaction.TransactionDateTime = DateTime.Now;
                        objTransaction.Coin = item.Coin;
                        objTransaction.Rate = model.Rate;
                        context.Transaction.Add(objTransaction);
                        context.SaveChanges();
                        buyCoin += (int)objTransaction.Coin;

                        var saleCoin = context.SaleOrder.Find(item.OrderId);
                        if (saleCoin != null)
                        {
                            var remaining_coin = saleCoin.Coin - objTransaction.Coin;
                            if (remaining_coin <= 0)
                            {
                                context.SaleOrder.Remove(saleCoin);
                            }
                            else
                            {
                                saleCoin.Coin = remaining_coin;
                            }
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        Transaction objTransaction = new Transaction();
                        objTransaction.UserId              = 1;
                        objTransaction.TransactionType     = 1;
                        objTransaction.SaleUserId          = item.UserId;
                        objTransaction.TransactionDateTime = DateTime.Now;
                        objTransaction.Coin = (totalCoin - buyCoin);
                        objTransaction.Rate = item.Rate;
                        context.Transaction.Add(objTransaction);
                        context.SaveChanges();
                        buyCoin += (int)objTransaction.Coin;

                        var saleCoin = context.SaleOrder.Find(item.OrderId);
                        if (saleCoin != null)
                        {
                            var remaining_coin = saleCoin.Coin - objTransaction.Coin;
                            if (remaining_coin <= 0)
                            {
                                context.SaleOrder.Remove(saleCoin);
                            }
                            else
                            {
                                saleCoin.Coin = remaining_coin;
                            }
                            context.SaveChanges();
                        }
                    }

                    if (totalCoin == buyCoin)
                    {
                        isCompleted = true;
                        break;
                    }
                }

                if (!isCompleted)
                {
                    BuyOrder objBuyOrder = new BuyOrder();
                    objBuyOrder.Coin   = (totalCoin - buyCoin);
                    objBuyOrder.Rate   = model.Rate;
                    objBuyOrder.UserId = 1;
                    context.BuyOrder.Add(objBuyOrder);
                    context.SaveChanges();
                }
                return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Ok, "Order Placed Successfully ", null)));
            }
        }