コード例 #1
0
        public static BLL_CLASS ToBLLModel <API_CLASS, BLL_CLASS>(dynamic partialApiModel)
            where API_CLASS : BaseApiModel <BLL_CLASS>
            where BLL_CLASS : BaseChangeTrackingEntity
        {
            APIMessageException apiException  = null;
            API_CLASS           apiModel      = (API_CLASS)Activator.CreateInstance(typeof(API_CLASS), new object[] { });
            List <string>       changedFields = new List <string>();

            foreach (var item in partialApiModel.Children())
            {
                try
                {
                    ObjectExtensions.SetPropertyValue(apiModel, item.Name, item.Value);

                    // Translate Property Name from API_CLASS to BLL_CLASS
                    string propertyName = PropertyMapper.GetPropertyName <API_CLASS, BLL_CLASS>(item.Name);
                    changedFields.Add(propertyName);
                }
                catch (Exception)
                {
                    apiException = apiException ?? new IllegalArgumentAPIException("Invalid Field");
                    apiException.Add(item.Name, $"Error applying value to field '{item.Name}' on '{apiModel.GetType().Name}'.");
                }
            }

            if (apiException != null)
            {
                throw apiException;
            }

            BLL_CLASS model = apiModel.ToBLLModel();

            model.AddChangedFields(changedFields);
            return(model);
        }
コード例 #2
0
        protected IHttpActionResult Search <T>(string filter, T criteria, Func <SearchCriteria, IEnumerable <string>, IEnumerable> distinct, Func <SearchCriteria, IPaginatedList <BLL_CLASS> > search, Func <SearchCriteria, MemoryStream> export) where T : APISearchCriteria, new()
        {
            criteria = criteria ?? new T();
            if (filter.HasValue())
            {
                criteria.FilterParameters.AddRange(JsonConvert.DeserializeObject <List <FilterParameter> >(filter));
            }

            IEnumerable <string> columns        = criteria.Columns?.Select(c => PropertyMapper.GetPropertyName <API_CLASS, BLL_CLASS>(c));
            SearchCriteria       searchCriteria = criteria.ToSearchCriteria().MapProperties <API_CLASS, BLL_CLASS>();

            // Set default filter operator based on type
            foreach (FilterParameter filterParameter in searchCriteria.Parameters.Where(f => f.FilterOperator == ComparisonType.None))
            {
                Type propertyType = filterParameter.Name.GetPropertyType <BLL_CLASS>();
                filterParameter.FilterOperator = (DEFAULT_COMPARISON_TYPE.ContainsKey(propertyType)) ? DEFAULT_COMPARISON_TYPE[propertyType] : ComparisonType.Equals;
            }

            if (export != null && criteria.ExportType == ExportTypeEnum.Excel)
            {
                // NOTE: 10/30/18 - This code is not currently used. In fact, it does not work because the MemoryStream is disposed
                // at a lower level. The client currently requests all records and creates an Excel document via ag-grid.
                // We should review in the future with ticket ENTPRC-4890
                MemoryStream memoryStream = export(searchCriteria);
                if (memoryStream == null)
                {
                    return(NotFound());
                }

                HttpResponseMessage response = new HttpResponseMessage();
                response.StatusCode = HttpStatusCode.OK;
                response.Content    = new StreamContent(memoryStream);
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                //response.Content.Headers.ContentLength = memoryStream.Length;
                return(ResponseMessage(response));
            }
            else if (distinct != null && criteria.IsDistinct)
            {
                IEnumerable searchResults = distinct(searchCriteria, columns);
                return(Ok(searchResults));
            }
            else
            {
                IPaginatedList <BLL_CLASS> searchResults = search(searchCriteria);
                return(SearchResponse(searchResults));
            }
        }
コード例 #3
0
        public SearchCriteria MapProperties <F, T>()
        {
            _parameters.ForEach(p => { p.Name = PropertyMapper.GetPropertyName <F, T>(p.Name); });
            _sortedFields.ForEach(s => { s.FieldName = PropertyMapper.GetPropertyName <F, T>(s.FieldName); });
            _aggregateFields.ForEach(p => { p.Field = PropertyMapper.GetPropertyName <F, T>(p.Field); });

            //IEnumerable<string> sumFields = this._summaryFields.Select((field) => PropertyMapper.GetPropertyName<F, T>(field)).ToList();
            //_summaryFields.Clear();
            //_summaryFields.AddRange(sumFields);

            // Validate that mapped properties are valid
            var validProperties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(p => p.Name).ToList();

            validProperties.AddRange(PropertyMapper.GetReferenceOnlyProperties <F, T>());
            ValidateSearchCriteria(validProperties, validProperties);

            return(this);
        }