Beispiel #1
0
        /// <summary>
        /// Gets the <see cref="Person"/> collection object that matches the selection criteria.
        /// </summary>
        /// <param name="args">The Args (see <see cref="PersonArgs"/>).</param>
        /// <param name="paging">The <see cref="PagingArgs"/>.</param>
        /// <returns>A <see cref="PersonCollectionResult"/>.</returns>
        public Task <PersonCollectionResult> GetByArgsWithEfAsync(PersonArgs args, PagingArgs paging)
        {
            return(ManagerInvoker.Default.InvokeAsync(this, async() =>
            {
                ExecutionContext.Current.OperationType = OperationType.Read;
                EntityBase.CleanUp(args);
                if (_getByArgsWithEfOnPreValidateAsync != null)
                {
                    await _getByArgsWithEfOnPreValidateAsync(args, paging).ConfigureAwait(false);
                }

                MultiValidator.Create()
                .Add(args.Validate(nameof(args)).Entity(PersonArgsValidator.Default))
                .Additional((__mv) => _getByArgsWithEfOnValidate?.Invoke(__mv, args, paging))
                .Run().ThrowOnError();

                if (_getByArgsWithEfOnBeforeAsync != null)
                {
                    await _getByArgsWithEfOnBeforeAsync(args, paging).ConfigureAwait(false);
                }
                var __result = await PersonDataSvc.GetByArgsWithEfAsync(args, paging).ConfigureAwait(false);
                if (_getByArgsWithEfOnAfterAsync != null)
                {
                    await _getByArgsWithEfOnAfterAsync(__result, args, paging).ConfigureAwait(false);
                }
                Cleaner.Clean(__result);
                return __result;
            }));
        }
Beispiel #2
0
 /// <summary>
 /// Gets the <see cref="PersonDetail"/> collection object that matches the selection criteria.
 /// </summary>
 /// <param name="args">The Args (see <see cref="PersonArgs"/>).</param>
 /// <param name="paging">The <see cref="PagingArgs"/>.</param>
 /// <returns>A <see cref="PersonDetailCollectionResult"/>.</returns>
 public Task <PersonDetailCollectionResult> GetDetailByArgsAsync(PersonArgs args, PagingArgs paging)
 {
     return(DataInvoker.Default.InvokeAsync(this, () => GetDetailByArgsOnImplementationAsync(args, paging),
                                            new BusinessInvokerArgs {
         ExceptionHandler = _getDetailByArgsOnException
     }));
 }
Beispiel #3
0
 private IQueryable <Person> GetByArgsOnQuery(IQueryable <Person> q, PersonArgs args, ICosmosDbArgs dbArgs)
 {
     q = q.WhereWildcard(x => x.FirstName, args?.FirstName);
     q = q.WhereWildcard(x => x.LastName, args?.LastName);
     q = q.WhereWith(args?.Genders, x => args.Genders.ToCodeList().Contains(x.GenderSid));
     return(q.OrderBy(x => x.LastName));
 }
Beispiel #4
0
        public IActionResult GetByArgsWithEf(string?firstName = default, string?lastName = default, List <string>?genders = default)
        {
            var args = new PersonArgs {
                FirstName = firstName, LastName = lastName, GendersSids = genders
            };

            return(new WebApiGet <PersonCollectionResult, PersonCollection, Person>(this, () => Factory.Create <IPersonManager>().GetByArgsWithEfAsync(args, WebApiQueryString.CreatePagingArgs(this)),
                                                                                    operationType: OperationType.Read, statusCode: HttpStatusCode.OK, alternateStatusCode: HttpStatusCode.NoContent));
        }
Beispiel #5
0
        private void GetByArgs_EmptyArgs(bool useEf)
        {
            // Test with null args.
            var args = new PersonArgs {
            };
            var pcr  = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                       .ExpectStatusCode(HttpStatusCode.OK)
                       .Run((a) => useEf ? a.Agent.GetByArgsWithEfAsync(args) : a.Agent.GetByArgsAsync(args));

            // Check all 4 are returned in the sorted order.
            Assert.AreEqual(4, pcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "Browne", "Jones", "Smith", "Smithers" }, pcr.Value.Result.Select(x => x.LastName).ToArray());
        }
