Ejemplo n.º 1
0
        public IHttpActionResult GetMultiCrossRefValues(CrossRefLoadModel requestModel)
        {
            if (requestModel == null)
            {
                throw new ArgumentNullException("requestModel");
            }

            try
            {
                DetailsModelContainer detailsModel = ExtractModelFromRequest(requestModel);
                if (detailsModel.Model == null)
                {
                    return this.Json(new DetailsSaveResult { Success = false, Message = "Item not found. Was it deleted while you were editing it?" });
                }

                string fullName = string.Join(".", detailsModel.Model.GetFullPropertyPath(requestModel.FieldName));
                PropertyInfo property = detailsModel.Model.GetPropertyByFullName(fullName);

                IEditableRoot model = detailsModel.Model.GetAncestor(property);

                MobileObservableCollection<IFilterDescriptor> filterList = new MobileObservableCollection<IFilterDescriptor>();
                IEnumerable<IFilterDescriptor> crossRefFilters = DynamicTypeManager.GetCrossRefFilter(model, requestModel.FieldName);
                if (crossRefFilters != null)
                {
                    filterList.AddRange(crossRefFilters);
                }

                //string filterText = string.Empty; // (FilterString ?? string.Empty).Trim();

                //if (!string.IsNullOrEmpty(filterText))
                //{
                //    var quickSearchFilters = new MobileObservableCollection<IFilterDescriptor>();

                //    //foreach (var column in Columns)
                //    //{
                //    //    quickSearchFilters.Add(new FilterDescriptor(column.Property.Name, FilterOperator.Contains, filterText));
                //    //}

                //    filterList.Add(new FilterDescriptor(LogicalOperators.Or, quickSearchFilters));
                //}

                var items = DynamicTypeManager.GetCrossReferenceList(
                        model.ProcessName,
                        requestModel.FieldName,
                        null,
                        // SortDescriptors,
                        string.Empty,
                        1000,
                        // PageSize
                        0,
                        //CurrentPageNumber,
                        FilterDescriptor.GetFilterExpression(filterList)
                    );

                CrossRefFieldAttribute mcrAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>();

                IList<IdValues> values = new List<IdValues>();
                foreach (var l in items)
                {
                    var id = (int)l.GetType().GetProperty(Constants.IdColumnName).GetValue(l);
                    var value = SafeTypeConverter.Convert<string>(l.GetType().GetProperty(mcrAttribute.RefFieldName).GetValue(l));
                    values.Add(new IdValues(id, value));
                }

                return this.Ok(values);
            }
            catch (Exception ex)
            {
                Logger.Log(LogSeverity.Error, "ProcessController", ex);
                throw;
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult GetSingleCrossRefValues(CrossRefLoadModel requestModel)
        {
            if (requestModel == null)
            {
                throw new ArgumentNullException("requestModel");
            }

            try
            {
                DetailsModelContainer detailModel = ExtractModelFromRequest(requestModel);
                if (detailModel.Model == null)
                {
                    return Json(new DetailsSaveResult { Success = false, Message = "Item not found. Was it deleted while you were editing it?" });
                }

                string fullName = string.Join(".", detailModel.Model.GetFullPropertyPath(requestModel.FieldName));
                PropertyInfo property = detailModel.Model.GetPropertyByFullName(fullName);

                IEditableRoot entity = detailModel.Model.GetAncestor(property);

                var filterList = new MobileObservableCollection<IFilterDescriptor>();
                
                var crossRefFilters = DynamicTypeManager.GetCrossRefFilter(entity, requestModel.FieldName);
                if (crossRefFilters != null)
                {
                    filterList.AddRange(crossRefFilters);
                }

                var items = DynamicTypeManager.GetCrossReferenceListPage(entity.ProcessName, requestModel.FieldName, entity.Id, null, 1000, filterExpression: FilterDescriptor.GetFilterExpression(filterList));

                CrossRefFieldAttribute customAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>();

                IList<IdValues> values = new List<IdValues>();
                foreach (var item in items)
                {
                    var id = (int)item.GetType().GetProperty(Constants.IdColumnName).GetValue(item);
                    var value = SafeTypeConverter.Convert<string>(item.GetType().GetProperty(customAttribute.RefFieldName).GetValue(item));
                    values.Add(new IdValues(id, value));
                }

                return Ok(values);
            }
            catch (Exception ex)
            {
                Logger.Log(LogSeverity.Error, "ProcessController", ex);
                throw;
            }
        }