Ejemplo n.º 1
0
        private void OnSaveCustomRegion()
        {
            Validate();
            if (HasErrors)
            {
                return;
            }

            //if (string.IsNullOrWhiteSpace(RegionTitle) || RegionID == null || SelectedState == null)
            //{
            //    MessageBox.Show("Please enter a region  ID , name and select a state before adding a custom geographic region.",
            //        "Unable to add Custom Region", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            //    return;
            //}

            var customRegion = new CustomRegion
            {
                Code = string.Format("CUS{0}{1}", RegionID, SelectedState),
                Name = RegionTitle,
                IsSourcedFromBaseData = false,
                State          = SelectedState,
                Version        = 1,
                Created        = DateTime.Now,
                ImportRegionId = RegionID
            };

            using (var session = DataserviceProvider.SessionFactory.OpenSession())
            {
                try
                {
                    OnAddNewItem(customRegion);
                    CollectionItems.AddNewItem(customRegion);
                    CollectionItems.CommitNew();
                    Reset();
                    var msg = String.Format("Custom region {0} with state {1} has been added", customRegion.Name, customRegion.State);
                    MappedCustomRegionToPopulationCount = Service.GetCustomRegionToPopulationMappingCount(ConfigurationService.HospitalRegion.DefaultStates.OfType <string>().ToList());
                    EventAggregator.GetEvent <GenericNotificationEvent>().Publish(msg);
                    IsAddNewRegionPopupVisible = false;
                }
                catch (GenericADOException)
                {
                    MessageBox.Show("region  ID already exist.", "Unable to add Custom Region", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }