Пример #1
0
        public static SubEntityRecord CreateRecord(OrgUnitOrgUnitTypeDto type, int orgUnitId)
        {
            var record = new SubEntityRecord();
            var fields = new List<Field>();

            fields.Add(new Field(_idField, _idField, FieldTypes.Hidden, type.Id));
            fields.Add(new Field(_orgUnitIdField, _orgUnitIdField, FieldTypes.Hidden, orgUnitId));
            fields.Add(new Field(_orgUnitTypeIdField, _orgUnitTypeIdField, FieldTypes.Hidden, type.OrgUnitTypeId));
            fields.Add(new Field(_nameField, "Name", FieldTypes.Label, type.OrgUnitTypeName));
            fields.Add(new Field(_isPrimaryOrgUnitTypeField, "Is Primary", FieldTypes.Checkbox, type.IsPrimaryOrgUnitType));

            record.Fields = fields;

            return record;
        }
Пример #2
0
        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;
            }
        }