Exemplo n.º 1
0
        public List <AuthPermissionsViewModel> GetAllNavigationPermissionsInGroup(int tenantId)
        {
            var tenantModules = _tenantsServices.GetAllTenantModules(0).Select(m => m.ModuleId);

            return((from e in _currentDbContext.AuthActivities
                    join t in _currentDbContext.AuthActivityGroupMaps on e.ActivityId equals t.ActivityId
                    join x in _currentDbContext.AuthActivityGroups on t.ActivityGroupId equals x.ActivityGroupId
                    where t.IsDeleted != true && e.IsActive == true && e.IsDeleted != true && e.RightNav == true && (!e.ModuleId.HasValue || tenantModules.Contains(e.ModuleId.Value))
                    select new AuthPermissionsViewModel
            {
                Controller = e.ActivityController,
                Action = e.ActivityAction,
                ActivityName = e.ActivityName,
                SortOrder = e.SortOrder,
                ActivityGroupId = x.ActivityGroupId
            }).OrderBy(x => x.SortOrder).ThenBy(a => a.ActivityName).ToList());
        }
        //change user permissions  quick
        public ActionResult UserPermissions(int?id)
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }
            string        Checked       = "";
            StringBuilder stringBuilder = new StringBuilder();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            caTenant tenant = caCurrent.CurrentTenant();
            caUser   user   = caCurrent.CurrentUser();

            var userModules = _tenantServices.GetAllTenantModules(user.TenantId).Select(m => m.ModuleId).ToList();

            ICollection <TenantLocations> WareHouse = tenant.TenantLocations.Where(x => x.IsMobile != true).ToList();

            stringBuilder.Append(string.Format("<input type=\"hidden\" name=\"UserId\" value=\"{0}\" />", id));

            foreach (TenantLocations vh in WareHouse)
            {
                stringBuilder.Append(string.Format("<div id=\"page-wrap{0}\" class=\"page-wrap form-horizontal\">", vh.WarehouseId));
                stringBuilder.Append("<ul>");
                stringBuilder.Append("<li>");
                stringBuilder.Append(string.Format("<input type=\"checkbox\" name=\"wareh\" id=\"wareh-{0}\" value=\"{0}\">", vh.WarehouseId, vh.WarehouseName));
                stringBuilder.Append(string.Format("<label for=\"wareh-{0}\">{1}</label>", vh.WarehouseId, vh.WarehouseName));

                stringBuilder.Append("<ul class=\"wareh-ul\">");

                var Groups = _activityServices.GetDistinctActivityGroupsForPerm(userModules);

                foreach (var Grp in Groups)
                {
                    stringBuilder.Append("<li class=\"group-li\">");
                    stringBuilder.Append(string.Format("<input type=\"checkbox\" name=\"group-{0}-{1}\" id=\"group-{0}-{1}\" value=\"{1}\">", vh.WarehouseId, Grp.ActivityGroupId));
                    stringBuilder.Append(string.Format("<label for=\"group-{0}-{1}\">{2}</label>", vh.WarehouseId, Grp.ActivityGroupId, Grp.ActivityGroupName));
                    stringBuilder.Append("<ul class=\"group-ul\">");

                    var nav = _activityServices.GetAuthActivitiesForPermByGroup(Grp, userModules, CurrentTenantId);

                    foreach (var perm in nav)
                    {
                        if (_activityServices.PermCheckByActivityId(perm.ActivityId, (int)id, vh.WarehouseId))
                        {
                            Checked = "checked";
                        }

                        stringBuilder.Append("<li class=\"col-lg-2 col-md-3 col-sm-4 pull-left\">");
                        stringBuilder.Append(string.Format("<input type=\"checkbox\" name=\"perm\" id=\"{0}-{1}\" {2} value=\"{0}-{1}\">", vh.WarehouseId, perm.ActivityId, Checked));
                        stringBuilder.Append(string.Format("<label for=\"{0}-{1}\">{2}</label>", vh.WarehouseId, perm.ActivityId, perm.ActivityName));
                        stringBuilder.Append("</li>");

                        Checked = "";
                    }

                    stringBuilder.Append("</ul>");
                    stringBuilder.Append("</li>");
                }

                // check the activities which are not in any group
                var nav2 = _activityServices.GetAuthActivitiesForPermNoGroup(userModules);

                if (nav2.Count() > 0)
                {
                    stringBuilder.Append("<li>");
                    stringBuilder.Append(string.Format("<input type=\"checkbox\" name=\"Misc-{0}\" id=\"Misc-{0}\" value=\"{0}\">", vh.WarehouseId));
                    stringBuilder.Append(string.Format("<label for=\"Misc-{0}\">Miscellaneous</label>", vh.WarehouseId));
                    stringBuilder.Append("<ul>");

                    foreach (var perm2 in nav2)
                    {
                        if (_activityServices.PermCheckByActivityId(perm2.ActivityId, (int)id, vh.WarehouseId))
                        {
                            Checked = "checked";
                        }

                        stringBuilder.Append("<li>");
                        stringBuilder.Append(string.Format("<input type=\"checkbox\" name=\"perm\" id=\"{0}-{1}\" {2} value=\"{0}-{1}\">", vh.WarehouseId, perm2.ActivityId, Checked));
                        stringBuilder.Append(string.Format("<label for=\"{0}-{1}\">{2}</label>", vh.WarehouseId, perm2.ActivityId, perm2.ActivityName));
                        stringBuilder.Append("</li>");

                        Checked = "";
                    }

                    stringBuilder.Append("</ul>");
                    stringBuilder.Append("</li>");
                }

                stringBuilder.Append("</ul>");
                stringBuilder.Append("</li>");
                stringBuilder.Append("</ul>");
                stringBuilder.Append("</div>");
            }

            stringBuilder.Append("<div class=\"page-wrap-btn\">");
            stringBuilder.Append("</div>");

            ViewBag.permissions = stringBuilder.ToString();
            return(View());
        }