Beispiel #6
0
        private void GetByArgs_Args_FirstNameAndGender(bool useEf)
        {
            // Test with null args.
            var args = new PersonArgs {
                FirstName = "*a*", Genders = new RefData.ReferenceDataSidList <Gender, string>(new Gender[] { "F" })
            };
            var pcr = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run((a) => useEf ? a.Agent.GetByArgsWithEfAsync(args) : a.Agent.GetByArgsAsync(args));

            // Check 1 is returned in the sorted order.
            Assert.AreEqual(1, pcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "Browne" }, pcr.Value.Result.Select(x => x.LastName).ToArray());
        }
Beispiel #7
0
        public void D310_GetDetailByArgs_LastName()
        {
            var args = new PersonArgs {
                LastName = "sm*"
            };
            var pdcr = AgentTester.Create <PersonAgent, PersonDetailCollectionResult>()
                       .ExpectStatusCode(HttpStatusCode.OK)
                       .Run((a) => a.Agent.GetDetailByArgsAsync(args, PagingArgs.CreateSkipAndTake(0, 2, true)));

            Assert.AreEqual(2, pdcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "Smith", "Smithers" }, pdcr.Value.Result.Select(x => x.LastName).ToArray());
            Assert.AreEqual(2, pdcr.Value.Result[0].History.Count);
            Assert.AreEqual(2, pdcr.Value.Result[1].History.Count);

            Assert.AreEqual(2, pdcr.Value.Paging.TotalCount);
        }
Beispiel #8
0
        public void B140_GetByArgs()
        {
            var args = new PersonArgs {
                LastName = "sm*"
            };
            var pcr = AgentTester.Test <PersonAgent, PersonCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run(a => a.GetByArgsAsync(args));

            var etag = pcr.Response.Headers.ETag.Tag;

            AgentTester.Test <PersonAgent, PersonCollectionResult>()
            .ExpectStatusCode(HttpStatusCode.NotModified)
            .Run(a => a.GetByArgsAsync(args, requestOptions: new WebApiRequestOptions {
                ETag = etag
            }));
        }
        public void B140_GetByArgs()
        {
            var args = new PersonArgs {
                LastName = "sm*"
            };
            var pcr = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run((a) => a.Agent.GetByArgsAsync(args));

            var etag = pcr.Response.Headers.ETag.Tag;

            AgentTester.Create <PersonAgent, PersonCollectionResult>()
            .ExpectStatusCode(HttpStatusCode.NotModified)
            .Run((a) => new PersonAgent(a.Client, (r) =>
            {
                r.Headers.IfNoneMatch.Add(new System.Net.Http.Headers.EntityTagHeaderValue(etag));
            }).GetByArgsAsync(args));
        }
Beispiel #10
0
 /// <summary>
 /// Gets the <see cref="Person"/> collection object that matches the selection criteria.
 /// </summary>
 /// <param name="args">The Args (see <see cref="PersonArgs"/>).</param>
 /// <param name="paging">The <see cref="PagingArgs"/>.</param>
 /// <returns>A <see cref="PersonCollectionResult"/>.</returns>
 public Task <PersonCollectionResult> GetByArgsWithEfAsync(PersonArgs args, PagingArgs paging)
 {
     return(DataInvoker.Default.InvokeAsync(this, async() =>
     {
         PersonCollectionResult __result = new PersonCollectionResult(paging);
         var __dataArgs = EfMapper.Default.CreateArgs(__result.Paging);
         if (_getByArgsWithEfOnBeforeAsync != null)
         {
             await _getByArgsWithEfOnBeforeAsync(args, __dataArgs).ConfigureAwait(false);
         }
         __result.Result = EfDb.Default.Query(__dataArgs, q => _getByArgsWithEfOnQuery == null ? q : _getByArgsWithEfOnQuery(q, args, __dataArgs)).SelectQuery <PersonCollection>();
         if (_getByArgsWithEfOnAfterAsync != null)
         {
             await _getByArgsWithEfOnAfterAsync(__result, args).ConfigureAwait(false);
         }
         return __result;
     }, new BusinessInvokerArgs {
         ExceptionHandler = _getByArgsWithEfOnException
     }));
 }
