public EventLossFootprintViewModel(int id, decimal lossAmount, t031_geo_code region) { Id = id; LossAmount = lossAmount; Region = region; }
private void SaveGeoRegion() { try { if (!ValidateFields()) return; if (!_editMode) { // This is a new Meta-Region creation var geoRegion = SelectedGeoRegion.GetNewRegionObject(); _repository.InsertItem(geoRegion); // This is a leaf level node so we need a t031 entry too if (geoRegion.t030_level_no.HasValue && geoRegion.t030_level_no.Value == MaintenanceConstants.GeoRegionMappingLevel) { var geoCode = new t031_geo_code { t030_subarea_id = geoRegion.t030_id, t030_subarea_code = geoRegion.t030_code, t030_subarea_name = geoRegion.t030_name, t030_area_id = SelectedGeoRegion.ParentNode.Id, t030_area_code = SelectedGeoRegion.ParentNode.Code, t030_area_name = SelectedGeoRegion.ParentNode.Name, t030_country_id = SelectedGeoRegion.ParentNode.ParentNode.Id, t030_country_code = SelectedGeoRegion.ParentNode.ParentNode.Code, t030_country_name = SelectedGeoRegion.ParentNode.ParentNode.Name, t030_region_id = SelectedGeoRegion.ParentNode.ParentNode.ParentNode.Id, t030_region_code = SelectedGeoRegion.ParentNode.ParentNode.ParentNode.Code, t030_region_name = SelectedGeoRegion.ParentNode.ParentNode.ParentNode.Name, t031_active_flag = "Y" }; _repository.InsertItem(geoCode); } _repository.Save(); SelectedGeoRegion.SetSaved(); var newNode = new GeoRegionViewModel(geoRegion) {ParentNode = SelectedGeoRegion.ParentNode}; SelectedGeoRegion.ParentNode.Children.Add(newNode); _eventAggregator.GetEvent<UserNotificationEvent>().Publish(new DialogParams("Save successful", "Geo Region created successfully")); } else { var geoRegion = SelectedGeoRegion.GetUpdatedRegionObject(); _repository.UpdateItem(geoRegion, geoRegion.t030_id); // This is a leaf level node so we need to update the t031 entry too if (geoRegion.t030_level_no.HasValue && geoRegion.t030_level_no.Value == MaintenanceConstants.GeoRegionMappingLevel) { var geoCode = _repository.GetItems<t031_geo_code>().FirstOrDefault( g => g.t030_subarea_id == geoRegion.t030_id); if (geoCode != null) { geoCode.t030_subarea_code = geoRegion.t030_code; geoCode.t030_subarea_name = geoRegion.t030_name; _repository.UpdateItem(geoCode, geoCode.t031_id); } } _repository.Save(); SelectedGeoRegion.SetSaved(); _eventAggregator.GetEvent<UserNotificationEvent>().Publish(new DialogParams("Update successful", "Geo Region updated successfully")); } _moduleController.SwitchPanel(MaintenanceRegionNames.GeoRegionRegion, MaintenanceViewNames.GeoRegionView); } catch (Exception ex) { _eventAggregator.GetEvent<UserNotificationEvent>().Publish(new DialogParams("Save unsuccessful", "There was an error saving this Meta-Region. " + ex.Message)); } }