public async Task <IActionResult> OrderFoodFromCart()
        {
            _logService.LogMessage("Order Entity received at endpoint : api/OrderFoodFromCart");
            int         UserId      = (Request.Headers.ContainsKey("CustomerId") ? int.Parse(HttpContext.Request.Headers["CustomerId"]) : 0);
            string      UserToken   = (Request.Headers.ContainsKey("AuthToken") ? Convert.ToString(HttpContext.Request.Headers["AuthToken"]) : "");
            OrderEntity orderEntity = _placeOrderActions.mappingorderandcartitems(UserId);

            if (orderEntity == null)
            {
                return(BadRequest("No Items in Cart"));
            }
            ////List<OrderMenus> om1 = new List<OrderMenus>();
            ////List<CartItemsEntity> cartitems = new List<CartItemsEntity>();
            ////cartitems = _icartActions.GetCartDetails(UserId);
            ////foreach(var item in cartitems)
            ////{
            ////    orderEntity.CustomerId = (int) item.TblCustomerID;
            ////    orderEntity.RestaurantId = (int)item.TblRestaurantID;
            ////    orderEntity.DeliveryAddress = "abc";
            ////    OrderMenus om = new OrderMenus();
            ////    om.MenuId = item.TblMenuID;
            ////    om.Price = item.Price;
            ////    om.quantity =(int) item.Quantity;
            ////    om1.Add(om);
            ////}
            //orderEntity.OrderMenuDetails = new List<OrderMenus>(om1);
            else
            {
                OrderEntityValidator orderEntityValidator = new OrderEntityValidator(UserId, UserToken, _placeOrderActions);
                ValidationResult     validationResult     = orderEntityValidator.Validate(orderEntity);
                if (!validationResult.IsValid)
                {
                    return(BadRequest(validationResult.ToString("; ")));
                }
                else
                {
                    var result = await Task <int> .Run(() => _placeOrderActions.PlaceOrder(orderEntity));

                    if (result == 0)
                    {
                        return(BadRequest("Failed to place order, Please try again later"));
                    }
                    else
                    {
                        // Publish Quantity of menu to search service.
                        //remove cart.
                        var pub = JsonConvert.SerializeObject(orderEntity.OrderMenuDetails);
                        await PublishOrderPlaced.SendMessagesAsync(pub);

                        foreach (var item in orderEntity.OrderMenuDetails)
                        {
                            _icartActions.Removecart(orderEntity.CustomerId, item.MenuId > 0 ? item.MenuId : 0);
                        }
                    }
                }
            }

            return(Ok("Order placed successfully"));
        }
        public async Task <IActionResult> Post([FromBody] OrderEntity orderEntity)
        {
            _logService.LogMessage("Order Entity received at endpoint : api/OrderFood, User ID : " + orderEntity.CustomerId);
            int    UserId    = (Request.Headers.ContainsKey("CustomerId") ? int.Parse(HttpContext.Request.Headers["CustomerId"]) : 0);
            string UserToken = (Request.Headers.ContainsKey("AuthToken") ? Convert.ToString(HttpContext.Request.Headers["AuthToken"]) : "");

            OrderEntityValidator orderEntityValidator = new OrderEntityValidator(UserId, UserToken, _placeOrderActions);
            ValidationResult     validationResult     = orderEntityValidator.Validate(orderEntity);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.ToString("; ")));
            }
            else
            {
                var result = await Task <int> .Run(() => _placeOrderActions.PlaceOrder(orderEntity));

                if (result == 0)
                {
                    return(BadRequest("Failed to place order, Please try again later"));
                }
                else
                {
                    // Publish Quantity of menu to search service.
                    //update cart quantity if menu exists.
                    var pubquantity = JsonConvert.SerializeObject(orderEntity.OrderMenuDetails);
                    await PublishOrderPlaced.SendMessagesAsync(pubquantity);

                    //foreach (var item in orderEntity.OrderMenuDetails)
                    //{
                    //    _icartActions.Removecart(orderEntity.CustomerId, item.MenuId>0?item.MenuId:0);
                    //}
                }
            }
            return(Ok("Order placed successfully"));
        }