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;

            ISalesOrderService svcSalesOrder = DI.Resolve<ISalesOrderService>();
            try
            {
                SalesOrder_ReadListInput_Criteria inReadList_Criteria = new SalesOrder_ReadListInput_Criteria();
                criteria.ToDataContract(inReadList_Criteria);
                IEnumerable<SalesOrder_ReadListOutput> outReadList;
                using (TimeTracker.ServiceCall)
                    outReadList = svcSalesOrder.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 (svcSalesOrder is IDisposable) ((IDisposable)svcSalesOrder).Dispose();
            }
            return false;
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public virtual async Task <Output <ICollection <SalesOrder_ReadListOutput> > > ReadListAsync(SalesOrder_ReadListInput_Criteria _criteria)
        {
            HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Get, $"sales-order?{ ToQueryString(_criteria) }");

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

                return(await JsonSerializer.DeserializeAsync <Output <ICollection <SalesOrder_ReadListOutput> > >(content, SerializerOptions));
            }
        }
        public virtual IEnumerable<SalesOrder_ReadListOutput> ReadList(SalesOrder_ReadListInput_Criteria _criteria)
        {
            IEnumerable<SalesOrder_ReadListOutput> res = null;
            using (AdventureWorksEntities ctx = new AdventureWorksEntities())
            {
                var src = from obj in ctx.SalesOrder select obj;
                #region Source filter
                if (_criteria != null)
                {

                    // CUSTOM_CODE_START: add code for GlobalRegion criteria of ReadList operation below
                    if (_criteria.GlobalRegion != null)
                    {
                        src = src.Where(o => _criteria.GlobalRegion == o.TerritoryIdObject.Group);
                    } // CUSTOM_CODE_END
                }
                // 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 SalesOrder_ReadListOutput() {
                              SalesOrderId = obj.SalesOrderId,
                              SalesOrderNumber = obj.SalesOrderNumber,
                              Status = obj.Status,
                              OrderDate = obj.OrderDate,
                              ShipDate = obj.ShipDate,
                              DueDate = obj.DueDate,
                              TotalDue = obj.TotalDue,
                              OnlineOrderFlag = obj.OnlineOrderFlag,
                              // CUSTOM_CODE_START: set the CustomerStore output parameter of ReadList operation below
                              CustomerStore = obj.CustomerIdObject.StoreIdObject.Name, // CUSTOM_CODE_END
                              // CUSTOM_CODE_START: set the CustomerName output parameter of ReadList operation below
                              CustomerName = obj.CustomerIdObject.PersonIdObject.LastName + ", " +
                                             obj.CustomerIdObject.PersonIdObject.FirstName, // CUSTOM_CODE_END
                              SalesPersonId = obj.SalesPersonIdObject.BusinessEntityId,
                              TerritoryId = obj.TerritoryIdObject.TerritoryId,
                          };
                #region Result filter
                if (_criteria != null)
                {
                    #region SalesOrderNumber
                    if (_criteria.SalesOrderNumberOperator != null)
                    {
                        switch (_criteria.SalesOrderNumberOperator)
                        {
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.SalesOrderNumber == _criteria.SalesOrderNumber); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.SalesOrderNumber != _criteria.SalesOrderNumber); break;
                            case Operators.Contains:
                                qry = qry.Where(o => o.SalesOrderNumber.Contains(_criteria.SalesOrderNumber)); break;
                            case Operators.DoesNotContain:
                                qry = qry.Where(o => !o.SalesOrderNumber.Contains(_criteria.SalesOrderNumber)); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Sales Order Number.", _criteria.SalesOrderNumberOperator); break;
                        }
                    }
                    #endregion

                    #region Status
                    if (_criteria.StatusOperator != null)
                    {
                        switch (_criteria.StatusOperator)
                        {
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.Status == _criteria.Status); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.Status != _criteria.Status); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Status.", _criteria.StatusOperator); break;
                        }
                    }
                    #endregion

                    #region OrderDate
                    if (_criteria.OrderDateOperator != null)
                    {
                        switch (_criteria.OrderDateOperator)
                        {
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.OrderDate == _criteria.OrderDate); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.OrderDate != _criteria.OrderDate); break;
                            case Operators.IsEarlierThan:
                                qry = qry.Where(o => o.OrderDate < _criteria.OrderDate); break;
                            case Operators.IsLaterThan:
                                qry = qry.Where(o => o.OrderDate > _criteria.OrderDate); break;
                            case Operators.IsBetween:
                                qry = qry.Where(o => o.OrderDate >= _criteria.OrderDate && o.OrderDate <= _criteria.OrderDate2); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Order Date.", _criteria.OrderDateOperator); break;
                        }
                    }
                    #endregion

                    #region DueDate
                    if (_criteria.DueDateOperator != null)
                    {
                        switch (_criteria.DueDateOperator)
                        {
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.DueDate == _criteria.DueDate); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.DueDate != _criteria.DueDate); break;
                            case Operators.IsEarlierThan:
                                qry = qry.Where(o => o.DueDate < _criteria.DueDate); break;
                            case Operators.IsLaterThan:
                                qry = qry.Where(o => o.DueDate > _criteria.DueDate); break;
                            case Operators.IsBetween:
                                qry = qry.Where(o => o.DueDate >= _criteria.DueDate && o.DueDate <= _criteria.DueDate2); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Due Date.", _criteria.DueDateOperator); break;
                        }
                    }
                    #endregion

                    #region TotalDue
                    if (_criteria.TotalDueOperator != null)
                    {
                        switch (_criteria.TotalDueOperator)
                        {
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.TotalDue == _criteria.TotalDue); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.TotalDue != _criteria.TotalDue); break;
                            case Operators.IsLessThan:
                                qry = qry.Where(o => o.TotalDue < _criteria.TotalDue); break;
                            case Operators.IsNotLessThan:
                                qry = qry.Where(o => o.TotalDue >= _criteria.TotalDue); break;
                            case Operators.IsGreaterThan:
                                qry = qry.Where(o => o.TotalDue > _criteria.TotalDue); break;
                            case Operators.IsNotGreaterThan:
                                qry = qry.Where(o => o.TotalDue <= _criteria.TotalDue); break;
                            case Operators.IsBetween:
                                qry = qry.Where(o => o.TotalDue >= _criteria.TotalDue && o.TotalDue <= _criteria.TotalDue2); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Total Due.", _criteria.TotalDueOperator); break;
                        }
                    }
                    #endregion

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

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

                    #region TerritoryId
                    if (_criteria.TerritoryIdOperator != null)
                    {
                        switch (_criteria.TerritoryIdOperator)
                        {
                            case Operators.IsNull:
                                qry = qry.Where(o => o.TerritoryId == null); break;
                            case Operators.IsNotNull:
                                qry = qry.Where(o => o.TerritoryId != null); break;
                            case Operators.IsEqualTo:
                                qry = qry.Where(o => o.TerritoryId == _criteria.TerritoryId); break;
                            case Operators.IsNotEqualTo:
                                qry = qry.Where(o => o.TerritoryId != _criteria.TerritoryId); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Territory Id.", _criteria.TerritoryIdOperator); break;
                        }
                    }
                    #endregion

                    #region SalesPersonId
                    if (_criteria.SalesPersonIdOperator != null)
                    {
                        switch (_criteria.SalesPersonIdOperator)
                        {
                            case Operators.IsNull:
                                qry = qry.Where(o => o.SalesPersonId == null); break;
                            case Operators.IsNotNull:
                                qry = qry.Where(o => o.SalesPersonId != null); break;
                            case Operators.IsOneOf:
                                qry = qry.WhereIn(o => o.SalesPersonId, _criteria.SalesPersonId); break;
                            case Operators.IsNoneOf:
                                qry = qry.WhereNotIn(o => o.SalesPersonId, _criteria.SalesPersonId); break;
                            default:
                                ErrorList.Current.AddError("Unsupported operator {0} for the Sales Person Id.", _criteria.SalesPersonIdOperator); 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;
        }