// GET: Roll
        public ActionResult Index()
        {
            if (CurrentUser != null)
            {
                List <vw_KeyValue> Circuits      = CircuitService.GetCircuitsBySecretairyID(CurrentUser.ID, null);
                RollOrderViewModel _AllViewModel = new RollOrderViewModel();
                _AllViewModel.Circuits = Circuits;

                RollOrderCaseViewModel Roll = new RollOrderCaseViewModel();
                Roll.CurentUserID  = CurrentUser.ID;
                Roll.CourtID       = CurrentUser.CourtID;
                _AllViewModel.Roll = Roll;

                return(View(_AllViewModel));
            }
            else
            {
                return(RedirectTo(Url.Action("login", "User", new { returnUrl = "/" })).WithErrorMessages("تم الخروج بشكل تلقائى لعدم التفاعل اكثر من 15 دقيقة"));
            }
        }
        //[HttpGet]
        // public ActionResult IndexGrid(int RollID, int CircuitID)
        // {
        //     RollOrderCaseViewModel Roll = new RollOrderCaseViewModel()
        //     {
        //         CircuitID =CircuitID,
        //          RollID =RollID,
        //      };
        //     RollOrderViewModel _AllViewModel = PrepareViewModel(null, Roll);
        //     _AllViewModel.ListRollBeforeOrder = PrepareBeforeOrder(_AllViewModel.ListRollToOrder);

        //     // Only grid string query values will be visible here.
        //     return PartialView("_IndexGrid", _AllViewModel);
        // }
        public ActionResult AfterOrder(int RollID, int CircuitID)
        {
            if (CurrentUser != null)
            {
                ViewData["SessionEnded"] = false;
                RollOrderCaseViewModel Roll = new RollOrderCaseViewModel()
                {
                    CircuitID    = CircuitID,
                    RollID       = RollID,
                    CourtID      = CurrentUser.CourtID,
                    CurentUserID = CurrentUser.ID,
                };
                RollOrderViewModel _AllViewModel = PrepareViewModel(null, Roll);
                _AllViewModel.ListRollToOrder = PrepareOrder(_AllViewModel.ListRollToOrder);
                return(PartialView(_AllViewModel));
            }
            else
            {
                ViewData["SessionEnded"] = true;
                return(PartialView());
            }
        }
        public ActionResult Create(List <CaseOrderViewModel> CaseOrder, int RollID, int CircuitID, bool saveBeforeOrder)
        {
            if (CurrentUser != null)
            {
                ViewData["SessionEnded"] = false;
                RollOrderCaseViewModel Roll = new RollOrderCaseViewModel()
                {
                    CircuitID    = CircuitID,
                    RollID       = RollID,
                    CourtID      = CurrentUser.CourtID,
                    CurentUserID = CurrentUser.ID,
                };
                RollOrderViewModel _AllViewModel = PrepareViewModel(CaseOrder, Roll);
                _AllViewModel.ListRollToOrder     = PrepareOrder(_AllViewModel.ListRollToOrder);
                _AllViewModel.ListUnableOrder     = PrepareUnableOrder(_AllViewModel.ListUnableOrder);
                _AllViewModel.ListRollBeforeOrder = PrepareBeforeOrder(_AllViewModel.ListRollToOrder);

                try
                {
                    if (ModelState.IsValid)
                    {
                        List <vw_CaseOrder> vw_order = new List <vw_CaseOrder>();

                        if (saveBeforeOrder == false)
                        {
                            vw_order = CaseOrder
                                       .Select(order => new vw_CaseOrder
                            {
                                CaseID      = order.CaseID,
                                Order       = order.Order,
                                SecritaryID = order.SecritaryID
                            }).ToList();
                        }
                        else if (saveBeforeOrder == true)
                        {
                            int count = _AllViewModel.ListRollToOrder.Count();
                            count++;
                            vw_order = CaseOrder
                                       .Select(order => new vw_CaseOrder
                            {
                                CaseID      = order.CaseID,
                                Order       = count,
                                SecritaryID = order.SecritaryID
                            }).ToList();
                            foreach (var order in vw_order)
                            {
                                order.Order = count;
                                count++;
                            }
                        }

                        SaveRollOrderStatus saveRollOrderStatus = RollService.SaveRollOrder(Roll.RollID, vw_order);
                        if (saveBeforeOrder == false)
                        {
                            if (saveRollOrderStatus == Base.SaveRollOrderStatus.SuccessFull)
                            {
                                return(CPartialView("_RollForm", _AllViewModel).WithSuccessMessages(JIC.Base.Resources.Messages.SuccessOrder));
                            }
                        }
                        else if (saveBeforeOrder == true)
                        {
                            if (saveRollOrderStatus == Base.SaveRollOrderStatus.SuccessFull)
                            {
                                return(CPartialView("_RollForm", _AllViewModel).WithSuccessMessages("تم النقل لجدول الترتيب"));
                                //  ViewBag.sccessMessage = true;
                            }
                        }

                        else if (saveRollOrderStatus == Base.SaveRollOrderStatus.RollOpened)
                        {
                            //  return RedirectJS(Url.Action("Index")).WithSuccessMessages(JIC.Base.Resources.Messages.RollOpened);
                            return(CPartialView("_RollForm", _AllViewModel).WithSuccessMessages(JIC.Base.Resources.Messages.RollOpened));
                        }

                        else if (saveRollOrderStatus == Base.SaveRollOrderStatus.Failed)
                        {
                            return(CPartialView("_RollForm", _AllViewModel).WithErrorMessages(JIC.Base.Resources.Messages.OperationNotCompleted));

                            //  ViewBag.sccessMessage = false;
                        }
                    }

                    return(CPartialView("_RollForm", _AllViewModel).WithErrorMessages(JIC.Base.Resources.Messages.OperationNotCompleted));
                }
                catch (Exception ex)
                {
                    return(ErrorPage(ex));
                }
            }
            else
            {
                ViewData["SessionEnded"] = true;
                return(PartialView());
            }
        }