Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="page"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public PaginatedList <ExpenseGetModel> GetAll(int page, DateTime?from = null, DateTime?to = null, Models.Type?type = null)
        {
            IQueryable <Expense> result = context
                                          .Expenses
                                          .OrderBy(e => e.Id)
                                          .Include(x => x.Comments);
            PaginatedList <ExpenseGetModel> paginatedResult = new PaginatedList <ExpenseGetModel>();

            paginatedResult.CurrentPage = page;

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

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

            return(paginatedResult);
        }
Exemplo n.º 2
0
        public IEnumerable <ExpenseGetModel> GetAll(int page, DateTime?from = null, DateTime?to = null, ExpenseType?type = null)
        {
            DateTime             dateTimeFrom = new DateTime();
            DateTime             dateTimeTo   = new DateTime();
            IQueryable <Expense> result       = context.Expenses.OrderBy(f => f.Id).Include(f => f.Comments);

            //      PaginatedList<ExpenseGetModel> paginatedResult = new PaginatedList<ExpenseGetModel>();
            //      paginatedResult.CurrentPage = page;

            if (from != null && from != dateTimeFrom)
            {
                result = result.Where(f => f.Date >= from);
            }
            if (to != null && to != dateTimeTo)
            {
                result = result.Where(f => f.Date <= to);
            }
            if (type != ExpenseType.none)
            {
                result = result.Where(f => f.ExpenseType == type);
            }
            //       paginatedResult.NumberOfPages = (result.Count() - 1) / PaginatedList<ExpenseGetModel>.EntriesPerPage + 1;
            //       result = result
            //          .Skip((page - 1) * PaginatedList<ExpenseGetModel>.EntriesPerPage)
            //          .Take(PaginatedList<ExpenseGetModel>.EntriesPerPage);
            //       paginatedResult.Entries = result.Select(f => ExpenseGetModel.FromExpense(f)).ToList();
            IEnumerable <ExpenseGetModel> resultGetModel = result.Select(f => ExpenseGetModel.FromExpense(f)).ToList();

            return(resultGetModel);
        }
Exemplo n.º 3
0
        public IEnumerable <ExpenseGetModel> GetAll(DateTime?from = null, DateTime?to = null, ExpenseType?type = null)
        {
            IQueryable <Expense> result = context.Expenses.Include(f => f.Comments);

            if (from == null && to == null && type == null)
            {
                return(result.Select(f => ExpenseGetModel.FromExpense(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.ExpenseType == type);
            }
            return(result.Select(f => ExpenseGetModel.FromExpense(f)));;
        }
Exemplo n.º 4
0
        public IEnumerable <ExpenseGetModel> GetAll(DateTime?from = null, DateTime?to = null, TypeExpenses?type = null)
        {
            IQueryable <Expense> result = context.
                                          Expenses.
                                          Include(c => c.Comments);

            if (from == null && to == null && type == null)
            {
                return(result.Select(e => ExpenseGetModel.FromExpense(e)));
            }
            if (from != null)
            {
                result = result.Where(e => e.Date >= from);
            }
            if (to != null)
            {
                result = result.Where(e => e.Date <= to);
            }
            if (type != null)
            {
                result = result.Where(e => e.Type.Equals(type));
            }
            return(result.Select(e => ExpenseGetModel.FromExpense(e)));
        }