public InvoicesCollectionResponse Fetch(InvoicesQueryCollectionRequest request)
        {
            base.FixupLimitAndPagingOnRequest(request);

            var totalItemCount     = 0;
            var sortExpression     = RepositoryHelper.ConvertStringToSortExpression(TypedViewType, request.Sort);
            var includedFieldNames = RepositoryHelper.ConvertStringToExcludedIncludedFields(request.Select);
            var predicateBucket    = RepositoryHelper.ConvertStringToRelationPredicateBucket(TypedViewType, request.Filter);

            var typedView = new InvoicesTypedView();

            using (var adapter = DataAccessAdapterFactory.NewDataAccessAdapter())
            {
                OnBeforeFetchInvoicesQueryCollectionRequest(adapter, request, sortExpression, includedFieldNames, predicateBucket,
                                                            request.PageNumber, request.PageSize, request.Limit);
                totalItemCount = (int)adapter.GetDbCount(typedView.GetFieldsInfo(), predicateBucket, null, false);
                adapter.FetchTypedView(typedView.GetFieldsInfo(), typedView, predicateBucket, request.Limit, sortExpression, true, null, request.PageNumber, request.PageSize);
                OnAfterFetchInvoicesQueryCollectionRequest(adapter, request, typedView, sortExpression, includedFieldNames, predicateBucket,
                                                           request.PageNumber, request.PageSize, request.Limit, totalItemCount);
            }

            var dtos       = new InvoicesCollection();
            var enumerator = typedView.GetEnumerator();

            while (enumerator.MoveNext())
            {
                dtos.Add(Map(enumerator.Current, includedFieldNames));
            }

            var response = new InvoicesCollectionResponse(dtos, request.PageNumber,
                                                          request.PageSize, totalItemCount);

            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Use this function when adding new invoice to the list, don't directly modify invoices collection outside of this function
        /// </summary>
        /// <param name="Invoice"></param>
        public void addInvoice(Invoice Invoice)
        {
            InvoicesCollection.Add(Invoice);
            int TotalInvoiceRevenue;

            if (Int32.TryParse(Invoice.TotalCost, out TotalInvoiceRevenue))
            {
                totalRevenue += TotalInvoiceRevenue;
            }
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(totalInvoices)));
        }