public virtual bool CanDelete(Permission item) { if (item == null) throw new ArgumentNullException("Permission"); if (item.Id == default(Guid)) throw new Exception("Permission id cannot be empty."); bool canDelete = false; var rolesWithPermissionCount = _roleRepository.Query.Where(x => x.Permissions.Any(y => y.Id == item.Id)).Count(); if (rolesWithPermissionCount <= 0) canDelete = true; return canDelete; }
public virtual bool UpdatePermission(Permission newPermission) { var permission = _permissionRepository.Query.Where(x => x.Id == newPermission.Id).SingleOrDefault(); permission.Name = newPermission.Name; permission.Description = newPermission.Description; using (var scope = new UnitOfWorkScope()) { _permissionRepository.Update(permission); scope.Commit(); } StringBuilder message = new StringBuilder(); message.AppendFormat("Permission {0} is updated.", permission.Name); ActivityLog item = new ActivityLog(ActivityType.UpdatePermission.ToString(), message.ToString()); _activityLogService.Add(item); return true; }
public virtual Permission CreatePermission(Permission permission) { Permission matchedPermission = _permissionRepository.Query.FirstOrDefault(x => x.Name == permission.Name); if (matchedPermission != null) throw new Exception(string.Format("Permission {0} already exist.", permission.Name)); using (var scope = new UnitOfWorkScope()) { _permissionRepository.Add(permission); scope.Commit(); } StringBuilder message = new StringBuilder(); message.AppendFormat("Permission {0} is created.", permission.Name); ActivityLog item = new ActivityLog(ActivityType.AddPermission.ToString(), message.ToString()); _activityLogService.Add(item); return permission; }