public EditMaintenanceRecordObservationsViewData(Person currentPerson, Models.TreatmentBMP treatmentBMP,
                                                  CustomAttributeTypePurpose customAttributeTypePurpose, Models.MaintenanceRecord maintenanceRecord,
                                                  bool isSubForm, bool missingRequiredAttributes) : base(currentPerson, treatmentBMP, customAttributeTypePurpose, isSubForm, missingRequiredAttributes)
 {
     PageTitle       = $"Edit Maintenance Record Observations";
     ParentDetailUrl = maintenanceRecord.GetDetailUrl();
 }
        public EditAttributesViewData(Person currentPerson, Models.TreatmentBMP treatmentBMP,
                                      CustomAttributeTypePurpose customAttributeTypePurpose, bool isSubForm, bool missingRequiredAttributes) : base(currentPerson, NeptuneArea.OCStormwaterTools)
        {
            IsSubForm = isSubForm;
            MissingRequiredAttributes = missingRequiredAttributes;
            EntityName = $"{FieldDefinitionType.TreatmentBMP.GetFieldDefinitionLabelPluralized()}";
            var treatmentBMPIndexUrl = SitkaRoute <TreatmentBMPController> .BuildUrlFromExpression(x => x.FindABMP());

            EntityUrl     = treatmentBMPIndexUrl;
            SubEntityName = treatmentBMP.TreatmentBMPName;
            SubEntityUrl  = treatmentBMP.GetDetailUrl();
            PageTitle     = $"Edit {FieldDefinitionType.TreatmentBMP.GetFieldDefinitionLabel()} Attributes";

            ParentDetailUrl = treatmentBMP.GetDetailUrl();

            TreatmentBMPTypeCustomAttributeTypes = treatmentBMP.TreatmentBMPType.TreatmentBMPTypeCustomAttributeTypes
                                                   .Where(x => x.CustomAttributeType.CustomAttributeTypePurposeID ==
                                                          customAttributeTypePurpose.CustomAttributeTypePurposeID)
                                                   .ToList().SortByOrderThenName().ToList();
        }
        public void UpdateModel(Models.TreatmentBMP treatmentBMP, Person currentPerson,
                                CustomAttributeTypePurpose customAttributeTypePurpose, List <Models.CustomAttributeType> allCustomAttributeTypes)
        {
            var customAttributeSimplesWithValues = CustomAttributes.Where(x => x.CustomAttributeValues != null && x.CustomAttributeValues.Count > 0);
            var customAttributesToUpdate         = new List <CustomAttribute>();
            var customAttributeValuesToUpdate    = new List <CustomAttributeValue>();

            foreach (var x in customAttributeSimplesWithValues)
            {
                var customAttribute = new CustomAttribute(treatmentBMP.TreatmentBMPID, x.TreatmentBMPTypeCustomAttributeTypeID, treatmentBMP.TreatmentBMPTypeID, x.CustomAttributeTypeID);
                customAttributesToUpdate.Add(customAttribute);
                foreach (var value in x.CustomAttributeValues)
                {
                    var valueParsedForDataType = allCustomAttributeTypes.Single(y => y.CustomAttributeTypeID == x.CustomAttributeTypeID).CustomAttributeDataType.ValueParsedForDataType(value);
                    var customAttributeValue   = new CustomAttributeValue(customAttribute, valueParsedForDataType);
                    customAttributeValuesToUpdate.Add(customAttributeValue);
                }
            }

            var customAttributesInDatabase      = HttpRequestStorage.DatabaseEntities.CustomAttributes.Local;
            var customAttributeValuesInDatabase = HttpRequestStorage.DatabaseEntities.CustomAttributeValues.Local;

            var existingCustomAttributes = treatmentBMP.CustomAttributes.Where(x =>
                                                                               x.CustomAttributeType.CustomAttributeTypePurposeID ==
                                                                               customAttributeTypePurpose.CustomAttributeTypePurposeID).ToList();

            var existingCustomAttributeValues = existingCustomAttributes.SelectMany(x => x.CustomAttributeValues).ToList();

            existingCustomAttributes.Merge(customAttributesToUpdate, customAttributesInDatabase,
                                           (x, y) => x.TreatmentBMPID == y.TreatmentBMPID &&
                                           x.TreatmentBMPTypeID == y.TreatmentBMPTypeID &&
                                           x.CustomAttributeTypeID == y.CustomAttributeTypeID &&
                                           x.CustomAttributeID == y.CustomAttributeID);

            existingCustomAttributeValues.Merge(customAttributeValuesToUpdate, customAttributeValuesInDatabase,
                                                (x, y) => x.CustomAttributeValueID == y.CustomAttributeValueID &&
                                                x.CustomAttributeID == y.CustomAttributeID,
                                                (x, y) => { x.AttributeValue = y.AttributeValue; });
        }
Esempio n. 4
0
 public EditAttributesViewModel(Models.TreatmentBMP treatmentBMP, CustomAttributeTypePurpose customAttributeTypePurpose) : base(treatmentBMP, customAttributeTypePurpose)
 {
 }
Esempio n. 5
0
 public EditAttributesViewData(Person currentPerson, Models.TreatmentBMP treatmentBMP,
                               CustomAttributeTypePurpose customAttributeTypePurpose, bool missingRequiredAttributes) : base(currentPerson, treatmentBMP, customAttributeTypePurpose, false, missingRequiredAttributes)
 {
 }
 public EditAttributesViewModel(Models.TreatmentBMP treatmentBMP,
                                CustomAttributeTypePurpose customAttributeTypePurpose)
 {
     CustomAttributes = treatmentBMP.CustomAttributes.Where(x => x.CustomAttributeType.CustomAttributeTypePurposeID == customAttributeTypePurpose.CustomAttributeTypePurposeID).Select(x => new CustomAttributeSimple(x)).ToList();
 }