Exemplo n.º 1
0
        /// <summary>
        /// Get All Expenses
        /// </summary>
        ///  <remarks>
        /// Sample request:
        ///
        ///     GET /api/expenses?from=2019-05-05 and type=food
        ///
        ///
        /// </remarks>
        /// <param name="page"></param>
        /// <param name="from">Optional, filter by minimum Date</param>
        /// <param name="to">Optiona, filter by maximum Date</param>
        /// <param name="type">Optional, filter by expenses type</param>
        /// <returns>List of Expenses with/without filters</returns>
        public PaginatedList <ExpensesGetModel> GetAllExpenses(int page, DateTime?from, DateTime?to, Models.Type?type)
        {
            IQueryable <Expenses> result = context.Expensess.Include(f => f.Comments);

            PaginatedList <ExpensesGetModel> paginatedResult = new PaginatedList <ExpensesGetModel>();

            paginatedResult.CurrentPage = page;

            if (from != null)
            {
                result = result.Where(f => f.Date >= from);
            }
            if (to != null)
            {
                result = result.Where(f => f.Date <= to);
            }
            if (type != null)
            {
                result = result.Where(f => f.Type.Equals(type));
            }

            paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList <ExpensesGetModel> .EntriesPerPage + 1;
            result = result
                     .Skip((page - 1) * PaginatedList <ExpensesGetModel> .EntriesPerPage)
                     .Take(PaginatedList <ExpensesGetModel> .EntriesPerPage);
            paginatedResult.Entries = result.Select(f => ExpensesGetModel.FromExpenses(f)).ToList();



            return(paginatedResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get All Expenses
        /// </summary>
        ///  <remarks>
        /// Sample request:
        ///
        ///     GET /api/expenses?from=2019-05-05&&type=food
        ///
        ///
        /// </remarks>
        /// <param name="from">Optional, filter by minimum Date</param>
        /// <param name="to">Optiona, filter by maximum Date</param>
        /// <param name="type">Optional, filter by expenses type</param>
        /// <returns>List of Expenses with/without filters</returns>
        public IEnumerable <ExpensesGetModel> GetAll(DateTime?from, DateTime?to, Models.Type?type)
        {
            IQueryable <Expenses> result = context.Expensess.Include(f => f.Comments);

            if ((from == null && to == null) && type == null)
            {
                return(result.Select(f => ExpensesGetModel.FromExpenses(f)));
            }
            if (from != null)
            {
                result = result.Where(f => f.Date >= from);
            }
            if (to != null)
            {
                result = result.Where(f => f.Date <= to);
            }
            if (type != null)
            {
                result = result.Where(f => f.Type.Equals(type));
            }
            return(result.Select(f => ExpensesGetModel.FromExpenses(f)));
        }