public virtual TEntity Delete(object id)
        {
            var entity = Repository.Get(id);

            Repository.Delete(entity);
            Repository.Save();

            return(entity);
        }
Esempio n. 2
0
        public void DeleteRole(Guid guid)
        {
            var role = roleRepository.Get(x => x.Id == guid);

            if (role == null)
            {
                throw new ArgumentNullException("Guid don't represent a valid role");
            }

            roleRepository.Delete(role);
            securityUnitOfWork.Commit();
        }
Esempio n. 3
0
        public void DeleteUser(Guid guid)
        {
            var user = userRepository.Get(x => x.Id == guid);

            if (user == null)
            {
                throw new ArgumentNullException("Guid don't represent a valid user");
            }

            userRepository.Delete(user);
            securityUnitOfWork.Commit();
        }
Esempio n. 4
0
        public void DeleteUserRole(int id)
        {
            var userRole = userRoleRepository.Get(x => x.Id == id);

            if (userRole == null)
            {
                throw new ArgumentNullException("Id don't represent a valid user role");
            }

            userRoleRepository.Delete(userRole);
            securityUnitOfWork.Commit();
        }
        public void DeleteWebsitePermission(int id)
        {
            var webSiteAccessPermission = webSiteAccessPermissionRepository.Get(x => x.Id == id);

            if (webSiteAccessPermission == null)
            {
                throw new ArgumentNullException("Id don't represent a valid website access permission");
            }

            webSiteAccessPermissionRepository.Delete(webSiteAccessPermission);
            securityUnitOfWork.Commit();
        }
        public bool AddList(List <Permission> models)
        {
            List <Permission> missingModels = new List <Permission>();

            var resources = _resourceRepository.GetAllIgnoreFilter().Where(x => x.IsPublic == false).ToList();

            foreach (var model in models)
            {
                var resource       = resources.First(x => x.Id == model.ResourceId);
                var parentResource = resources.FirstOrDefault(x => x.Route == resource.ParentRoute);
                if (parentResource != null && models.All(x => x.ResourceId != parentResource.Id) && missingModels.All(x => x.ResourceId != parentResource.Id))
                {
                    missingModels.Add(new Permission()
                    {
                        Id         = Guid.NewGuid().ToString(),
                        ResourceId = parentResource.Id,
                        RoleId     = model.RoleId,
                        TenantId   = model.TenantId
                    });
                }
            }


            if (missingModels.Any())
            {
                models.AddRange(missingModels);
            }


            var permissions = models.Select(model => _repository.GetAll().Where(x => x.RoleId == model.RoleId).ToList()).FirstOrDefault();

            if (permissions != null)
            {
                _repository.Delete(permissions);
            }

            if (models.Any(model => model.ResourceId != "00000000-0000-0000-0000-000000000000"))
            {
                _repository.Create(models);
            }

            _repository.Save();

            return(true);
        }