private void AddButtonHandler(object parameter)
        {
            LocationPicker picker = new LocationPicker();

            picker.Closed += (s1, e1) =>
                                 {
                                     //Handle dialog closed
                                     if (picker.DialogResult.HasValue && picker.DialogResult.Value)
                                     {
                                         foreach (DocumentLocation location in picker.Locations)
                                         {
                                             var documentLocation = new DocumentAssignedLocation
                                                 {
                                                     Document = mDocument,
                                                     DocumentId = mDocument.Id,
                                                     LocationId = location.Id,
                                                     DocumentLocation = location
                                                 };
                                             var existingDocumentLocation = (from x in mDocument.DocumentAssignedLocations
                                                                             where x.DocumentId == mDocument.Id
                                                                                   && x.LocationId == location.Id
                                                                             select x).FirstOrDefault();
                                             if (existingDocumentLocation == null)
                                             {
                                                 mDocument.DocumentAssignedLocations.Add(documentLocation);
                                             }
                                         }
                                         RaisePropertyChanged("DocumentLocations");
                                         OnCollectionChanged();
                                         Utils.OnCollectionChanged(EventAggregator, mDocument, "DocumentLocationsViewModel", true);
                                     }
                                 };

            picker.Show();
        }
Exemplo n.º 2
0
        private void InsertData(IList<DocumentLocationDataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

            using (var cee = new CmsEntities())
            {
                cee.Configuration.LazyLoadingEnabled = false;

                foreach (DocumentLocationDataAdapter adapter in importData)
                {
                    var newAssignedLoc = new DocumentAssignedLocation
                    {
                        DocumentId = adapter.DocumentId,
                        LocationId = adapter.LocationId
                    };

                    cee.DocumentAssignedLocations.Add(newAssignedLoc);

                    mSavedResults.Add(newAssignedLoc);
                }

                if (mSavedResults.Count == 0)
                {
                    RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Documents were processed from worksheet {0}.", WorkSheetName));
                }
                else
                {
                    //SAVE
                    cee.SaveChanges();
                    RaiseMessage(CommonUtils.MessageType.Info, string.Format("Saved {0} DocumentAssignedLocations.", mSavedResults.Count()));
                }
            }
        }