コード例 #1
0
        public async Task <ActionResult> ReadListAsync([FromQuery] Customer_ReadListInput_Criteria _criteria)
        {
            ActionResult response;

            try
            {
                if (ModelState.IsValid)
                {
                    Output <ICollection <Customer_ReadListOutput> > output = await svc.ReadListAsync(_criteria);

                    response = StatusCode((int)output.HttpStatus, output);
                    return(response);
                }
                else
                {
                    currentErrors.AddModelErrors(ModelState);
                }
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorsParser.FromException(ex));
            }
            response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors));
            return(response);
        }
コード例 #2
0
        public virtual Output <ICollection <Customer_ReadListOutput> > ReadList(Customer_ReadListInput_Criteria _criteria)
        {
            // CUSTOM_CODE_START: add custom security checks for ReadList operation below
            // CUSTOM_CODE_END
            ICollection <Customer_ReadListOutput> res = null;

            try
            {
                var src = from obj in ctx.Customer select obj;

                // 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

                var qry = from obj in src
                          select new Customer_ReadListOutput()
                {
                    CustomerId = obj.CustomerId,
                    StoreId    = obj.StoreId,
                    // CUSTOM_CODE_START: set the StoreName output parameter of ReadList operation below
                    StoreName = obj.StoreObject.Name,           // CUSTOM_CODE_END
                    PersonId  = obj.PersonId,
                    // CUSTOM_CODE_START: set the PersonName output parameter of ReadList operation below
                    PersonName    = obj.PersonObject.FullName,        // CUSTOM_CODE_END
                    AccountNumber = obj.AccountNumber,
                    TerritoryId   = obj.TerritoryId,
                };

                // Result filter
                if (_criteria != null)
                {
                    qry = AddClause(qry, "TerritoryId", o => o.TerritoryId, _criteria.TerritoryId);
                    qry = AddClause(qry, "PersonName", o => o.PersonName, _criteria.PersonNameOperator, _criteria.PersonName);
                    qry = AddClause(qry, "StoreName", o => o.StoreName, _criteria.StoreNameOperator, _criteria.StoreName);
                    qry = AddClause(qry, "AccountNumber", o => o.AccountNumber, _criteria.AccountNumberOperator, _criteria.AccountNumber);
                }

                // 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

                currentErrors.AbortIfHasErrors();
                res = qry.ToList();
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorParser.FromException(ex));
            }
            return(new Output <ICollection <Customer_ReadListOutput> >(currentErrors, res));
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: CustomerList.cs プロジェクト: ksharma7/Test
        protected virtual Output <ICollection <Customer_ReadListOutput> > Customer_ReadList(Customer_ReadListInput_Criteria _criteria, object options)
        {
            using (var s = ServiceProvider.CreateScope())
            {
                var output = s.ServiceProvider.GetService <ICustomerService>().ReadList(_criteria);

                FromDataContract(output?.Result, options);
                return(output);
            }
        }
コード例 #6
0
        protected virtual async Task <Output <ICollection <Customer_ReadListOutput> > > Customer_ReadListAsync(object options, Customer_ReadListInput_Criteria _criteria)
        {
            using (var s = ServiceProvider.CreateScope())
            {
                var output = await s.ServiceProvider.GetService <ICustomerService>().ReadListAsync(_criteria);

                await FromDataContractAsync(output?.Result, options);

                return(output);
            }
        }