/// <summary> /// Remove from friend list if there (at the correct level) // - company - blats all company, branch and users // - branch - blats the branch and it's users (even if users on other branches) // - users - blats that user /// </summary> /// <param name="db"></param> /// <param name="level"></param> /// <param name="ofReferenceId"></param> /// <param name="byReferenceId"></param> /// <param name="byAppUserId"></param> public static void RemoveFriendItemsDueToBlock(ApplicationDbContext db, LevelEnum level, Guid ofReferenceId, Guid byReferenceId, Guid byAppUserId) { switch (level) { case LevelEnum.Company: //Remove the company level RemoveFriend(db, level, ofReferenceId, byReferenceId); //Remove the branches for that company from our company branches List <Branch> ofBranches = BranchHelpers.GetBranchesForCompany(db, ofReferenceId); List <Branch> byBranches = BranchHelpers.GetBranchesForCompany(db, byReferenceId); foreach (Branch ofBranch in ofBranches) { foreach (Branch byBranch in byBranches) { RemoveFriend(db, LevelEnum.Branch, ofBranch.BranchId, byBranch.BranchId); } } //Remove users of that company from our company users List <AppUser> ofCompanyUsers = AppUserHelpers.GetAppUsersForCompany(db, ofReferenceId); List <AppUser> byCompanyUsers = AppUserHelpers.GetAppUsersForCompany(db, byReferenceId); foreach (AppUser ofUser in ofCompanyUsers) { foreach (AppUser byUser in byCompanyUsers) { RemoveFriend(db, LevelEnum.User, ofUser.AppUserId, byUser.AppUserId); } } break; case LevelEnum.Branch: //Remove the branch level RemoveFriend(db, level, ofReferenceId, byReferenceId); //Remove users of that branch from our branch users List <AppUser> ofBranchUsers = AppUserHelpers.GetAppUsersForBranch(db, ofReferenceId); List <AppUser> byBranchUsers = AppUserHelpers.GetAppUsersForBranch(db, byReferenceId); foreach (AppUser ofUser in ofBranchUsers) { foreach (AppUser byUser in byBranchUsers) { RemoveFriend(db, LevelEnum.User, ofUser.AppUserId, byUser.AppUserId); } } break; case LevelEnum.User: RemoveFriend(db, level, ofReferenceId, byReferenceId); break; } }