예제 #1
0
        internal IFacadeUpdateResult <SubjectData> SaveSubjectField(object subjectId, SubjectFieldInfoDto fieldInfoDto)
        {
            ArgumentValidator.IsNotNull("fieldInfoDto", fieldInfoDto);
            ArgumentValidator.IsNotNull("subjectId", subjectId);

            FacadeUpdateResult <SubjectData> result = new FacadeUpdateResult <SubjectData>();

            ISubjectService subjectService = UnitOfWork.GetService <ISubjectService>();
            var             subjectQuery   = subjectService.Retrieve(subjectId);

            if (!subjectQuery.HasResult)
            {
                AddError(result.ValidationResult, "SubjectCannotBeFound");
                return(result);
            }

            IDataTypeService dataTypeService = UnitOfWork.GetService <IDataTypeService>();
            int dataTypeId    = System.Convert.ToInt32(fieldInfoDto.FieldDataTypeId);
            var dataTypeQuery = dataTypeService.Retrieve(dataTypeId);

            if (!dataTypeQuery.HasResult)
            {
                AddError(result.ValidationResult, "DataTypeCannotBeFound");
                return(result);
            }

            Subject      subject      = subjectQuery.ToBo <Subject>();
            SubjectField subjectField = RetrieveOrNewSubjectField(subject, fieldInfoDto.SubjectFieldId);

            if (subjectField == null)
            {
                AddWarning(result.ValidationResult, "SubjectFieldCannotBeFound");
                return(result);
            }

            subjectField.FieldKey            = fieldInfoDto.FieldKey;
            subjectField.FieldLabel          = fieldInfoDto.FieldLabel;
            subjectField.HelpText            = fieldInfoDto.HelpText;
            subjectField.FieldDataType.Value = dataTypeQuery.ToBo <DataType>();
            subjectField.PickupEntityId      = fieldInfoDto.PickupEntityId;
            subjectField.LookupSubjectId     = fieldInfoDto.LookupSubjectId;
            subjectField.Sort         = fieldInfoDto.Sort;
            subjectField.RowIndex     = fieldInfoDto.RowIndex;
            subjectField.ColIndex     = fieldInfoDto.ColIndex;
            subjectField.IsRequired   = fieldInfoDto.IsRequired;
            subjectField.IsReadonly   = fieldInfoDto.IsReadonly;
            subjectField.IsLinkInGrid = fieldInfoDto.IsLinkInGrid;
            subjectField.IsShowInGrid = fieldInfoDto.IsShowInGrid;
            if (fieldInfoDto.MaxLength.HasValue)
            {
                subjectField.MaxLength = fieldInfoDto.MaxLength;
            }
            else
            {
                subjectField.MaxLength = fieldInfoDto.MaxLengthInTable;
            }
            subjectField.NavigateUrlFormatString = fieldInfoDto.NavigateUrlFormatString;

            var saveQuery = subjectService.Save(subject);

            result.Merge(saveQuery);
            result.AttachResult(subject.RetrieveData <SubjectData>());

            return(result);
        }