public static RequirementListing CreateRequirementListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?requiredFrom, DateTime?requiredTo, bool acceptDamagedItems, bool acceptOutOfDateItems, bool collectionAvailable, ItemRequiredListingStatusEnum listingStatus, Guid?selectedCampaignId) { BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user); Branch branch = BranchHelpers.GetBranch(db, branchUser.BranchId); RequirementListing requirementListing = new RequirementListing() { ListingId = Guid.NewGuid(), ItemDescription = itemDescription, ItemCategory = itemCategory, ItemType = itemType, QuantityRequired = quantityRequired, QuantityFulfilled = 0, QuantityOutstanding = quantityRequired, UoM = uom, RequiredFrom = requiredFrom, RequiredTo = requiredTo, AcceptDamagedItems = acceptDamagedItems, AcceptOutOfDateItems = acceptOutOfDateItems, CollectionAvailable = collectionAvailable, ListingBranchPostcode = branch.AddressPostcode, ListingOriginatorAppUserId = branchUser.UserId, ListingOriginatorBranchId = branchUser.BranchId, ListingOriginatorCompanyId = branchUser.CompanyId, ListingOriginatorDateTime = DateTime.Now, ListingStatus = ItemRequiredListingStatusEnum.Open, CampaignId = selectedCampaignId }; db.RequirementListings.Add(requirementListing); db.SaveChanges(); return(requirementListing); }
public static List <AvailableListing> GetAllManageListingFilteredAvailableListings(ApplicationDbContext db, Guid appUserId, bool getHistory) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); var dateCheck = DateTime.MinValue; //Create list within the time frame if setting set List <AvailableListing> list = new List <AvailableListing>(); //Now bring in the Selection Level sort switch (settings.AvailableListingManageViewInternalSelectionLevel) { case InternalSearchLevelEnum.User: list = GetAllAvailableListingsForUser(db, appUserId, getHistory); break; case InternalSearchLevelEnum.Branch: //user's current branch to filter list = GetAllAvailableListingsForBranch(db, branch.BranchId, getHistory); break; case InternalSearchLevelEnum.Company: //user's current company to filter list = GetAllAvailableListingsForCompany(db, branch.CompanyId, getHistory); break; case InternalSearchLevelEnum.Group: //user's built group sets to filter ***TO BE DONE*** break; } return(list); }
public static List <Offer> GetAllManageListingFilteredOffers(ApplicationDbContext db, Guid appUserId, bool getHistory) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); //Create list List <Offer> list = new List <Offer>(); //Now bring in the Selection Level sort switch (settings.OffersManageViewInternalSelectionLevel) { case InternalSearchLevelEnum.User: list = GetAllOffersForUser(db, appUserId, getHistory); break; case InternalSearchLevelEnum.Branch: //user's current branch to filter list = GetAllOffersForBranch(db, branch.BranchId, getHistory); break; case InternalSearchLevelEnum.Company: //user's current company to filter list = GetAllOffersForCompany(db, branch.CompanyId, getHistory); break; case InternalSearchLevelEnum.Group: //user's built group sets to filter ***TO BE DONE*** break; } return(list); }
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> /// Gets the relevant Guid for the level of internal authorisation sent /// i.e. If this is a 'User' level of authorisation, then the current user AppUserId is returned. /// </summary> /// <param name="authorisationLevel"></param> /// <param name="user"></param> /// <returns></returns> public static Guid GetAuthorisationId(InternalSearchLevelEnum authorisationLevel, IPrincipal user) { Guid id = Guid.Empty; AppUser appUser = AppUserHelpers.GetAppUser(user); Branch branch = BranchHelpers.GetBranch(appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(appUser.AppUserId); switch (settings.OrdersDespatchedAuthorisationManageViewLevel) { case InternalSearchLevelEnum.User: id = appUser.AppUserId; break; case InternalSearchLevelEnum.Branch: id = branch.BranchId; break; case InternalSearchLevelEnum.Company: id = branch.CompanyId; break; case InternalSearchLevelEnum.Group: //TO BE DONE LSLSLS id = appUser.AppUserId; break; } return(id); }
public static AvailableListing CreateAvailableListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?availableFrom, DateTime?availableTo, ItemConditionEnum itemCondition, DateTime?displayUntilDate, DateTime?sellByDate, DateTime?useByDate, bool?deliveryAvailable, ItemRequiredListingStatusEnum listingStatus) { BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user); Branch branch = BranchHelpers.GetBranch(db, branchUser.BranchId); AvailableListing AvailableListing = new AvailableListing() { ListingId = Guid.NewGuid(), ItemDescription = itemDescription, ItemCategory = itemCategory, ItemType = itemType, QuantityRequired = quantityRequired, QuantityFulfilled = 0, QuantityOutstanding = quantityRequired, UoM = uom, AvailableFrom = availableFrom, AvailableTo = availableTo, ItemCondition = itemCondition, DisplayUntilDate = displayUntilDate, SellByDate = sellByDate, UseByDate = useByDate, DeliveryAvailable = deliveryAvailable ?? false, ListingBranchPostcode = branch.AddressPostcode, ListingOriginatorAppUserId = branchUser.UserId, ListingOriginatorBranchId = branchUser.BranchId, ListingOriginatorCompanyId = branchUser.CompanyId, ListingOriginatorDateTime = DateTime.Now, ListingStatus = ItemRequiredListingStatusEnum.Open }; db.AvailableListings.Add(AvailableListing); db.SaveChanges(); return(AvailableListing); }
public static string GetCompanyNameTownPostCode(ApplicationDbContext db, Guid companyId) { Company company = GetCompany(db, companyId); Branch headOffice = BranchHelpers.GetBranch(db, company.HeadOfficeBranchId); return(headOffice.BranchName + ", " + headOffice.AddressTownCity + ", " + headOffice.AddressPostcode); }
public static void ReassignAllTasksForUserChangingRoleFromAdmin(ApplicationDbContext db, Guid appUserId) { List <UserTaskAssignment> list = (from uta in db.UserTaskAssignments where uta.AppUserId == appUserId select uta).ToList(); List <Guid> taskGuidsFromList = (from l in list select l.UserTaskId).Distinct().ToList(); //Find current admins for the company List <AppUser> admins = AppUserHelpers.GetAdminAppUsersForCompany(db, BranchHelpers.GetBranch(db, AppUserHelpers.GetAppUser(db, appUserId).CurrentBranchId).CompanyId); //now match up admins to tasks and if any are missing add them foreach (Guid task in taskGuidsFromList) { foreach (AppUser admin in admins) { List <Guid> assignedToTask = (from l in list where l.UserTaskId == task select l.AppUserId).ToList(); Guid result = assignedToTask.Find(x => x == admin.AppUserId); if (result == Guid.Empty) { CopyTaskFromUserAToUserB(db, task, appUserId, admin.AppUserId); } } } }
public static List <AvailableListing> GetAllGeneralInfoFilteredAvailableListings(ApplicationDbContext db, Guid appUserId) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); var dateCheck = DateTime.MinValue; int settingsMaxDistance = settings.AvailableListingGeneralInfoMaxDistance ?? 0; //Create list within the time frame if setting set List <AvailableListing> list = (from rl in db.AvailableListings where ((rl.ListingStatus == ItemRequiredListingStatusEnum.Open || rl.ListingStatus == ItemRequiredListingStatusEnum.Partial) && rl.ListingOriginatorDateTime >= dateCheck) orderby rl.AvailableTo ?? DateTime.MaxValue select rl).ToList(); //Now bring in the Selection Level sort switch (settings.AvailableListingGeneralInfoExternalSelectionLevel) { case ExternalSearchLevelEnum.All: //do nothing break; case ExternalSearchLevelEnum.Branch: //user's current branch to filter list = list.Where(l => l.ListingOriginatorBranchId == branch.BranchId).ToList(); break; case ExternalSearchLevelEnum.Company: //user's current company to filter list = list.Where(l => l.ListingOriginatorCompanyId == branch.CompanyId).ToList(); break; case ExternalSearchLevelEnum.Group: //LSLSLS user's built group sets to filter ***TO BE DONE*** break; } //Now sort by distance if (settingsMaxDistance > 0) { List <AvailableListing> removeList = new List <AvailableListing>(); foreach (AvailableListing listing in list) { DistanceHelpers distance = new DistanceHelpers(); int distanceValue = distance.GetDistance(branch.AddressPostcode, listing.ListingBranchPostcode); if (distanceValue > settingsMaxDistance) { removeList.Add(listing); } } if (removeList.Count > 0) { list.RemoveAll(l => removeList.Contains(l)); } } return(list); }
public static List <Campaign> GetAllGeneralInfoFilteredCampaigns(ApplicationDbContext db, Guid appUserId) { AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId); Branch branch = BranchHelpers.GetBranch(db, appUser.CurrentBranchId); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserId); var dateCheck = DateTime.MinValue; int settingsMaxDistance = settings.CampaignGeneralInfoMaxDistance ?? 0; //Create list within the time frame if setting set List <Campaign> list = (from c in db.Campaigns where (c.EntityStatus == EntityStatusEnum.Active && c.CampaignOriginatorDateTime >= dateCheck) orderby c.CampaignEndDateTime ?? DateTime.MaxValue select c).ToList(); //Now bring in the Selection Level sort switch (settings.CampaignGeneralInfoExternalSelectionLevel) { case ExternalSearchLevelEnum.All: //do nothing break; case ExternalSearchLevelEnum.Branch: //user's current branch to filter list = list.Where(l => l.CampaignOriginatorBranchId == branch.BranchId).ToList(); break; case ExternalSearchLevelEnum.Company: //user's current company to filter list = list.Where(l => l.CampaignOriginatorCompanyId == branch.CompanyId).ToList(); break; case ExternalSearchLevelEnum.Group: //user's built group sets to filter ***TO BE DONE*** break; } //Now sort by distance if (settingsMaxDistance > 0) { List <Campaign> removeList = new List <Campaign>(); foreach (Campaign campaign in list) { DistanceHelpers distance = new DistanceHelpers(); int distanceValue = distance.GetDistance(branch.AddressPostcode, campaign.LocationAddressPostcode); if (distanceValue > settingsMaxDistance) { removeList.Add(campaign); } } if (removeList.Count > 0) { list.RemoveAll(l => removeList.Contains(l)); } } return(list); }
public static OfferManageView GetOfferManageViewForOffer(ApplicationDbContext db, Offer offer, IPrincipal user) { AppUser offerAppUser = AppUserHelpers.GetAppUser(db, offer.OfferOriginatorAppUserId); AvailableListing availableListing = null; RequirementListing requirementListing = null; AppUser listingAppUser = null; switch (offer.ListingType) { case ListingTypeEnum.Available: availableListing = AvailableListingHelpers.GetAvailableListing(db, offer.ListingId); listingAppUser = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId); break; case ListingTypeEnum.Requirement: requirementListing = RequirementListingHelpers.GetRequirementListing(db, offer.ListingId); listingAppUser = AppUserHelpers.GetAppUser(db, requirementListing.ListingOriginatorAppUserId); break; } OfferManageView offerManageView = new OfferManageView() { OfferDetails = offer, AvailableListingDetails = availableListing, RequirementListingDetails = requirementListing, OfferAppUserDetails = offerAppUser, ListingAppUserDetails = listingAppUser, OfferBranchDetails = BranchHelpers.GetBranch(db, offerAppUser.CurrentBranchId), ListingBranchDetails = BranchHelpers.GetBranch(db, listingAppUser.CurrentBranchId), OfferAppUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, offerAppUser.AppUserId), ListingAppUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, listingAppUser.AppUserId) }; AppUser thisAppUser = AppUserHelpers.GetAppUser(db, user); //If we allow branch trading then differentiate between branches for in/out trading, otherwise it is at company level Company thisCompany = CompanyHelpers.GetCompanyForUser(db, user); //set Inhouse flag offerManageView.InhouseOffer = OfferProcessHelpers.SetInhouseFlag(offer, thisAppUser, thisCompany); //set buttons bool?displayAcceptButton = null; bool?displayRejectButton = null; bool?displayCounterButton = null; bool?displayOfferButton = null; OfferProcessHelpers.SetOrderButtons(db, user, offerManageView, out displayAcceptButton, out displayRejectButton, out displayCounterButton, out displayOfferButton); offerManageView.DisplayAcceptButton = displayAcceptButton; offerManageView.DisplayRejectButton = displayRejectButton; offerManageView.DisplayCounterButton = displayCounterButton; offerManageView.DisplayOfferButton = displayOfferButton; return(offerManageView); }
public static List <Block> GetBlocksCreatedByUserBranches(ApplicationDbContext db, Guid appUserId) { List <Branch> userBranches = BranchHelpers.GetBranchesForUser(db, appUserId); List <Block> list = (from ub in userBranches join b in db.Blocks on ub.BranchId equals b.BlockedById select b).Distinct().ToList(); return(list); }
public static List <Friend> GetFriendsCreatedByUserBranches(ApplicationDbContext db, Guid appUserId) { List <Branch> userBranches = BranchHelpers.GetBranchesForUser(db, appUserId); List <Friend> list = (from ub in userBranches join f in db.Friends on ub.BranchId equals f.RequestedById select f).Distinct().ToList(); return(list); }
public static Branch UpdateEntityStatus(ApplicationDbContext db, Guid branchId, EntityStatusEnum entityStatus) { Branch branch = BranchHelpers.GetBranch(db, branchId); branch.EntityStatus = entityStatus; db.Entry(branch).State = EntityState.Modified; db.SaveChanges(); return(branch); }
public static GroupAddView GetGroupAddView(ApplicationDbContext db, LevelEnum?level, Guid?ofReferenceId, Guid?byReferenceId, Guid?byAppUserId, Guid appUserId) { //Build a list of companies/branches/users from level if set List <GroupAddMemberView> members = new List <GroupAddMemberView>(); GroupAddView view = new GroupAddView(); if (level != null) //Build a list of users for this view { switch (level.Value) { case LevelEnum.Company: List <Company> companies = CompanyHelpers.GetAllCompaniesForGroupForUser(db, appUserId); foreach (Company company in companies) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, company.CompanyId, company.CompanyName)); } break; case LevelEnum.Branch: List <Branch> branches = BranchHelpers.GetAllBranchesForGroupForUser(db, appUserId); foreach (Branch branch in branches) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, branch.BranchId, branch.BranchName + ", " + branch.AddressTownCity)); } break; case LevelEnum.User: List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, appUserId); foreach (AppUser user in users) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, user.AppUserId, user.FirstName + " " + user.LastName)); } break; } view.Type = level.Value; view.scratchEntry = false; view.Members = members; } else //return blank view with blank users as this is new from scratch { view.scratchEntry = true; //this will be used in view to stop the changing fo the 'type' field. //build members as User as this is the default List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, appUserId); foreach (AppUser user in users) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, user.AppUserId, user.FirstName + " " + user.LastName)); } view.Members = members; } return(view); }
public static List <CampaignGeneralInfoView> GetAllCampaignsGeneralInfoView(ApplicationDbContext db, IPrincipal user) { List <CampaignGeneralInfoView> allCampaignsGeneralInfoView = new List <CampaignGeneralInfoView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUser.AppUserId); Branch currentBranch = BranchHelpers.GetBranch(appUser.CurrentBranchId); List <Campaign> allCampaigns = CampaignHelpers.GetAllGeneralInfoFilteredCampaigns(db, appUser.AppUserId); foreach (Campaign campaign in allCampaigns) { bool userBlocked = false; bool branchBlocked = false; bool companyBlocked = false; BlockHelpers.GetBlocksForAllTypesForSpecificOfBy(db, campaign.CampaignOriginatorAppUserId, appUser.AppUserId, campaign.CampaignOriginatorBranchId, currentBranch.BranchId, campaign.CampaignOriginatorCompanyId, currentBranch.CompanyId, out userBlocked, out branchBlocked, out companyBlocked); bool userMatchedOwner = false; bool branchMatchedOwner = false; bool companyMatchedOwner = false; if (currentBranch.CompanyId == campaign.CampaignOriginatorCompanyId) { companyMatchedOwner = true; } if (currentBranch.BranchId == campaign.CampaignOriginatorBranchId) { branchMatchedOwner = true; } if (appUser.AppUserId == campaign.CampaignOriginatorAppUserId) { userMatchedOwner = true; } CampaignGeneralInfoView campaignGeneralInfoView = new CampaignGeneralInfoView() { Campaign = campaign, UserLevelBlock = userBlocked, BranchLevelBlock = branchBlocked, CompanyLevelBlock = companyBlocked, DisplayBlocks = settings.CampaignGeneralInfoDisplayBlockedListings, CompanyLevelOwner = companyMatchedOwner, DisplayMyCompanyRecords = settings.CampaignGeneralInfoDisplayMyUserListings, BranchLevelOwner = branchMatchedOwner, DisplayMyBranchRecords = settings.CampaignGeneralInfoDisplayMyBranchListings, UserLevelOwner = userMatchedOwner, DisplayMyRecords = settings.CampaignGeneralInfoDisplayMyUserListings }; allCampaignsGeneralInfoView.Add(campaignGeneralInfoView); } return(allCampaignsGeneralInfoView); }
public static List <Branch> GetAllBranchesForGroupForUser(ApplicationDbContext db, Guid appUserId) { List <Branch> allBranches = GetAllBranches(db); //Remove branches for current user List <Branch> userBranches = BranchHelpers.GetBranchesForUser(db, appUserId); allBranches.RemoveAll(x => userBranches.Any(y => y.BranchId == x.BranchId)); return(allBranches); }
/// <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 List <UserActionView> GetActionsForViewsForUser(ApplicationDbContext db, IPrincipal user) { List <UserActionView> list = new List <UserActionView>(); List <UserAction> userActionList = UserActionHelpers.GetActionsForUser(db, user); foreach (UserAction userAction in userActionList) { string referenceName = ""; switch (userAction.ActionLevel) { case LevelEnum.Company: referenceName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.ReferenceKey); break; case LevelEnum.Branch: referenceName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.ReferenceKey); break; case LevelEnum.User: referenceName = AppUserHelpers.GetAppUserName(db, userAction.ReferenceKey); break; } string createdByName = ""; //Get the user that created the action. Note, this could be at Company or Branch level, so try the user first, if that //fails then work through a switch try { createdByName = AppUserHelpers.GetAppUserName(db, userAction.CreatedBy); } catch { switch (userAction.ActionLevel) { case LevelEnum.Company: createdByName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.CreatedBy); break; case LevelEnum.Branch: createdByName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.CreatedBy); break; } } list.Add(CreateUserActionView(userAction, referenceName, createdByName)); } return(list); }
public static List <GroupListView> GetGroupListViewsCreatedByUser(ApplicationDbContext db, Guid appUserId) { List <GroupListView> list = new List <GroupListView>(); List <Group> allGroupsCreatedByUser = GroupHelpers.GetGroupsCreatedByUser(db, appUserId); foreach (Group group in allGroupsCreatedByUser) { //Get members of the group List <GroupMember> groupMembers = GroupMemberHelpers.GetMembersForGroup(db, group.GroupId); List <GroupMemberListView> groupMembersView = new List <GroupMemberListView>(); foreach (GroupMember member in groupMembers) { string memberName = null; switch (member.Type) { case LevelEnum.User: memberName = AppUserHelpers.GetAppUserName(db, member.ReferenceId); break; case LevelEnum.Branch: memberName = BranchHelpers.GetBranchNameTownPostCode(db, member.ReferenceId); break; case LevelEnum.Company: memberName = CompanyHelpers.GetCompanyNameTownPostCode(db, member.ReferenceId); break; } GroupMemberListView groupMemberListView = new GroupMemberListView() { GroupMember = member, GroupMemberName = memberName }; groupMembersView.Add(groupMemberListView); } //create view record to add to list of view records GroupListView view = new GroupListView(); view.Group = group; view.GroupOriginatorName = AppUserHelpers.GetAppUserName(db, view.Group.GroupOriginatorAppUserId); view.Members = groupMembersView; list.Add(view); } return(list); }
public static List <Branch> GetBranchesForUser(ApplicationDbContext db, Guid appUserId) { List <BranchUser> branchUserForUser = BranchUserHelpers.GetBranchUsersForUser(db, appUserId); List <Branch> branchesForUser = new List <Branch>(); foreach (BranchUser branchUser in branchUserForUser) { branchesForUser.Add(BranchHelpers.GetBranch(db, branchUser.BranchId)); } List <Branch> branchesForUserDistinct = branchesForUser.Distinct().ToList(); return(branchesForUserDistinct); }
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 List <Branch> GetBranchesForUserForAdminView(ApplicationDbContext db, Guid appUserId) { AppUser currentAppUser = AppUserHelpers.GetAppUser(db, appUserId); Branch currentBranch = BranchHelpers.GetBranch(db, currentAppUser.CurrentBranchId); BranchUser currentBranchUser = BranchUserHelpers.GetBranchUser(db, appUserId, currentAppUser.CurrentBranchId, currentBranch.CompanyId); List <BranchUser> branchUserForUser = BranchUserHelpers.GetBranchUsersForUserWithRole(db, appUserId, currentBranchUser.UserRole); List <Branch> branchesForUser = new List <Branch>(); foreach (BranchUser branchUser in branchUserForUser) { branchesForUser.Add(BranchHelpers.GetBranch(db, branchUser.BranchId)); } List <Branch> branchesForUserDistinct = branchesForUser.Distinct().ToList(); return(branchesForUserDistinct); }
public static GroupAddView GetGroupAddView(ApplicationDbContext db, string groupName, string level, IPrincipal user) { List <GroupAddMemberView> members = new List <GroupAddMemberView>(); GroupAddView view = new GroupAddView(); LevelEnum levelEnum = LevelEnum.User; switch (level) { case "Company": levelEnum = LevelEnum.Company; List <Company> companies = CompanyHelpers.GetAllCompaniesForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); foreach (Company company in companies) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, company.CompanyId, company.CompanyName)); } break; case "Branch": levelEnum = LevelEnum.Branch; List <Branch> branches = BranchHelpers.GetAllBranchesForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); foreach (Branch branch in branches) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, branch.BranchId, branch.BranchName + ", " + branch.AddressTownCity)); } break; case "User": levelEnum = LevelEnum.User; List <AppUser> users = AppUserHelpers.GetAllAppUsersForGroupForUser(db, AppUserHelpers.GetAppUserIdFromUser(user)); foreach (AppUser appUser in users) { members.Add(GroupMemberViewHelpers.CreateGroupAddMemberViewMember(db, false, appUser.AppUserId, appUser.FirstName + " " + appUser.LastName)); } break; } view.Name = groupName; view.Type = levelEnum; view.scratchEntry = true; //this only comes from the scratch entry values view.Members = members; return(view); }
public static CampaignEditView GetCampaignEditView(ApplicationDbContext db, Guid campaignId, IPrincipal user) { Campaign campaignDetails = CampaignHelpers.GetCampaign(db, campaignId); AppUser campaignAppUser = AppUserHelpers.GetAppUser(db, campaignDetails.CampaignOriginatorAppUserId); Branch campaignBranch = BranchHelpers.GetBranch(db, campaignDetails.CampaignOriginatorBranchId); Company campaignCompany = CompanyHelpers.GetCompany(db, campaignDetails.CampaignOriginatorCompanyId); ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, campaignAppUser, campaignBranch, campaignCompany, user); CampaignEditView view = new CampaignEditView() { CampaignId = campaignDetails.CampaignId, Name = campaignDetails.Name, StrapLine = campaignDetails.StrapLine, Description = campaignDetails.Description, Image = campaignDetails.Image, ImageLocation = campaignDetails.ImageLocation, Website = campaignDetails.Website, CampaignStartDateTime = campaignDetails.CampaignStartDateTime, CampaignEndDateTime = campaignDetails.CampaignEndDateTime, LocationName = campaignDetails.LocationName, LocationAddressLine1 = campaignDetails.LocationAddressLine1, LocationAddressLine2 = campaignDetails.LocationAddressLine2, LocationAddressLine3 = campaignDetails.LocationAddressLine3, LocationAddressTownCity = campaignDetails.LocationAddressTownCity, LocationAddressCounty = campaignDetails.LocationAddressCounty, LocationAddressPostcode = campaignDetails.LocationAddressPostcode, LocationTelephoneNumber = campaignDetails.LocationTelephoneNumber, LocationEmail = campaignDetails.LocationEmail, LocationContactName = campaignDetails.LocationContactName, EntityStatus = campaignDetails.EntityStatus, CampaignOriginatorDateTime = campaignDetails.CampaignOriginatorDateTime, CampaignAppUser = campaignAppUser, CampaignBranchDetails = campaignBranch, CampaignCompanyDetails = campaignCompany, Buttons = buttons }; return(view); }
public static List <UserTaskView> GetUserTasksForUserView(ApplicationDbContext db, Guid appUserId) { List <UserTaskView> userTasksForUserView = new List <UserTaskView>(); List <UserTask> userTasksForUser = UserTaskHelpers.GetUserTasksForUser(db, appUserId); foreach (UserTask userTaskForUser in userTasksForUser) { AppUser appUser = null; Branch branch = null; switch (userTaskForUser.TaskType) { case TaskTypeEnum.UserOnHold: appUser = AppUserHelpers.GetAppUser(db, userTaskForUser.ReferenceKey); break; case TaskTypeEnum.BranchOnHold: branch = BranchHelpers.GetBranch(db, userTaskForUser.ReferenceKey); break; } UserTaskView userTaskForUserView = new UserTaskView() { UserTaskId = userTaskForUser.UserTaskId, TaskType = userTaskForUser.TaskType, TaskDescription = userTaskForUser.TaskDescription, AppUserReference = appUser, BranchReference = branch, CreatedOn = userTaskForUser.CreatedOn, CreatedBy = AppUserHelpers.GetAppUser(db, userTaskForUser.CreatedBy), EntityStatus = userTaskForUser.EntityStatus }; userTasksForUserView.Add(userTaskForUserView); } return(userTasksForUserView); }
public static AvailableListingEditView GetAvailableListingEditView(ApplicationDbContext db, Guid listingId, IPrincipal user) { AvailableListing availableListing = AvailableListingHelpers.GetAvailableListing(db, listingId); AppUser listingAppUser = AppUserHelpers.GetAppUser(db, availableListing.ListingOriginatorAppUserId); Branch listingBranch = BranchHelpers.GetBranch(db, availableListing.ListingOriginatorBranchId); Company listingCompany = CompanyHelpers.GetCompany(db, availableListing.ListingOriginatorCompanyId); ViewButtons buttons = ViewButtonsHelpers.GetAvailableButtonsForSingleView(db, listingAppUser, listingBranch, listingCompany, user); AvailableListingEditView view = new AvailableListingEditView() { ListingId = availableListing.ListingId, ItemDescription = availableListing.ItemDescription, ItemCategory = availableListing.ItemCategory, ItemType = availableListing.ItemType, QuantityRequired = availableListing.QuantityRequired, QuantityFulfilled = availableListing.QuantityFulfilled, QuantityOutstanding = availableListing.QuantityOutstanding, UoM = availableListing.UoM, AvailableFrom = availableListing.AvailableFrom, AvailableTo = availableListing.AvailableTo, ItemCondition = availableListing.ItemCondition, DisplayUntilDate = availableListing.DisplayUntilDate, SellByDate = availableListing.SellByDate, UseByDate = availableListing.UseByDate, DeliveryAvailable = availableListing.DeliveryAvailable, ListingStatus = availableListing.ListingStatus, ListingOriginatorDateTime = availableListing.ListingOriginatorDateTime, ListingAppUser = listingAppUser, ListingBranchDetails = listingBranch, ListingCompanyDetails = listingCompany, Buttons = buttons }; return(view); }
public static ViewButtons GetAvailableButtonsForSingleView(ApplicationDbContext db, AppUser appUser, Branch branch, Company company, IPrincipal user) { //Build initial list ViewButtons buttons = new ViewButtons() { CompanyBlockButton = false, CompanyAddFriendButton = false, CompanyAddToGroupButton = false, BranchBlockButton = false, BranchAddFriendButton = false, BranchAddToGroupButton = false, UserBlockButton = false, UserAddFriendButton = false, UserAddToGroupButton = false }; //First: check this is not our listing AppUser currentUser = AppUserHelpers.GetAppUser(db, user); if (currentUser.AppUserId == appUser.AppUserId) { return(buttons); } //Second: check the branch is not our branch, else return current button settings if (currentUser.CurrentBranchId == branch.BranchId) { return(buttons); } //Third: check if the Company allows interbranch dealing, if not and company level are the same return current button settings Branch currentUserBranch = BranchHelpers.GetBranch(db, currentUser.CurrentBranchId); if (!company.AllowBranchTrading && currentUserBranch.CompanyId == company.CompanyId) { return(buttons); } //Now validate for button status depending on type of user for this branch user combo BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, branch.BranchId, company.CompanyId); switch (branchUser.UserRole) { //Note - must be in this order as there are override checks the lower down the ranking/role you go case UserRoleEnum.SuperUser: case UserRoleEnum.Admin: buttons = SetCompanyButtons(db, buttons, company.CompanyId, currentUserBranch.CompanyId); buttons = SetBranchButtons(db, buttons, branch.BranchId, currentUser.CurrentBranchId); buttons = SetUserButtons(db, buttons, appUser.AppUserId, currentUser.AppUserId); break; case UserRoleEnum.Manager: buttons = SetBranchButtons(db, buttons, branch.BranchId, currentUser.CurrentBranchId); buttons = SetUserButtons(db, buttons, appUser.AppUserId, currentUser.AppUserId); break; case UserRoleEnum.User: buttons = SetUserButtons(db, buttons, appUser.AppUserId, currentUser.AppUserId); break; } return(buttons); }
public static SelectList AllBranchesForUserListDropDown(Guid appUserId, Guid branchId) { return(new SelectList(BranchHelpers.GetBranchesForUser(appUserId), "BranchId", "BranchName", branchId)); }
public static SelectList AllBranchesForCompany(Guid companyId) { return(new SelectList(BranchHelpers.GetBranchesForCompany(companyId), "BranchId", "BranchName")); }