private IEnumerable<AssociationUserCreditCard> GetCreditCards(LomsContext db, int profileId, SearchRequest searchRequest) { var query = db.AssociationUserCreditCards.IncludeAll("Info") .Where(a => a.AssociationUserId == profileId); if (searchRequest != null && !string.IsNullOrWhiteSpace(searchRequest.SearchFilterValue)) { if (searchRequest.SearchFilter == "Nickname") query = from card in query where card.Nickname.Contains(searchRequest.SearchFilterValue) select card; } var cards = query.OrderBy(a => a.Nickname).ToList(); cards.ForEach(card => { card.Number = AssociationUserCreditCard.ObfuscateCreditCardNumber(card.Info.Number); card.Info = null; card.AcceptChanges(); }); var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == profileId); if (defaultBilling != null && defaultBilling.CreditCardId.HasValue) { var card = cards.Single(i => i.Id == defaultBilling.CreditCardId); card.IsDefaultBilling = true; } return cards; }
private void Search() { var currentAsyncResult = default(IAsyncResult); SearchRequest searchRequest = new SearchRequest { SearchFilter = Filter, SearchFilterValue = FilterValue }; currentAsyncResult = _lastSearchAsyncResult = Service.BeginGetProfiles(AssociationManagerId, searchRequest, CreateAsyncCallback(ar => Service.EndGetProfiles(ar), response => { if (_lastSearchAsyncResult != currentAsyncResult) return; // This might be call multiple times, we only care about the last one. var profiles = new ObservableCollection<AssociationUser>(response.ManagedProfiles); _manager = response.Manager; _manager.CurrentManagerId = _manager.Id; foreach (AssociationUser user in profiles) user.CurrentManagerId = _manager.Id; //_manager.IsManager = true; ManagerSelected.Raise(this, _manager); profiles.Insert(0, _manager); Profiles = profiles; SelectedProfile = _manager; }), null); }
public IEnumerable<AssociationUserCreditCard> GetCreditCards(int profileId, SearchRequest searchRequest) { using (var db = new LomsContext()) { var query = db.AssociationUserCreditCards.IncludeAll("Info") .Where(a => a.AssociationUserId == profileId); if (!string.IsNullOrWhiteSpace(searchRequest.SearchFilterValue)) { if (searchRequest.SearchFilter == "Nickname") query = from card in query where card.Nickname.Contains(searchRequest.SearchFilterValue) select card; } var cards = query.OrderBy(a => a.Nickname).ToList(); cards.ForEach(card => { card.Number = ObfuscateCreditCardNumber(card.Info.Number); card.Info = null; card.AcceptChanges(); }); return cards; } }
public IEnumerable<AssociationUserCreditCard> GetCreditCards(int profileId, SearchRequest searchRequest) { using (var db = new LomsContext()) { return GetCreditCards(db, profileId, searchRequest); } }
private void GetCreditCards() { SearchRequest searchRequest = new SearchRequest { SearchFilter = "Nickname", SearchFilterValue = string.Empty }; Service.BeginGetCreditCards(Profile.Id, searchRequest, CreateAsyncCallback( ar => Service.EndGetCreditCards(ar), result => { var selectedCreditCard = SelectedCreditCard; CreditCards = new ObservableCollection<AssociationUserCreditCard>(result); SelectedCreditCard = selectedCreditCard != null ? CreditCards.FirstOrDefault(a => a.Id == selectedCreditCard.Id) ?? null : null; }), null); }
private void Search() { SearchRequest searchRequest = new SearchRequest { SearchFilter = Filter, SearchFilterValue = FilterValue == "" ? null : FilterValue }; Service.BeginGetTravelAgencies(searchRequest, CreateAsyncCallback( ar => Service.EndGetTravelAgencies(ar), result => { var selectedTravelAgency = SelectedTravelAgency; TravelAgencies = new ObservableCollection<AssociationTravelAgency>(result); SelectedTravelAgency = selectedTravelAgency != null ? TravelAgencies.FirstOrDefault(a => a.Id == selectedTravelAgency.Id) ?? TravelAgencies.FirstOrDefault() : TravelAgencies.FirstOrDefault(); }), null); }
public IEnumerable<AssociationTravelAgency> GetTravelAgencies(SearchRequest searchRequest) { if (!Roles.IsUserInRole(RoleName.StaffUser)) throw new SecurityException(); using (var db = new LomsContext()) { var query = db.AssociationTravelAgencies.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country", "Manager") .Where(a => a.AssociationId == CurrentAssociationId); if (!string.IsNullOrWhiteSpace(searchRequest.SearchFilterValue)) { if (searchRequest.SearchFilter == "Name") query = from profile in query where profile.Name.Contains(searchRequest.SearchFilterValue) select profile; } return query.OrderBy(a => a.Name).ToList(); } }
private void Search() { if (_selectedProfile == null) return; IsBusy = true; SearchRequest searchRequest = new SearchRequest { SearchFilter = Filter, SearchFilterValue = FilterValue }; Service.BeginGetAddresses(_selectedProfile.Id, searchRequest, CreateAsyncCallback( ar => Service.EndGetAddresses(ar), result => { IsBusy = false; var selectedAddress = SelectedAddress; Addresses = new ObservableCollection<AssociationUserAddress>(result); SelectedAddress = selectedAddress != null ? Addresses.FirstOrDefault(a => a.Id == selectedAddress.Id) ?? Addresses.FirstOrDefault() : Addresses.FirstOrDefault(); }), null); }
public IEnumerable<AssociationUserAddress> GetAddresses(int profileId, SearchRequest searchRequest) { using (var db = new LomsContext()) { var query = from a in db.AssociationUserAddresses.IncludeAll("Country", "State", "State.Country", "Suburb", "Suburb.Country", "Suburb.State", "Suburb.State.Country") where a.AssociationUserId == profileId && a.TypeId == (int)AddressType.Other orderby a.Nickname select a; if (!string.IsNullOrWhiteSpace(searchRequest.SearchFilterValue)) { if (searchRequest.SearchFilter == "Nickname") query = from a in query where a.Nickname.Contains(searchRequest.SearchFilterValue) orderby a.Nickname select a; } return query.ToList(); } }
private void GetSavedAddresses() { SearchRequest searchRequest = new SearchRequest { SearchFilter = "Nickname", SearchFilterValue = string.Empty }; Service.BeginGetAddresses(Profile.Id, searchRequest, CreateAsyncCallback( ar => Service.EndGetAddresses(ar), result => { var selectedAddress = Address; Addresses = new ObservableCollection<AssociationUserAddress>(result); Addresses.Insert(0, GetDummyAddress(-1, " - Select a Saved Address -")); Addresses.Insert(1, GetDummyAddress(-2, " - Add New Address -")); Address = selectedAddress != null ? Addresses.FirstOrDefault(a => a.Id == selectedAddress.Id) ?? Addresses.FirstOrDefault() : Addresses.FirstOrDefault(); }), null); }
private static IEnumerable<AssociationUserBillingAccount> GetUserBillingAccounts(LomsContext db, int profileId, SearchRequest searchRequest) { var query = from a in db.AssociationUserBillingAccounts.IncludeAll("BillingAccount", "BillingAccount.Country") where a.AssociationUserId == profileId && a.BillingAccount.StatusId == (byte)EntityStatus.Active select a; if (searchRequest != null && !string.IsNullOrWhiteSpace(searchRequest.SearchFilterValue)) { if (searchRequest.SearchFilter == "Name") query = from cb in query where cb.Name.Contains(searchRequest.SearchFilterValue) select cb; } var billingAccounts = query.OrderBy(a => a.Name).ToList(); var defaultBilling = db.AssociationUserDefaultBillings.SingleOrDefault(b => b.AssociationUserId == profileId); if (defaultBilling != null && defaultBilling.BillingAccountId.HasValue) { var billingAccount = billingAccounts.Single(i => i.Id == defaultBilling.BillingAccountId); billingAccount.IsDefaultBilling = true; } return billingAccounts; }
public IEnumerable<AssociationUserBillingAccount> GetUserBillingAccounts(int profileId, SearchRequest searchRequest) { using (var db = new LomsContext()) { return GetUserBillingAccounts(db, profileId, searchRequest); } }
public GetProfilesResponse GetProfiles(int managerId, SearchRequest searchRequest) { using (var db = new LomsContext()) { var managedProfiles = new List<AssociationUser>(); var manager = (from profile in db.AssociationUsers.IncludeAll("Country", "Activation", "TravelAgencyRole", "TravelAgencyRole.TravelAgency", "TravelAgencyRole.TravelAgency.Country", "TravelAgencyRole.TravelAgency.State", "TravelAgencyRole.TravelAgency.State.Country", "TravelAgencyRole.TravelAgency.Suburb", "TravelAgencyRole.TravelAgency.Suburb.Country", "TravelAgencyRole.TravelAgency.Suburb.State", "TravelAgencyRole.TravelAgency.Suburb.State.Country") where profile.Id == managerId select profile) .SingleOrDefault(); manager.TravelAgencyName = (from a in db.AssociationUserAddresses where a.AssociationUserId == managerId && a.TypeId == (int)AddressType.Work select a.BusinessName).SingleOrDefault(); var profilesOfManager = from profile in db.AssociationUsers.IncludeAll("Country", "Activation") where profile.ManagerId == manager.Id select profile; //filter profilesOfManager = ApplyProfileSearchFiler(profilesOfManager, searchRequest.SearchFilter, searchRequest.SearchFilterValue); managedProfiles.AddRange(profilesOfManager); if (manager.TravelAgencyRole != null && (manager.TravelAgencyRole.Role == TravelAgencyRole.Manager || manager.TravelAgencyRole.Role == TravelAgencyRole.SupervisorAsManager)) { var travelAgencyRoles = from r in db.AssociationUserTravelAgencyRoles where r.AgencyId == manager.TravelAgencyRole.AgencyId select r; foreach (var r in travelAgencyRoles) { if (r.UserId == managerId) continue; //skipe manager profile as it will be added at any case later var memberProfiles = from profile in db.AssociationUsers.IncludeAll("Country", "Activation", "TravelAgencyRole") where profile.Id == r.UserId || (profile.ManagerId == r.UserId && profile.Id != managerId) //skipe manager profile (avoid duplication when Profile and one if it's Managed Profiles entered a group together.) select profile; managedProfiles.AddRange(memberProfiles); } } else { //get group member profiles { //managed groups var managedGroups = from g in db.AssociationUserGroups where g.AssociationUserId == managerId select g; //other groups where the manager is a member (not manager) var otherGroups = from g in db.AssociationUserGroups join m in db.AssociationUserGroupMembers on g.Id equals m.GroupId where !m.IsManager && m.UserId == managerId && m.StatusId == (int)AssociationUserGroupStatus.Accepted select g; var groups = managedGroups.Concat(otherGroups); foreach (var g in groups) { var members = from m in db.AssociationUserGroupMembers where m.GroupId == g.Id && m.StatusId == (int)AssociationUserGroupStatus.Accepted select m; foreach (var m in members) { if (m.UserId == managerId) continue; //skipe manager profile as it will be added at any case later var memberProfiles = from profile in db.AssociationUsers.IncludeAll("Country", "Activation") where profile.Id == m.UserId || (profile.ManagerId == m.UserId && profile.Id != managerId) //skipe manager profile (avoid duplication when Profile and one if it's Managed Profiles entered a group together.) select profile; managedProfiles.AddRange(memberProfiles); } } } } if (searchRequest.PageSize > 0) managedProfiles = managedProfiles.Distinct().Skip(searchRequest.RecordsToSkip).Take(searchRequest.PageSize).ToList(); else managedProfiles = managedProfiles.Distinct().ToList(); return new GetProfilesResponse() { Manager = manager, ManagedProfiles = managedProfiles }; } //var managedProfiles = new List<AssociationUser>(); //var manager = (from profile in _db.AssociationUsers.ObjectSet.IncludeAll("Country", "Activation", "TravelAgencyRole", "TravelAgencyRole.TravelAgency", "TravelAgencyRole.TravelAgency.Country", "TravelAgencyRole.TravelAgency.State", "TravelAgencyRole.TravelAgency.State.Country", "TravelAgencyRole.TravelAgency.Suburb", "TravelAgencyRole.TravelAgency.Suburb.Country", "TravelAgencyRole.TravelAgency.Suburb.State", "TravelAgencyRole.TravelAgency.Suburb.State.Country") // where profile.Id == managerId // select profile) // .SingleOrDefault(); //manager.TravelAgencyName = (from a in _db.AssociationUserAddresses.ObjectSet // where a.AssociationUserId == managerId && a.TypeId == (int)AddressType.Work // select a.BusinessName).SingleOrDefault(); //var profilesOfManager = from profile in _db.AssociationUsers.ObjectSet.IncludeAll("Country", "Activation") // where profile.ManagerId == manager.Id // select profile; ////filter //profilesOfManager = ApplyProfileSearchFiler(profilesOfManager, searchRequest.SearchFilter, searchRequest.SearchFilterValue); //managedProfiles.AddRange(profilesOfManager); //if (manager.TravelAgencyRole != null && (manager.TravelAgencyRole.Role == TravelAgencyRole.Manager || manager.TravelAgencyRole.Role == TravelAgencyRole.SupervisorAsManager)) //{ // var travelAgencyRoles = from r in _db.AssociationUserTravelAgencyRoles.ObjectSet // where r.AgencyId == manager.TravelAgencyRole.AgencyId // select r; // foreach (var r in travelAgencyRoles) // { // if (r.UserId == managerId) // continue; //skipe manager profile as it will be added at any case later // var memberProfiles = from profile in _db.AssociationUsers.ObjectSet.IncludeAll("Country", "Activation", "TravelAgencyRole") // where profile.Id == r.UserId || (profile.ManagerId == r.UserId && profile.Id != managerId) //skipe manager profile (avoid duplication when Profile and one if it's Managed Profiles entered a group together.) // select profile; // //filter // memberProfiles = ApplyProfileSearchFiler(memberProfiles, searchRequest.SearchFilter, searchRequest.SearchFilterValue); // managedProfiles.AddRange(memberProfiles); // } //} //else //{ // //get group member profiles // { // //managed groups // var managedGroups = from g in _db.AssociationUserGroups.ObjectSet // where g.AssociationUserId == managerId // select g; // //other groups where the manager is a member (not manager) // var otherGroups = from g in _db.AssociationUserGroups.ObjectSet // join m in _db.AssociationUserGroupMembers.ObjectSet on g.Id equals m.GroupId // where !m.IsManager && m.UserId == managerId && m.StatusId == (int)AssociationUserGroupStatus.Accepted // select g; // var groups = managedGroups.Concat(otherGroups); // foreach (var g in groups) // { // var members = from m in _db.AssociationUserGroupMembers.ObjectSet // where m.GroupId == g.Id && m.StatusId == (int)AssociationUserGroupStatus.Accepted // select m; // foreach (var m in members) // { // if (m.UserId == managerId) // continue; //skipe manager profile as it will be added at any case later // var memberProfiles = from profile in _db.AssociationUsers.ObjectSet.IncludeAll("Country", "Activation") // where profile.Id == m.UserId || (profile.ManagerId == m.UserId && profile.Id != managerId) //skipe manager profile (avoid duplication when Profile and one if it's Managed Profiles entered a group together.) // select profile; // //filter // memberProfiles = ApplyProfileSearchFiler(memberProfiles, searchRequest.SearchFilter, searchRequest.SearchFilterValue); // managedProfiles.AddRange(memberProfiles); // } // } // } //} //if (searchRequest.PageSize > 0) // managedProfiles = managedProfiles.Distinct(new AssociationUser.Comparer()).Skip(searchRequest.RecordsToSkip).Take(searchRequest.PageSize).ToList(); //else // managedProfiles = managedProfiles.Distinct(new AssociationUser.Comparer()).ToList(); //return new GetProfilesResponse() { Manager = manager, ManagedProfiles = managedProfiles }; }
private void SearchCreditCards() { if (SelectedProfile == null) return; IsBusy = true; var searchRequest = new SearchRequest { SearchFilter = SelectedCCFilter, SearchFilterValue = CCFilterValue }; Service.BeginGetCreditCards(SelectedProfile.Id, searchRequest, CreateAsyncCallback( ar => Service.EndGetCreditCards(ar), result => { IsBusy = false; var selectedCreaditCard = SelectedCreditCard; CreditCards = new ObservableCollection<AssociationUserCreditCard>(result); SelectedCreditCard = selectedCreaditCard != null ? CreditCards.FirstOrDefault(a => a.Id == selectedCreaditCard.Id) ?? CreditCards.FirstOrDefault() : CreditCards.FirstOrDefault(); }), null); }