public ActionResult GetStudy(string SearchText)
        {
            try
            {
                if (pagemanager.IsPageValid((int)Session["FOGroupId"], 11))
                {
                    return(View("PageError"));
                }
                else
                {
                    NavManager.Logger((int)Session["FOUserId"], 11, DateTime.Now, Request.Url.AbsoluteUri);
                    int id   = (int)(Session["FOUserId"]);
                    var user = usermanager.GetUserByID(id);

                    var studies = studymanager.GetGrantedStudiesbyUserID(id);
                    GrantDenyStudyModels grant = new GrantDenyStudyModels();

                    foreach (var item in studies)
                    {
                        StudyModels std          = new StudyModels();
                        Study       sm           = new Study();
                        var         presentgroup = user.GroupID;
                        List <StudyStatusMapping> studyStatusMaps = mapGetter.GetAll().ToList <StudyStatusMapping>();

                        sm = studymanager.GetStudyByStudyId(item.StudyID);
                        var newStatus = (from status in studyStatusMaps
                                         where (status.DataSourceStudyStatus.StudyStatusName == sm.StudyStatus && status.GroupID == presentgroup)
                                         select status.LocalStudyStatus.StudyStatusName).FirstOrDefault <string>();
                        if (newStatus != null)
                        {
                            std.StudyName      = sm.StudyName;
                            std.StudyCode      = sm.StudyCode;
                            std.StudyID        = sm.StudyID;
                            std.SponsorName    = sm.Sponsor.SponsorName;
                            std.StudyStartDate = sm.StudyStartDate;
                            std.Status         = newStatus;
                            grant.studymodel.Add(std);
                        }
                    }

                    if (SearchText != null && SearchText != "")
                    {
                        List <StudyModels>   searchStudyList      = grant.studymodel.Where(x => x.StudyName.ToLower().Contains(SearchText.ToLower())).ToList <StudyModels>();
                        GrantDenyStudyModels grantDenyStudyModels = new GrantDenyStudyModels();
                        grantDenyStudyModels.studymodel = searchStudyList;
                        return(View(grantDenyStudyModels));
                    }
                    return(View(grant));
                }
            }
            catch (NullReferenceException ex)
            {
                return(Redirect(FormsAuthentication.LoginUrl));
            }
            catch (Exception e)
            {
                ViewBag.message = e.Message;
                return(View("Error"));
            }
        }
        public ActionResult StudyStatusesMapper()
        {
            try
            {
                List <UserGroup>      groups        = groupsGetter.GetAll().ToList <UserGroup>().Where <UserGroup>(x => x.GroupID != 3).ToList <UserGroup>();
                List <SelectListItem> groupItemList = new List <SelectListItem>();
                foreach (var item in groups)
                {
                    SelectListItem tempItem = new SelectListItem();
                    tempItem.Text  = item.GroupName;
                    tempItem.Value = item.GroupID.ToString();
                    groupItemList.Add(tempItem);
                }
                ViewBag.groups = groupItemList;


                return(View());
            }
            catch (Exception e)
            {
                ViewBag.message = e.Message;
                return(View("Error"));
            }
        }
        public ActionResult RenderMapper(string groupID)
        {
            StudyStatusesModel m = new StudyStatusesModel();

            m.groups = groupID;

            List <StudyStatusMapping> mappedStatus;

            try
            {
                mappedStatus = statusMap.GetAll().Where <StudyStatusMapping>(x => x.GroupID == int.Parse(groupID)).ToList <StudyStatusMapping>();
            }
            catch (Exception ex)
            {
                return(View("Error"));
            }
            List <DataSourceStudyStatus> statuses       = dsStatusGetter.GetAllStatus().ToList <DataSourceStudyStatus>();
            List <SelectListItem>        statusItemList = new List <SelectListItem>();
            List <DataSourceStudyStatus> tempStatus     = new List <DataSourceStudyStatus>();

            foreach (var item in statuses)
            {
                try
                {
                    if (mappedStatus.Where <StudyStatusMapping>(x => x.DataSourceStudyStatus.StudyStatusName == item.StudyStatusName).FirstOrDefault <StudyStatusMapping>() == null)
                    {
                        tempStatus.Add(item);
                    }
                    //choose the status which havnt been mapped
                }
                catch (Exception ex)
                {
                    return(View("Error"));
                }
            }

            statuses = tempStatus;

            foreach (var item in statuses)
            {
                SelectListItem tempItem = new SelectListItem();
                tempItem.Text  = item.StudyStatusName;
                tempItem.Value = item.StudyStatusName;
                statusItemList.Add(tempItem);
            }

            if (statusItemList.Count == 0)
            {
                ViewBag.dataSourceStatusState = "empty";
            }
            else
            {
                ViewBag.dataSourceStatus = statusItemList;
            }



            List <DataSource>     dataSources        = dataSourceGetter.GetAll().ToList <DataSource>();
            List <SelectListItem> dataSourceItemList = new List <SelectListItem>();

            foreach (var item in dataSources)
            {
                SelectListItem tempItem = new SelectListItem();
                tempItem.Text  = item.DataSourceName;
                tempItem.Value = item.DataSourceName;
                dataSourceItemList.Add(tempItem);
            }
            ViewBag.dataSource = dataSourceItemList;
            return(PartialView(m));
        }