Esempio n. 1
0
        public async Task <PaginatedList <Kit> > GetAsync(KitQuery kitQuery)
        {
            var query = Context.Kits
                        .Include(k => k.Squad)
                        .AsQueryable();

            if (kitQuery.SquadId.HasValue)
            {
                query = query.Where(k => k.SquadId == kitQuery.SquadId);
            }
            else if (kitQuery.SeasonId.HasValue && kitQuery.ClubId.HasValue)
            {
                query = query.Where(k => k.Squad.SeasonId == kitQuery.SeasonId &&
                                    k.Squad.ClubId == kitQuery.ClubId);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Kit, object> > >()
            {
                ["id"] = p => p.Id
            };

            query = query.Sort(kitQuery, columnsMap);

            return(await PaginatedList <Kit> .CreateAsync(query, kitQuery.PageNumber, kitQuery.PageSize));
        }
        public async Task <IActionResult> GetKits([FromQuery] KitQuery kitQuery)
        {
            var kits = await _kitService.GetAsync(kitQuery);

            var returnKits = _mapper.Map <PaginatedList <KitListDto> >(kits, opt =>
            {
                if (kitQuery.SquadId.HasValue)
                {
                    opt.Items["squadId"] = kitQuery.SquadId;
                }
            });

            return(Ok(returnKits));
        }
Esempio n. 3
0
        /// <summary>
        /// Test Find using the Query class
        /// </summary>
        private void Step_30_TestFindByQuery_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                //Insert Mock Instance
                Kit  mock   = CreateMockInstance(tm);
                bool result = DataRepository.KitProvider.Insert(tm, mock);

                Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed");

                KitQuery query = new KitQuery();

                query.AppendEquals(KitColumn.Id, mock.Id.ToString());
                if (mock.Description != null)
                {
                    query.AppendEquals(KitColumn.Description, mock.Description.ToString());
                }
                if (mock.Unitsymb != null)
                {
                    query.AppendEquals(KitColumn.Unitsymb, mock.Unitsymb.ToString());
                }
                if (mock.Rtprice != null)
                {
                    query.AppendEquals(KitColumn.Rtprice, mock.Rtprice.ToString());
                }
                if (mock.OpenDate != null)
                {
                    query.AppendEquals(KitColumn.OpenDate, mock.OpenDate.ToString());
                }
                if (mock.Status != null)
                {
                    query.AppendEquals(KitColumn.Status, mock.Status.ToString());
                }

                TList <Kit> results = DataRepository.KitProvider.Find(tm, query);

                Assert.IsTrue(results.Count == 1, "Find is not working correctly.  Failed to find the mock instance");
            }
        }
 public async Task <PaginatedList <Kit> > GetAsync(KitQuery kitQuery)
 {
     return(await _kitRepository.GetAsync(kitQuery));
 }