public ActionResult DeliveryFilter(int x, string deliveryOpt)
        {
            List <OrderDetailsViewModel> od  = new List <OrderDetailsViewModel>();
            CakesPosRepository           cpr = new CakesPosRepository(_connectionString);
            DateTime today = DateTime.Today;

            if (x == -1)
            {
                IEnumerable <OrderHistoryViewModel> orders = cpr.GetOrders().Where(o => o.deliveryOpt == deliveryOpt && o.requiredDate >= today.AddDays(x) && o.requiredDate < today && o.invoice == false);
                foreach (OrderHistoryViewModel o in orders)
                {
                    od.Add(cpr.GetOrderDetails(o.customerId, o.id));
                }
                return(Json(od, JsonRequestBehavior.AllowGet));
            }
            else if (x <= 0)
            {
                IEnumerable <OrderHistoryViewModel> orders = cpr.GetOrders().Where(o => o.deliveryOpt == deliveryOpt && o.requiredDate >= today.AddDays(x) && o.requiredDate <= today && o.invoice == false);
                foreach (OrderHistoryViewModel o in orders)
                {
                    od.Add(cpr.GetOrderDetails(o.customerId, o.id));
                }
                return(Json(od, JsonRequestBehavior.AllowGet));
            }
            else if (x == 1)
            {
                IEnumerable <OrderHistoryViewModel> orders = cpr.GetOrders().Where(o => o.deliveryOpt == deliveryOpt && o.requiredDate == today.AddDays(x) && o.invoice == false);
                foreach (OrderHistoryViewModel o in orders)
                {
                    od.Add(cpr.GetOrderDetails(o.customerId, o.id));
                }
                return(Json(od, JsonRequestBehavior.AllowGet));
            }
            else if (x == 8)
            {
                IEnumerable <OrderHistoryViewModel> orders = cpr.GetOrders().Where(o => o.deliveryOpt == deliveryOpt && o.invoice == false);
                foreach (OrderHistoryViewModel o in orders)
                {
                    od.Add(cpr.GetOrderDetails(o.customerId, o.id));
                }
                return(Json(od, JsonRequestBehavior.AllowGet));
            }
            else
            {
                IEnumerable <OrderHistoryViewModel> orders = cpr.GetOrders().Where(o => o.deliveryOpt == deliveryOpt && o.requiredDate <= today.AddDays(x) && o.requiredDate >= today && o.invoice == false);
                foreach (OrderHistoryViewModel o in orders)
                {
                    od.Add(cpr.GetOrderDetails(o.customerId, o.id));
                }
                return(Json(od, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult GetOrderHistory(int orderId, int customerId)
        {
            CakesPosRepository    cpr          = new CakesPosRepository(_connectionString);
            OrderDetailsViewModel orderHistory = cpr.GetOrderDetails(orderId, customerId);

            return(Json(orderHistory, JsonRequestBehavior.AllowGet));
        }
        public ActionResult CreateInvoice(int customerId, int orderId)
        {
            CakesPosRepository    cpr = new CakesPosRepository(_connectionString);
            OrderDetailsViewModel o   = cpr.GetOrderDetails(customerId, orderId);
            InvoiceManager        i   = new InvoiceManager();

            i.CreateInvoicePDF(o);
            return(null);
        }
        public ActionResult CreateInvoiceOtherEmail(int customerId, int orderId, string email)
        {
            CakesPosRepository    cpr = new CakesPosRepository(_connectionString);
            OrderDetailsViewModel o   = cpr.GetOrderDetails(customerId, orderId);
            InvoiceManager        i   = new InvoiceManager();

            i.CreateInvoicePDF(o);
            i.EmailInvoice(@"C:\inetpub\sites\CakesPos\InvoicesPdf\" + orderId + ".pdf", email);
            return(null);
        }
        public ActionResult OrderList()
        {
            List <OrderDetailsViewModel>        od     = new List <OrderDetailsViewModel>();
            CakesPosRepository                  cpr    = new CakesPosRepository(_connectionString);
            IEnumerable <OrderHistoryViewModel> orders = cpr.GetOrders().Where(o => o.requiredDate == DateTime.Today && o.invoice == false);

            foreach (OrderHistoryViewModel o in orders)
            {
                od.Add(cpr.GetOrderDetails(o.customerId, o.id));
            }
            return(View(od));
        }
        //[HttpPost]
        //public ActionResult Order(int customerId, int orderId)
        //{
        //    CakesPosRepository cpr = new CakesPosRepository(_connectionString);
        //    OrdersViewModel ovm = new OrdersViewModel();
        //    ovm.categories = cpr.GetAllCategories();
        //    ovm.products = cpr.GetProductsByCategory(1);
        //    ovm.order = cpr.GetOrderById(orderId);
        //    ovm.orderDetails = cpr.GetOrderDetailsById(orderId);
        //    return View(ovm);
        //}

        //[HttpPost]
        public ActionResult EditOrder(int customerId, int orderId)
        {
            CakesPosRepository  cpr = new CakesPosRepository(_connectionString);
            EditOrdersViewModel ovm = new EditOrdersViewModel();

            ovm.categories = cpr.GetAllCategories();
            ovm.products   = cpr.GetProductsByCategory(1);
            //ovm.order = cpr.GetOrderById(orderId);
            //ovm.orderDetails = cpr.GetOrderDetailsById();
            //ovm.customer = cpr.GetCustomerById(customerId);
            //ovm.orderedProducts=cpr.
            ovm.productAvailability = cpr.GetProductAvailability(DateTime.Today.AddMonths(-1), DateTime.Today.AddDays(3), 1);
            ovm.orderDetails        = cpr.GetOrderDetails(customerId, orderId);
            return(View(ovm));
        }