예제 #1
0
        public ActionResult Gebruikers(int?vanaf, int?desc, string search, int?mode, int?filter)
        {
            Session.Remove("stap3");
            Session["stap2"] = "Gebruikers";
            Session["url2"]  = "/../admin/gebruikers";
            ViewBag.stap1    = Session["stap1"];
            ViewBag.url1     = Session["url1"];
            ViewBag.stap2    = Session["stap2"];
            ViewBag.url2     = Session["url2"];
            if (search == null)
            {
                search = "";
            }
            if (TempData["Feedback"] != null)
            {
                UitnodigingFeedbackPM fb = TempData["Feedback"] as UitnodigingFeedbackPM;
                if (fb.Foutief == null && fb.Gebruikt == null)
                {
                    ViewBag.IsFout = false;
                }
                else
                {
                    ViewBag.IsFout   = true;
                    ViewBag.Fouten   = fb.Foutief;
                    ViewBag.Gebruikt = fb.Gebruikt;
                }
            }
            //mode == 1 -> json
            //mode == 0/null -> view

            //desc == 1 -> descending
            //desc == 0 -> ascending
            bool DisplayDeleted = false;

            if (bs.GetUser(User.Identity.Name).Roles.Any(r => r.RoleId == "1d3abf19-db82-484c-b93b-a4d7d21bc0a5"))
            {
                DisplayDeleted = true;
            }

            List <UserActivities>  ua  = new List <UserActivities>();
            List <ApplicationUser> res = new List <ApplicationUser>();

            if (!filter.HasValue)
            {
                filter = 0;
            }
            if (!vanaf.HasValue)
            {
                vanaf = 0;
            }
            if (!desc.HasValue)
            {
                desc = 0;
            }

            switch ((int)filter)
            {
            case 1:
                if (desc == 1)
                {
                    res = bs.GetUserNext30SortNaamZA((int)vanaf, search, DisplayDeleted);
                }
                else
                {
                    res = bs.GetUserNext30SortNaamAZ((int)vanaf, search, DisplayDeleted);
                }
                break;

            case 2:
                if (desc == 1)
                {
                    res = bs.GetUserNext30SortEmailZA((int)vanaf, search, DisplayDeleted);
                }
                else
                {
                    res = bs.GetUserNext30SortEmailAZ((int)vanaf, search, DisplayDeleted);
                }
                break;

            case 4:
                if (desc == 1)
                {
                    res = bs.GetUserNext30SortRoleZA((int)vanaf, search, DisplayDeleted);
                }
                else
                {
                    res = bs.GetUserNext30SortRoleAZ((int)vanaf, search, DisplayDeleted);
                }
                break;

            case 5:
                if (desc == 1)
                {
                    res = bs.GetUserNext30SortDeletedZA((int)vanaf, search, DisplayDeleted);
                }
                else
                {
                    res = bs.GetUserNext30SortDeletedAZ((int)vanaf, search, DisplayDeleted);
                }
                break;

            default:
                if (desc == 1)
                {
                    res = bs.GetUserNext30SortNaamZA((int)vanaf, search, DisplayDeleted);
                }
                else
                {
                    res = bs.GetUserNext30SortNaamAZ((int)vanaf, search, DisplayDeleted);
                }
                break;
            }


            foreach (ApplicationUser user in res)
            {
                UserActivities u = new UserActivities();
                u.User         = user;
                u.Activiteiten = bs.GetActivitiesByUsername(user.UserName);
                if (user.Roles.Any(x => x.RoleId == "f611bbe6-00e1-42fe-b34b-831e8383476b"))
                {
                    u.Role = "User";
                }
                if (user.Roles.Any(x => x.RoleId == "a8bd3f1c-2d04-43e8-b02e-a27ee2c9a19e"))
                {
                    u.Role = "Administrator";
                }
                if (user.Roles.Any(x => x.RoleId == "1d3abf19-db82-484c-b93b-a4d7d21bc0a5"))
                {
                    u.Role = "SuperAdministrator";
                }

                ua.Add(u);
            }


            ViewBag.vanaf  = vanaf;
            ViewBag.desc   = desc;
            ViewBag.filter = filter;
            GebruikersPM gpm = new GebruikersPM();

            gpm.UserActivities = ua;
            gpm.Uitnodigingen  = bs.GetUitnodigingenOpenByUser(User.Identity.Name);

            if (!mode.HasValue || (int)mode == 0)
            {
                return(View(gpm));
            }
            else
            {
                var jsonResult = Json(JsonConvert.SerializeObject(ua), JsonRequestBehavior.AllowGet);
                jsonResult.MaxJsonLength = int.MaxValue;
                return(jsonResult);
            }
        }