/// <summary>
        /// Updates address
        /// </summary>
        /// <returns></returns>
        public static async Task UpdateAddress()
        {
            try
            {
                using (IAddressBL addressBL = new AddressBL())
                {
                    //Read Sl.No
                    Write("Address #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out int serial);
                    if (isNumberValid)
                    {
                        serial--;
                        RetailerBL retailerBL = new RetailerBL();
                        Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
                        List<Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);
                        if (serial <= addresses.Count - 1)
                        {
                            //Read inputs
                            Address address = addresses[serial];
                            Write("Address Line 1: ");
                            address.AddressLine1 = ReadLine();
                            Write("Address Line 2: ");
                            address.AddressLine2 = ReadLine();
                            Write("LandMark: ");
                            address.Landmark = ReadLine();
                            Write("City: ");
                            address.City = ReadLine();
                            Write("State: ");
                            address.State = ReadLine();
                            Write("PinCode: ");
                            address.PinCode = ReadLine();

                            //Invoke UpdateAddressBL method to update
                            bool isUpdated = await addressBL.UpdateAddressBL(address);
                            if (isUpdated)
                            {
                                WriteLine("Address Updated");
                            }
                        }
                        else
                        {
                            WriteLine($"Invalid Address #.\nPlease enter a number between 1 to {addresses.Count}");
                        }
                    }
                    else
                    {
                        WriteLine($"Invalid number.");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }

        }
        /// <summary>
        /// Menu for Retailer Address User
        /// </summary>
        /// <returns></returns>
        public static async Task<int> AddressPresentationMenu()
        {
            int choice = -2;
            using (IAddressBL addressBL = new AddressBL())
            {
                do
                {
                    //Get and display list of system users.
                    RetailerBL retailerBL = new RetailerBL();
                    Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
                    List<Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);
                    WriteLine("\n***************ADDRESS***********\n");
                    WriteLine("Addresses:");
                    if (addresses != null && addresses?.Count > 0)
                    {
                        WriteLine("#\tAddressLine 1\tLandMark\tCity\tState");
                        int serial = 0;
                        foreach (var address in addresses)
                        {
                            serial++;
                            WriteLine($"{serial}\t{address.AddressLine1}\t{address.Landmark}\t{address.City}\t{address.State}");
                        }
                    }

                    //Menu
                    WriteLine("\n1.Add Address");
                    WriteLine("2. Update Existing Address");
                    WriteLine("3. Delete Existing Address");
                    WriteLine("0. Back");
                    WriteLine("-1. Exit");
                    Write("Choice: ");

                    //Accept and check choice
                    bool isValidChoice = int.TryParse(ReadLine(), out choice);
                    if (isValidChoice)
                    {
                        switch (choice)
                        {
                            case 1: await AddAddress(); break;
                            case 2: await UpdateAddress(); break;
                            case 3: await DeleteAddress(); break;
                            case 0: break;
                            case -1: break;
                            default: WriteLine("Invalid Choice"); break;
                        }
                    }
                    else
                    {
                        choice = -2;
                    }
                } while (choice != 0 && choice != -1);
            }
            return choice;
        }
        /// <summary>
        /// Delete Address.
        /// </summary>
        /// <returns></returns>
        public static async Task DeleteAddress()
        {
            try
            {
                using (IAddressBL addressBL = new AddressBL())
                {
                    //Read Sl.No
                    Write("Address #: ");
                    bool isNumberValid = int.TryParse(ReadLine(), out int serial);
                    if (isNumberValid)
                    {
                        serial--;
                        RetailerBL retailerBL = new RetailerBL();
                        Retailer retailer = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);
                        List<Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);

                        Write("Are you sure? (Y/N): ");


                        string confirmation = ReadLine();

                        if (confirmation.Equals("Y", StringComparison.OrdinalIgnoreCase))
                        {
                            if (serial <= addresses.Count - 1)
                            { //Invoke DeleteSystemUserBL method to delete
                                Address address = addresses[serial];
                                bool isDeleted = await addressBL.DeleteAddressBL(address.AddressID);
                                if (isDeleted)
                                {
                                    WriteLine("Retailer Address Deleted");
                                }
                            }
                        }
                    }

                }


            }

            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);

            }
        }
        /// <summary>
        /// Confirm Order
        /// </summary>
        /// <returns></returns>
        public static async Task ConfirmOrder()
        {
            try
            {
                IProductBL productBL = new ProductBL();
                Guid       tempOrderID;
                using (IOrderDetailBL orderDetailBL = new OrderDetailBL())
                {
                    RetailerBL retailerBL = new RetailerBL();
                    Retailer   retailer   = await retailerBL.GetRetailerByEmailBL(CommonData.CurrentUser.Email);

                    AddressBL      addressBL = new AddressBL();
                    List <Address> addresses = await addressBL.GetAddressByRetailerIDBL(retailer.RetailerID);

                    double totalamount = 0;
                    int    quantity    = 0;
                    Guid   orderID     = Guid.NewGuid();
                    tempOrderID = orderID;
                    foreach (var cartProduct in cart)
                    {
                        OrderDetail orderDetail = new OrderDetail();
                        WriteLine("#\tAddressLine 1\tLandMark\tCity");
                        int serial = 0;
                        foreach (var address in addresses)
                        {
                            serial++;
                            WriteLine($"{serial}\t{address.AddressLine1}\t{address.Landmark}\t{address.City}");
                        }

                        Write("Address #: ");
                        bool isNumberValid = int.TryParse(ReadLine(), out int serial1);
                        if (isNumberValid)
                        {
                            serial1--;

                            if (serial1 <= addresses.Count - 1)
                            {
                                //Read inputs
                                Address address = addresses[serial1];
                                orderDetail.AddressId = address.AddressID;
                            }
                        }
                        orderDetail.OrderId                = orderID;
                        orderDetail.ProductID              = cartProduct.ProductID;
                        orderDetail.ProductPrice           = cartProduct.ProductPrice;
                        orderDetail.ProductQuantityOrdered = cartProduct.ProductQuantityOrdered;
                        orderDetail.TotalAmount            = (cartProduct.ProductPrice * cartProduct.ProductQuantityOrdered);
                        totalamount += orderDetail.TotalAmount;
                        quantity    += orderDetail.ProductQuantityOrdered;
                        bool isAdded = await orderDetailBL.AddOrderDetailsBL(orderDetail);
                    }

                    using (IOrderBL orderBL = new OrderBL())
                    {
                        Order order = new Order();
                        order.OrderId       = orderID;
                        order.RetailerID    = retailer.RetailerID;
                        order.TotalQuantity = quantity;
                        order.OrderAmount   = totalamount;
                        bool isAdded = await orderBL.AddOrderBL(order);

                        if (isAdded)
                        {
                            WriteLine("Order  Added");
                        }
                    }
                }
                IOrderBL orderBL1 = new OrderBL();

                Order order1 = await orderBL1.GetOrderByOrderIDBL(tempOrderID);

                WriteLine($"Your Order No. {order1.OrderNumber}\t{order1.TotalQuantity}\t{order1.OrderAmount}\t{order1.DateOfOrder}");
                WriteLine("Order Details");
                IOrderDetailBL     orderDetailBL1   = new OrderDetailBL();
                List <OrderDetail> orderDetailslist = await orderDetailBL1.GetOrderDetailsByOrderIDBL(tempOrderID);

                foreach (var item in orderDetailslist)
                {
                    Product product = await productBL.GetProductByProductIDBL(item.ProductID);

                    WriteLine($"{product.ProductName}\t{item.ProductPrice}\t{item.ProductQuantityOrdered}\t{item.TotalAmount}");
                }
                cart.Clear();
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);
                WriteLine(ex.Message);
            }
        }