コード例 #1
0
        public override bool Search(bool preserveSelection)
        {
            criteria.Validate(true);
            ErrorList valErr = criteria.GetValidationErrors();
            errors.List.DataSource = valErr.Errors;
            errors.List.DataBind();
            if (valErr.HasErrors()) return false;

            ICustomerService svcCustomer = DI.Resolve<ICustomerService>();
            try
            {
                Customer_ReadListInput_Criteria inReadList_Criteria = new Customer_ReadListInput_Criteria();
                criteria.ToDataContract(inReadList_Criteria);
                IEnumerable<Customer_ReadListOutput> outReadList;
                using (TimeTracker.ServiceCall)
                    outReadList = svcCustomer.ReadList(inReadList_Criteria);
                list.FromDataContract(outReadList, preserveSelection);
                list.AppliedCriteria = criteria.GetFieldCriteriaSettings();
                uclAppliedCriteria.BindTo(list.AppliedCriteria);
                return true;
            }
            catch (Exception ex)
            {
                errors.List.DataSource = ErrorList.FromException(ex).Errors;
                errors.List.DataBind();
            }
            finally
            {
                if (svcCustomer is IDisposable) ((IDisposable)svcCustomer).Dispose();
            }
            return false;
        }
コード例 #2
0
        public virtual IEnumerable<Customer_ReadListOutput> ReadList(Customer_ReadListInput_Criteria _criteria)
        {
            IEnumerable<Customer_ReadListOutput> res = null;
            using (AdventureWorksEntities ctx = new AdventureWorksEntities())
            {
                var src = from obj in ctx.Customer select obj;
                #region Source filter
                if (_criteria != null)
                {
                }
                // CUSTOM_CODE_START: add custom filter criteria to the source query for ReadList operation below
                // src = src.Where(o => o.FieldName == VALUE);
                // CUSTOM_CODE_END
                #endregion
                var qry = from obj in src
                          select new Customer_ReadListOutput() {
                              CustomerId = obj.CustomerId,
                              StoreId = obj.StoreIdObject.BusinessEntityId,
                              // CUSTOM_CODE_START: set the StoreName output parameter of ReadList operation below
                              StoreName = obj.StoreIdObject.Name, // CUSTOM_CODE_END
                              PersonId = obj.PersonIdObject.BusinessEntityId,
                              // CUSTOM_CODE_START: set the PersonName output parameter of ReadList operation below
                              PersonName = obj.PersonIdObject.LastName + ", " + obj.PersonIdObject.FirstName, // CUSTOM_CODE_END
                              AccountNumber = obj.AccountNumber,
                              TerritoryId = obj.TerritoryIdObject.TerritoryId,
                          };
                #region Result filter
                if (_criteria != null)
                {
                    if (_criteria.TerritoryId != null)
                        qry = qry.Where(o => o.TerritoryId == _criteria.TerritoryId);

                    #region PersonName
                    if (_criteria.PersonNameOperator != null)
                    {
                        switch (_criteria.PersonNameOperator)
                        {
                            case Operators.IsNull:
                                qry = qry.Where(o => o.PersonName == null); break;
                            case Operators.IsNotNull:
                                qry = qry.Where(o => o.PersonName != null); break;
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.PersonName == _criteria.PersonName); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.PersonName != _criteria.PersonName); break;
                            case Operators.Contains:
                                qry = qry.Where(o => o.PersonName.Contains(_criteria.PersonName)); break;
                            case Operators.DoesNotContain:
                                qry = qry.Where(o => !o.PersonName.Contains(_criteria.PersonName)); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Person Name.", _criteria.PersonNameOperator); break;
                        }
                    }
                    #endregion

                    #region StoreName
                    if (_criteria.StoreNameOperator != null)
                    {
                        switch (_criteria.StoreNameOperator)
                        {
                            case Operators.IsNull:
                                qry = qry.Where(o => o.StoreName == null); break;
                            case Operators.IsNotNull:
                                qry = qry.Where(o => o.StoreName != null); break;
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.StoreName == _criteria.StoreName); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.StoreName != _criteria.StoreName); break;
                            case Operators.Contains:
                                qry = qry.Where(o => o.StoreName.Contains(_criteria.StoreName)); break;
                            case Operators.DoesNotContain:
                                qry = qry.Where(o => !o.StoreName.Contains(_criteria.StoreName)); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Store Name.", _criteria.StoreNameOperator); break;
                        }
                    }
                    #endregion

                    #region AccountNumber
                    if (_criteria.AccountNumberOperator != null)
                    {
                        switch (_criteria.AccountNumberOperator)
                        {
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.AccountNumber == _criteria.AccountNumber); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.AccountNumber != _criteria.AccountNumber); break;
                            case Operators.Contains:
                                qry = qry.Where(o => o.AccountNumber.Contains(_criteria.AccountNumber)); break;
                            case Operators.DoesNotContain:
                                qry = qry.Where(o => !o.AccountNumber.Contains(_criteria.AccountNumber)); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Account Number.", _criteria.AccountNumberOperator); break;
                        }
                    }
                    #endregion
                }
                // CUSTOM_CODE_START: add custom filter criteria to the result query for ReadList operation below
                // qry = qry.Where(o => o.FieldName == VALUE);
                // CUSTOM_CODE_END
                #endregion
                ErrorList.Current.AbortIfHasErrors(HttpStatusCode.BadRequest);
                res = qry.ToList();
            }
            return res;
        }
コード例 #3
0
        /// <inheritdoc/>
        public virtual async Task <Output <ICollection <Customer_ReadListOutput> > > ReadListAsync(Customer_ReadListInput_Criteria _criteria)
        {
            HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, $"customer?{ ToQueryString(_criteria) }");

            using (var resp = await Http.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead))
            {
                var content = await resp.Content.ReadAsStreamAsync();

                return(await JsonSerializer.DeserializeAsync <Output <ICollection <Customer_ReadListOutput> > >(content, SerializerOptions));
            }
        }