public static void CreateBranchUserAdminRolesForUserForAllBranches(ApplicationDbContext db, BranchUser branchUser, UserRoleEnum userRole) { List <Branch> companyBranches = BranchHelpers.GetBranchesForCompany(db, branchUser.CompanyId); foreach (Branch branch in companyBranches) { BranchUser thisBranchUser = BranchUserHelpers.GetBranchUser(db, branchUser.UserId, branch.BranchId, branch.CompanyId); //Update if required else create new if missing if (thisBranchUser != null) { //if this branchuser is having the status changed then just check any outstanding actions and remove if (userRole != thisBranchUser.UserRole) { thisBranchUser.UserRole = userRole; thisBranchUser.EntityStatus = EntityStatusEnum.Active; db.Entry(branchUser).State = EntityState.Modified; db.SaveChanges(); } } else { BranchUserHelpers.CreateBranchUser(db, branchUser.UserId, branch.BranchId, branch.CompanyId, userRole, EntityStatusEnum.Active); } } }
/// <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; } }
public static CompanyAdminView GetCompanyAdminView(ApplicationDbContext db, IPrincipal user) { //get company Company company = CompanyHelpers.GetCompanyForUser(user); //Get linked branches to this company List <Branch> branches = BranchHelpers.GetBranchesForCompany(db, company.CompanyId); //Build view CompanyAdminView companyAdminView = new CompanyAdminView() { CompanyDetails = company, RelatedBranches = branches }; return(companyAdminView); }
public static SelectList AllBranchesForCompany(Guid companyId) { return(new SelectList(BranchHelpers.GetBranchesForCompany(companyId), "BranchId", "BranchName")); }
public static SelectList AllBranchesForCompanyListDropDown(Guid companyId, Guid branchId) { return(new SelectList(BranchHelpers.GetBranchesForCompany(companyId), "BranchId", "BranchName", branchId)); }