Exemplo n.º 1
0
        public PaginatedList <ObiectivGetModel> GetAll(DateTime?from, DateTime?to, int page)
        {
            IQueryable <Obiectiv> result = context
                                           .Obiective
                                           .OrderBy(f => f.Id)
                                           .Include(o => o.Comments);

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

            paginatedResult.CurrentPage = page;

            if (from != null)
            {
                result = result.Where(o => o.Deadline >= from);
            }
            if (to != null)
            {
                result = result.Where(o => o.Deadline <= to);
            }

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

            return(paginatedResult);
        }
Exemplo n.º 2
0
        public IEnumerable <ObiectivGetModel> GetAll(DateTime?from, DateTime?to)
        {
            IQueryable <Obiectiv> result = context
                                           .Obiective
                                           .Include(o => o.Comments);

            if (from == null && to == null)
            {
                return(result.Select(o => ObiectivGetModel.FromObiectiv(o)));
            }

            if (from != null)
            {
                result = result.Where(o => o.Deadline >= from);
            }
            if (to != null)
            {
                result = result.Where(o => o.Deadline <= to);
            }

            return(result.Select(o => ObiectivGetModel.FromObiectiv(o)));
        }