public ActionResult Create(int CircuitID)
        {
            if (CurrentUser != null)
            {
                ViewData["SessionEnded"] = false;
                OpenRollViewModel OPenRoll = new OpenRollViewModel()
                {
                    CircuitID    = CircuitID,
                    CourtID      = CurrentUser.CourtID,
                    CurentUserID = CurrentUser.ID
                };
                OpenRollCreateViewModel _AllViewModel = PrepareViewModel(OPenRoll);
                _AllViewModel.ListCasesInRoll = PrepareOrder(_AllViewModel.ListCasesInRoll);
                //if (_AllViewModel.ListCasesInRoll.First().rollStatus == RollStatus.NotStarted)
                //{
                //    _AllViewModel.OPenRoll.CircuitID = _AllViewModel.ListCasesInRoll.First().CircuitID;
                //    ViewBag.Saved = true;
                //}
                _AllViewModel = DayNameChange(_AllViewModel);

                return(PartialView(_AllViewModel));
            }
            else
            {
                ViewData["SessionEnded"] = true;
                return(PartialView());
            }
        }
        public OpenRollCreateViewModel DayNameChange(OpenRollCreateViewModel _AllViewModel)
        {
            switch (_AllViewModel.SessionData.SessionDate.DayOfWeek)
            {
            case DayOfWeek.Saturday:
                _AllViewModel.SessionData.DayName = "السبت";
                break;

            case DayOfWeek.Sunday:
                _AllViewModel.SessionData.DayName = "الأحد";
                break;

            case DayOfWeek.Monday:
                _AllViewModel.SessionData.DayName = "الاثنين";
                break;

            case DayOfWeek.Tuesday:
                _AllViewModel.SessionData.DayName = "الثلاثاء";
                break;

            case DayOfWeek.Wednesday:
                _AllViewModel.SessionData.DayName = "الاربعاء";
                break;

            case DayOfWeek.Thursday:
                _AllViewModel.SessionData.DayName = "الخميس";
                break;

            case DayOfWeek.Friday:
                _AllViewModel.SessionData.DayName = "الجمعة";
                break;
            }
            return(_AllViewModel);
        }
        private OpenRollCreateViewModel PrepareViewModel(OpenRollViewModel OPenRoll = null)
        {
            if (OPenRoll == null)
            {
                OPenRoll = new OpenRollViewModel();
            }
            OpenRollCreateViewModel model = new OpenRollCreateViewModel()
            {
                ListCasesInRoll = RollService.GetRollCasesForOpening(OPenRoll.CircuitID, CurrentUser.ID)
                                  .Select(roll => new OpenRollViewModel
                {
                    SessionID         = roll.SessionID,
                    Order             = roll.Order,
                    CaseID            = roll.CaseID,
                    CaseStatus        = roll.CaseStatus,
                    OverAllNumber     = roll.OverAllNumber,
                    FirstLevelNumber  = roll.FirstLevelNumber,
                    SecondLevelNumber = roll.SecondLevelNumber,
                    MainCrime         = roll.MainCrime,
                    SecretaryID       = roll.SecretaryID,
                    RollID            = roll.RollID,
                    //CircuitID=roll.CircuitID,
                    //   rollStatus=roll.rollStatus,
                }).ToList(),
                //  SessionData = SessionService.GetSessionData(OPenRoll.CircuitID),
                Circuits = CircuitService.GetCircuitsBySecretairyID(CurrentUser.ID, CurrentUser.CourtID),

                OPenRoll    = OPenRoll,
                Prosecutors = ProsecutorService.GetProsecutor(CurrentUser.CourtID)
                              .Select(pros => new ProsecutorViewModels
                {
                    ID = pros.ID,
                    ProcecutoerName = pros.ProcecutoerName,
                }).ToList(),
                Halls = LookupService.GetCourtHalls(IsAuthenticatied ? CurrentUser.CourtID : null),
            };

            if (model.ListCasesInRoll.Count() != 0)
            {
                model.OPenRoll.RollID = model.ListCasesInRoll.Select(e => e.RollID).FirstOrDefault();
            }
            if (model.ListCasesInRoll.Any(e => e.Order == 0))
            {
                model.OPenRoll.rollStatus = RollStatus.NotSorted;
            }
            model.ListCasesInRoll = PrepareOrder(model.ListCasesInRoll);
            vw_SessionData SessionDate = new vw_SessionData();

            SessionDate.SessionDate     = DateTime.Now;
            model.SessionData           = SessionDate;
            model.OPenRoll.CourtID      = CurrentUser.CourtID;
            model.OPenRoll.CurentUserID = CurrentUser.ID;
            return(model);
        }
        // GET: AllOpenRolls
        public ActionResult Index()
        {
            if (CurrentUser != null)
            {
                List <vw_SessionData>   GetOpenedRolls = RollService.GetRollsOpend(CurrentUser.ID, CurrentUser.UserTypeID);
                OpenRollCreateViewModel _AllViewModel  = new OpenRollCreateViewModel();
                _AllViewModel.AllOpenRolls = GetOpenedRolls;
                return(View(_AllViewModel));
            }

            else
            {
                return(RedirectTo(Url.Action("login", "User", new { returnUrl = "/" })).WithErrorMessages("تم الخروج بشكل تلقائى لعدم التفاعل اكثر من 15 دقيقة"));
            }
        }
        public ActionResult OPenRoll(int CircuitID)
        {
            if (CurrentUser != null)
            {
                ViewData["SessionEnded"] = false;
                OpenRollViewModel OPenRoll = new OpenRollViewModel()
                {
                    CircuitID    = CircuitID,
                    CourtID      = CurrentUser.CourtID,
                    CurentUserID = CurrentUser.ID
                };
                OpenRollCreateViewModel _AllViewModel = new OpenRollCreateViewModel();
                _AllViewModel.OPenRoll = OPenRoll;
                vw_SessionData SessionDate = new vw_SessionData();
                SessionDate.SessionDate   = RollService.GetOpenedRolls(CurrentUser.ID).Select(e => e.RollDate).First();
                _AllViewModel.SessionData = SessionDate;

                _AllViewModel.ListCasesInRoll = RollService.GetOpenedRolls(CurrentUser.ID)
                                                .Select(roll => new OpenRollViewModel
                {
                    SessionID         = roll.SessionID,
                    Order             = roll.Order,
                    CaseID            = roll.CaseID,
                    CaseStatus        = roll.CaseStatus,
                    OverAllNumber     = roll.OverAllNumber,
                    FirstLevelNumber  = roll.FirstLevelNumber,
                    SecondLevelNumber = roll.SecondLevelNumber,
                    MainCrime         = roll.MainCrime,
                    SecretaryID       = roll.SecretaryID,
                }).ToList();


                _AllViewModel.ListCasesInRoll = PrepareOrder(_AllViewModel.ListCasesInRoll);
                _AllViewModel = DayNameChange(_AllViewModel);
                return(PartialView(_AllViewModel));
            }

            else
            {
                ViewData["SessionEnded"] = true;
                return(PartialView());
            }
        }
        public ActionResult CompleteOPenRoll(int SessionID)
        {
            if (CurrentUser != null)
            {
                OpenRollViewModel OPenRoll = new OpenRollViewModel()
                {
                    SessionID = SessionID,
                };
                OpenRollCreateViewModel _AllViewModel = new OpenRollCreateViewModel();
                _AllViewModel.OPenRoll = OPenRoll;
                vw_SessionData SessionDate = new vw_SessionData();
                SessionDate.SessionDate   = RollService.GetCasesINRoll(SessionID).Select(e => e.RollDate).FirstOrDefault();
                _AllViewModel.SessionData = SessionDate;

                _AllViewModel.ListCasesInRoll = RollService.GetCasesINRoll(SessionID)
                                                .Select(roll => new OpenRollViewModel
                {
                    SessionID         = roll.SessionID,
                    Order             = roll.Order,
                    CaseID            = roll.CaseID,
                    CaseStatus        = roll.CaseStatus,
                    OverAllNumber     = roll.OverAllNumber,
                    FirstLevelNumber  = roll.FirstLevelNumber,
                    SecondLevelNumber = roll.SecondLevelNumber,
                    MainCrime         = roll.MainCrime,
                    SecretaryID       = roll.SecretaryID,
                    CircuitID         = roll.CircuitID,
                }).ToList();


                _AllViewModel.ListCasesInRoll = PrepareOrder(_AllViewModel.ListCasesInRoll);
                _AllViewModel = DayNameChange(_AllViewModel);
                return(View(_AllViewModel));
            }

            else
            {
                return(RedirectTo(Url.Action("login", "User", new { returnUrl = "/" })).WithErrorMessages("تم الخروج بشكل تلقائى لعدم التفاعل اكثر من 15 دقيقة"));
            }
        }
        // GET: OpenRoll
        public ActionResult Index()
        {
            if (CurrentUser != null)
            {
                //  List<vw_RollCases> GetOpenedRolls = RollService.GetOpenedRolls(CurrentUser.ID);

                OpenRollCreateViewModel model = new OpenRollCreateViewModel()
                {
                    Circuits = CircuitService.GetCircuitsBySecretairyID(CurrentUser.ID, CurrentUser.CourtID)
                };

                if (model.Circuits.Count == 0)
                {
                    return(RedirectTo(Url.Action("NoSession")).WithErrorMessages("لا يوجد جلسات لفتحها اليوم"));
                }
                return(View(model));
            }

            else
            {
                return(RedirectTo(Url.Action("login", "User", new { returnUrl = "/" })).WithErrorMessages("تم الخروج بشكل تلقائى لعدم التفاعل اكثر من 15 دقيقة"));
            }
        }