Beispiel #1
0
        public bool MapPermission(List <RolesPermissionViewModel> request, string roleId)
        {
            var oldPermissionMaps = _permissionMapRepository.GetAllActive().Where(x => x.RoleId == roleId).ToList();

            _permissionMapRepository.RemoveAll(oldPermissionMaps);
//            _permissionMapRepository.Commit();
            var newPermissionMaps = new List <PermissionMap>();

            foreach (var mapItem in request)
            {
                if (mapItem.HasPermission == true)
                {
                    PermissionMap newPermissionMap = new PermissionMap();
                    newPermissionMap.RoleId       = roleId;
                    newPermissionMap.PermissionId = mapItem.Id;

                    var user = GetUserFromToken();
                    newPermissionMap.Id             = Guid.NewGuid().ToString();
                    newPermissionMap.Created        = DateTime.Now;
                    newPermissionMap.Modified       = DateTime.Now;
                    newPermissionMap.CreatedBy      = user.Id;
                    newPermissionMap.ModifiedBy     = user.Id;
                    newPermissionMap.CreatedCompany = user.Company.Id;
                    newPermissionMap.Active         = true;
                    newPermissionMap.DeletedBy      = null;
                    newPermissionMap.DeletionTime   = null;

                    newPermissionMaps.Add(newPermissionMap);
                }
            }

            _permissionMapRepository.Add(newPermissionMaps);

            return(_permissionMapRepository.Commit());
        }
Beispiel #2
0
        public bool getPermissionsById(string roleId, string permissionId)
        {
            var exist = _permissionMapRepository.GetAllActive().FirstOrDefault(x => x.PermissionId == permissionId && x.RoleId == roleId);

            if (exist == null)
            {
                return(false);
            }
            return(true);
        }