public static void PopulateRequestFieldValues(LocationAdminDetailView parent, SubEntity sites, int orgUnitId, OrgUnitRequestBase request) { var record = sites.Records.SingleOrDefault(r => r.Action == RecordActions.Edited); if (record == null) return; request.CustomUrl = parent.GetFieldValue(record.Fields, _siteUrlField); request.CustomLiveUrl = parent.GetFieldValue(record.Fields, _siteUrlLiveField); request.CustomStageUrl = parent.GetFieldValue(record.Fields, _siteUrlStageField); request.CustomQaUrl = parent.GetFieldValue(record.Fields, _siteUrlQaField); request.CustomDevUrl = parent.GetFieldValue(record.Fields, _siteUrlDevField); // Determine if site association is enabled var associationEnabled = false; bool.TryParse(CommonUtils.GetFieldValue(record.Fields, _associationEnabledField), out associationEnabled); // Add/remove "Site" location type automatically if site association is enabled/disabled var locationTypeSubEntity = parent._viewModel.SubEntities.Single(s => s.EntityName == LocationAdminDetailView._locationTypeSubEntity); var hasSiteLocationType = HasSiteLocationType(locationTypeSubEntity); if (associationEnabled && !hasSiteLocationType) { var orgUnitType = new OrgUnitOrgUnitTypeDto { OrgUnitTypeId = 1, IsEnabled = true, IsPrimaryOrgUnitType = false }; var locationTypeRecord = LocationTypesHelper.CreateRecord(orgUnitType, orgUnitId); locationTypeRecord.Action = RecordActions.Added; locationTypeSubEntity.Records.Add(locationTypeRecord); } else if (!associationEnabled && hasSiteLocationType) { var siteLocationTypeRecord = locationTypeSubEntity.Records.SingleOrDefault(s => s.Fields.Any(f => f.FieldName == "Name" && (f.FieldValue as string == "Site"))); if (siteLocationTypeRecord != null && siteLocationTypeRecord.Action != RecordActions.Added) siteLocationTypeRecord.Action = RecordActions.Deleted; } }
public void PopulateRequestFieldValues(OrgUnitRequestBase request) { request.IsEnabled = bool.Parse(GetFieldValue(_viewModel.Fields, _isEnabledField)); request.Name = GetFieldValue(_viewModel.Fields, _nameField); request.Address1 = GetFieldValue(_viewModel.Fields, _address1Field); request.Address2 = GetFieldValue(_viewModel.Fields, _address2Field); request.City = GetFieldValue(_viewModel.Fields, _cityField); if (!string.IsNullOrEmpty(GetFieldValue(_viewModel.Fields, _stateIdField))) request.StateId = int.Parse(GetFieldValue(_viewModel.Fields, _stateIdField)); request.PostalCode = GetFieldValue(_viewModel.Fields, _postalCodeField); if (!string.IsNullOrEmpty(GetFieldValue(_viewModel.Fields, _countryIdField))) request.CountryId = int.Parse(GetFieldValue(_viewModel.Fields, _countryIdField)); request.HasCustomCoordinates = bool.Parse(GetFieldValue(_viewModel.Fields, _hasCustomCoordinatesField)); if (!request.HasCustomCoordinates) UpdateGeocodeFields(_viewModel.Fields, "GeocodeAddressClicked"); if (!string.IsNullOrEmpty(GetFieldValue(_viewModel.Fields, _latitudeField))) request.Latitude = decimal.Parse(GetFieldValue(_viewModel.Fields, _latitudeField)); if (!string.IsNullOrEmpty(GetFieldValue(_viewModel.Fields, _longitudeField))) request.Longitude = decimal.Parse(GetFieldValue(_viewModel.Fields, _longitudeField)); request.ImageUrl = CalculateLocationImageUrl(); request.CostCenter = GetFieldValue(_viewModel.Fields, _costCenterField); request.Phone = GetFieldValue(_viewModel.Fields, _phoneField); request.Fax = GetFieldValue(_viewModel.Fields, _faxField); request.Email = GetFieldValue(_viewModel.Fields, _emailField); request.ServiceLineUrl = GetFieldValue(_viewModel.Fields, _serviceLineUrlField); if (!string.IsNullOrEmpty(GetFieldValue(_viewModel.Fields, _potentialEventLocationField))) request.PotentialEventLocation = bool.Parse(GetFieldValue(_viewModel.Fields, _potentialEventLocationField)); request.Description = GetFieldValue(_viewModel.Fields, _descriptionField); request.CustomKeywords = GetFieldValue(_viewModel.Fields, _customKeywordsField); request.Keywords = GetFieldValue(_viewModel.Fields, _generatedKeywordsField); request.Custom1 = GetFieldValue(_viewModel.Fields, _customField1Field); request.Custom2 = GetFieldValue(_viewModel.Fields, _customField2Field); request.Custom3 = GetFieldValue(_viewModel.Fields, _customField3Field); request.SeoPageTitle = GetFieldValue(_viewModel.Fields, _seoPageTitleField); request.SeoPageDescription = GetFieldValue(_viewModel.Fields, _seoPageDescriptionField); request.SeoH1Tag = GetFieldValue(_viewModel.Fields, _seoH1Field); request.SeoPrimaryKeyword = GetFieldValue(_viewModel.Fields, _seoPrimaryKeywordField); request.SeoSecondaryKeyword = GetFieldValue(_viewModel.Fields, _seoSecondaryKeywordField); request.SeoCanonicalUrl = GetFieldValue(_viewModel.Fields, _seoCanonicalUrlField); request.DynamicColumnData = CommonUtils.BuildDynamicColumnsSaveData(this, _viewModel, Constants.OrgUnitDynamicColumnEntityId); var paymentProcessorConfigValue = GetFieldValue(_viewModel.Fields, _paymentGateway); request.PaymentProcessorConfigurationId = (!string.IsNullOrEmpty(paymentProcessorConfigValue) && int.Parse(paymentProcessorConfigValue, CultureInfo.InvariantCulture) > 0) ? int.Parse(paymentProcessorConfigValue) : new int?(); //new records will not have subentities if (_viewModel.SubEntities.Count > 0) LocationSitesHelper.PopulateRequestFieldValues(this, _viewModel.SubEntities.Single(s => s.EntityName == _locationSiteSubEntity), _orgUnitId, request); }