Ejemplo n.º 1
0
 public static DbQuery <CardPayment> ToCardPaymentQuery(this MostlyUsedPaymentsQuery query, IList <Guid> cardIds)
 {
     Argument.NotNull(query, "query");
     return(DbQuery.For <CardPayment>()
            .FilterBy(x => cardIds.Contains(x.Card.Id))
            .AndFilterBy(x => x.CompletedDateUtc.HasValue &&
                         x.CompletedDateUtc >= query.From &&
                         x.CompletedDateUtc <= query.To));
 }
 public IList <PaymentCategoryUsagesModel> GetMostlyUsedPayments(MostlyUsedPaymentsQuery query)
 {
     EnsureIsValid(query);
     EnsureIsSecure <MostlyUsedPaymentsQuery, UserQueryValidator>(query);
     try
     {
         //TODO: of course it will be great to group in database first
         var cardIds      = _deps.UserCards.Select(DbQuery.For <UserCard>().FilterBy(x => x.Owner.Id == query.UserId), x => x.Id);
         var cardPayments = _deps.CardPayments.Query(query.ToCardPaymentQuery(cardIds));
         var groups       = cardPayments.GroupBy(x => x.Category);
         var usages       = groups.Select(g => new PaymentCategoryUsagesModel()
         {
             Category = g.First().ToModel <PaymentCategoryModel>(),
             Usages   = g.Count()
         });
         return(usages.OrderByDescending(x => x.Usages).Take(query.MaxResults).ToList());
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't get mostly used payments.", ex);
     }
 }
Ejemplo n.º 3
0
 public IList<PaymentCategoryUsagesModel> GetMostlyUsedPayments(MostlyUsedPaymentsQuery query)
 {
     EnsureIsValid(query);
     EnsureIsSecure<MostlyUsedPaymentsQuery, UserQueryValidator>(query);
     try
     {
         //TODO: of course it will be great to group in database first
         var cardIds = _deps.UserCards.Select(DbQuery.For<UserCard>().FilterBy(x => x.Owner.Id == query.UserId), x => x.Id);
         var cardPayments = _deps.CardPayments.Query(query.ToCardPaymentQuery(cardIds));
         var groups = cardPayments.GroupBy(x => x.Category);
         var usages = groups.Select(g => new PaymentCategoryUsagesModel()
         {
             Category = g.First().ToModel<PaymentCategoryModel>(),
             Usages = g.Count()
         });
         return usages.OrderByDescending(x => x.Usages).Take(query.MaxResults).ToList();
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't get mostly used payments.", ex);
     }
 }
Ejemplo n.º 4
0
        public IHttpActionResult StatsMostlyUsed([FromUri] MostlyUsedPaymentsQuery query)
        {
            var stats = _paymentStatisticsService.GetMostlyUsedPayments(query);

            return(Ok(stats));
        }