예제 #1
0
 private void ExecuteSaveResidence()
 {
     using (var unitOfWork = new UnitOfWork(new MahalluDBContext())) {
         if (ValidateResidence())
         {
             Residence residence = GetResidence();
             if (CurrentResidence != null)
             {
                 CurrentResidence.Name = residence.Name;
                 CurrentResidence.Area = residence.Area;
                 unitOfWork.Residences.Update(CurrentResidence);
                 MessageBox.Show(CurrentResidence.Name + " updated successfully !", "New Residence", MessageBoxButton.OK, MessageBoxImage.Information);
             }
             else
             {
                 if (CurrentResidence == null && IsHouserNumberExists(unitOfWork))
                 {
                     return;
                 }
                 unitOfWork.Residences.Add(residence);
                 ResidenceList.Add(residence);
                 CurrentResidence = residence;
                 MessageBox.Show(CurrentResidence.Name + " added successfully !", "New Residence", MessageBoxButton.OK, MessageBoxImage.Information);
             }
             unitOfWork.Complete();
             ResidenceType residenceType = new ResidenceType {
                 Residence = CurrentResidence, Operation = MahalluManager.Model.Common.Operation.Add
             };
             eventAggregator.GetEvent <PubSubEvent <ResidenceType> >().Publish(residenceType);
         }
     }
 }
예제 #2
0
 private void ExecuteSearch()
 {
     RefreshResidence();
     searchSource = ResidenceList.ToList();;
     if (SearchByHouseNumber)
     {
         ResidenceList = new ObservableCollection <Residence>(searchSource.FindAll((x) => x.Number == SearchText.Trim()));
         if (ResidenceList != null && ResidenceList.Count == 0)
         {
             MessageBox.Show("No Residence Found with House Number " + SearchText);
         }
     }
     else if (SearchByHouseName)
     {
         ResidenceList = new ObservableCollection <Residence>(searchSource.FindAll((x) => x.Name.ToLower().Contains(SearchText.Trim().ToLower())));
         if (ResidenceList != null && ResidenceList.Count == 0)
         {
             MessageBox.Show("No Residence Found with House Name " + SearchText);
         }
     }
     else if (SearchByMemberName)
     {
         using (var unitofWork = new UnitOfWork(new MahalluDBContext())) {
             List <ResidenceMember> tempResidenceMembers = unitofWork.ResidenceMembers.Find((x) => x.MemberName.ToLower().Contains(SearchText.Trim().ToLower())).ToList();
             if (tempResidenceMembers != null && tempResidenceMembers.Count == 0)
             {
                 MessageBox.Show("No Residence Found with Member Name " + SearchText);
             }
             else
             {
                 ResidenceList.Clear();
                 foreach (var item in tempResidenceMembers)
                 {
                     Residence residence = searchSource.Find((x) => x.Id == item.Residence_Id);
                     if (residence != null && !ResidenceList.Contains(residence))
                     {
                         ResidenceList.Add(residence);
                     }
                 }
             }
         }
     }
 }