void RunContactOwnerTypeSelectionChanged() { using (StructureMap.IContainer c = NestedContainer) { _myCostCentreId = Using<IConfigService>(c).Load().CostCentreId; ContactOwners.Clear(); var contactOwner = new EditContactViewModel.ContactOwnerLookUp(Guid.Empty) { Name = GetLocalText("sl.contacts.edit.contactOwner.default") /*"--Please Select Contact Owner--"*/ }; ContactOwners.Add(contactOwner); SelectedContactOwner = contactOwner; switch (SelectedContactOwnerType) { #if(KEMSA) case ContactOwnerType.HealthFacility: #else case ContactOwnerType.Outlet: #endif Using<IOutletRepository>(c).GetByDistributor(_myCostCentreId) .ForEach( n => ContactOwners.Add(new EditContactViewModel.ContactOwnerLookUp(n.Id) { Name = n.Name, Type = typeof (Outlet) })); break; case ContactOwnerType.User: //get all salesmen ccs whose cc has myCC as parent var mySalesmenCCIds = Using<ICostCentreRepository>(c).GetAll().OfType<DistributorSalesman>().Where( n => ((DistributorSalesman) n).ParentCostCentre.Id == _myCostCentreId) .Select(n => n.Id) .ToList(); List<Guid> ccIds = mySalesmenCCIds; ccIds.Add(_myCostCentreId); List<User> users = new List<User>(); foreach (var ccId in ccIds) { var usrs = Using<IUserRepository>(c).GetByCostCentre(ccId); usrs.ForEach(users.Add); } users.ToList().ForEach(n => ContactOwners.Add(new EditContactViewModel.ContactOwnerLookUp(n.CostCentre) { Name = n.Username, Type = typeof (User) })); break; case ContactOwnerType.Distributor: //ContactOwners.Remove(contactOwner); var cc = Using<ICostCentreRepository>(c).GetById(_myCostCentreId); ContactOwners.Add(new EditContactViewModel.ContactOwnerLookUp(cc.Id) { Name = cc.Name, Type = typeof (Distributor) }); //SelectedContactOwner = ContactOwners.FirstOrDefault(); break; } } }
void InitializeBlank() { using (StructureMap.IContainer c = NestedContainer) { PageTitle = GetLocalText("sl.contacts.edit.title.new"); //"Create Contact"; ClearViewModel(); _myCostCentreId = Using<IConfigService>(c).Load().CostCentreId; var contactOwner = new EditContactViewModel.ContactOwnerLookUp(Guid.Empty) { //Id = Guid.Empty, Name = GetLocalText("sl.contacts.edit.contactOwner.default") /*"--Please Select Contact Owner--"*/ }; ContactOwners.Clear(); ContactOwners.Add(contactOwner); SelectedContactOwner = contactOwner; if ( !Using<IContactRepository>(c).GetByContactsOwnerId(SelectedContactOwner.Id) .Any(n => n.ContactClassification == ContactClassification.PrimaryContact)) { setAsPrimContact = true; SelectedContactClassification = ContactClassification.PrimaryContact; } } }