Beispiel #11
0
 /// <summary>
 /// Gets the <see cref="Person"/> collection object that matches the selection criteria.
 /// </summary>
 /// <param name="args">The Args (see <see cref="PersonArgs"/>).</param>
 /// <param name="paging">The <see cref="PagingArgs"/>.</param>
 /// <returns>A <see cref="PersonCollectionResult"/>.</returns>
 public Task <PersonCollectionResult> GetByArgsAsync(PersonArgs args, PagingArgs paging)
 {
     return(DataInvoker.Default.InvokeAsync(this, async() =>
     {
         PersonCollectionResult __result = new PersonCollectionResult(paging);
         var __dataArgs = DbMapper.Default.CreateArgs("[Demo].[spPersonGetByArgs]", __result.Paging);
         if (_getByArgsOnBeforeAsync != null)
         {
             await _getByArgsOnBeforeAsync(args, __dataArgs).ConfigureAwait(false);
         }
         __result.Result = Database.Default.Query(__dataArgs, p => _getByArgsOnQuery?.Invoke(p, args, __dataArgs)).SelectQuery <PersonCollection>();
         if (_getByArgsOnAfterAsync != null)
         {
             await _getByArgsOnAfterAsync(__result, args).ConfigureAwait(false);
         }
         return __result;
     }, new BusinessInvokerArgs {
         ExceptionHandler = _getByArgsOnException
     }));
 }
 /// <summary>
 /// Gets the <see cref="Person"/> collection object that matches the selection criteria.
 /// </summary>
 /// <param name="args">The Args (see <see cref="PersonArgs"/>).</param>
 /// <param name="paging">The <see cref="PagingArgs"/>.</param>
 /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param>
 /// <returns>A <see cref="WebApiAgentResult"/>.</returns>
 public Task <WebApiAgentResult <PersonCollectionResult> > GetByArgsWithEfAsync(PersonArgs args, PagingArgs paging = null, WebApiRequestOptions requestOptions = null)
 {
     return(base.GetCollectionResultAsync <PersonCollectionResult, PersonCollection, Person>("api/v1/persons/args", requestOptions: requestOptions,
                                                                                             args: new WebApiArg[] { new WebApiArg <PersonArgs>("args", args, WebApiArgType.FromUriUseProperties), new WebApiPagingArgsArg("paging", paging) }));
 }
Beispiel #13
0
 public Task <PersonCollectionResult> GetByArgsAsync(PersonArgs args, PagingArgs?pagingArgs)
 {
     return(Task.FromResult <PersonCollectionResult>(new PersonCollectionResult(_dataStorage.Read <Person>())));
 }
Beispiel #14
0
 /// <summary>
 /// Gets the <see cref="Person"/> collection object that matches the selection criteria.
 /// </summary>
 /// <param name="args">The Args (see <see cref="PersonArgs"/>).</param>
 /// <param name="paging">The <see cref="PagingArgs"/>.</param>
 /// <param name="requestOptions">The optional <see cref="WebApiRequestOptions"/>.</param>
 /// <returns>A <see cref="WebApiAgentResult"/>.</returns>
 public Task <WebApiAgentResult <PersonCollectionResult> > GetByArgsWithEfAsync(PersonArgs args, PagingArgs paging = null, WebApiRequestOptions requestOptions = null)
 {
     return(PersonServiceAgent.GetByArgsWithEfAsync(args, paging, requestOptions));
 }
Beispiel #15
0
        private async Task <PersonDetailCollectionResult> GetDetailByArgsOnImplementationAsync(PersonArgs args, PagingArgs paging)
        {
            var pdcr = new PersonDetailCollectionResult(new PagingResult(paging));

            await _db.StoredProcedure("[Demo].[spPersonGetDetailByArgs]")
            .Params(p =>
            {
                p.ParamWithWildcard(args?.FirstName, DbMapper.Default[nameof(Person.FirstName)])
                .ParamWithWildcard(args?.LastName, DbMapper.Default[nameof(Person.LastName)])
                .TableValuedParamWith(args?.Genders, "GenderIds", () => TableValuedParameter.Create(args.Genders.ToGuidIdList()));
            })
            .SelectQueryMultiSetAsync(pdcr.Paging,
                                      new MultiSetCollArgs <PersonCollection, Person>(PersonData.DbMapper.Default, (r) => r.ForEach((p) => { var pd = new PersonDetail(); pd.CopyFrom(p); pdcr.Result.Add(pd); })),
                                      new MultiSetCollArgs <WorkHistoryCollection, WorkHistory>(WorkHistoryData.DbMapper.Default, (r) =>
            {
                PersonDetail pd = null;
                foreach (var wh in r)
                {
                    if (pd == null || wh.PersonId != pd.Id)
                    {
                        pd         = pdcr.Result.Where(x => x.Id == wh.PersonId).Single();
                        pd.History = new WorkHistoryCollection();
                    }

                    pd.History.Add(wh);
                }
            }));

            return(pdcr);
        }
Beispiel #16
0
 private IQueryable <EfModel.Person> GetByArgsWithEfOnQuery(IQueryable <EfModel.Person> q, PersonArgs args, EfDbArgs efArgs)
 {
     _ef.WithWildcard(args?.FirstName, (w) => q = q.Where(x => EF.Functions.Like(x.FirstName, w)));
     _ef.WithWildcard(args?.LastName, (w) => q  = q.Where(x => EF.Functions.Like(x.LastName, w)));
     _ef.With(args?.Genders, () => q            = q.Where(x => args.Genders.ToGuidIdList().Contains(x.GenderId.Value)));
     return(q.OrderBy(x => x.LastName).ThenBy(x => x.FirstName));
 }
Beispiel #17
0
 private void GetByArgsOnQuery(DatabaseParameters p, PersonArgs args, IDatabaseArgs dbArgs)
 {
     p.ParamWithWildcard(args?.FirstName, DbMapper.Default[nameof(Person.FirstName)])
     .ParamWithWildcard(args?.LastName, DbMapper.Default[nameof(Person.LastName)])
     .TableValuedParamWith(args?.Genders, "GenderIds", () => TableValuedParameter.Create(args.Genders.ToGuidIdList()));
 }
Beispiel #18
0
 private void GetByArgsOnQuery(DatabaseParameters p, PersonArgs args, IDatabaseArgs dbArgs)
 {
     p.ParamWithWildcard(args?.FirstName, DbMapper.Default[Person.Property_FirstName])
     .ParamWithWildcard(args?.LastName, DbMapper.Default[Person.Property_LastName])
     .TableValuedParamWith(args?.Genders, "GenderCodes", () => TableValuedParameter.Create(args.Genders.ToCodeList()));
 }
Beispiel #19
0
 public IActionResult GetByArgs(PersonArgs args)
 {
     return(new WebApiGet <PersonCollectionResult, PersonCollection, Person>(this, () => Manager.GetByArgsAsync(args, WebApiQueryString.CreatePagingArgs(this)),
                                                                             operationType: OperationType.Read, statusCode: HttpStatusCode.OK, alternateStatusCode: null));
 }
Beispiel #20
0
 public async Task <WebApiAgentResult <PersonCollectionResult> > GetByArgsAsync(PersonArgs args, PagingArgs?pagingArgs, WebApiRequestOptions?requestOptions = null)
 {
     return(await base.GetAsync <PersonCollectionResult>("api/v1/persons/", requestOptions : requestOptions,
                                                         args : new WebApiArg[] { new WebApiArg <PersonArgs>("args", args), new WebApiArg <PagingArgs?>("pagingArgs", pagingArgs) }));
 }