Пример #1
0
        /// <summary>
        /// Prikazuje početnu stranicu
        /// </summary>
        /// <param name="page">Broj stranice</param>
        /// <param name="sort">Atribut po kojemu se sortira</param>
        /// <param name="ascending">Oznaka je li sortiranje uzlazno ili silazno</param>
        /// <returns></returns>
        public async Task <IActionResult> Index(int page = 1, int sort = 1, bool ascending = true)
        {
            int pagesize = appData.PageSize;

            var query = ctx.Dokuments.AsNoTracking();
            int count = await query.CountAsync();

            var pagingInfo = new PagingInfo
            {
                CurrentPage  = page,
                Sort         = sort,
                Ascending    = ascending,
                ItemsPerPage = pagesize,
                TotalItems   = count
            };

            if (page < 1 || page > pagingInfo.TotalPages)
            {
                return(RedirectToAction(nameof(Index), new { page = 1, sort = sort, ascending = ascending }));
            }

            query = query.ApplySort(sort, ascending);

            var dok = await query

                      .Select(m => new DokumentViewModel

            {
                DokumentId   = m.DokumentId,
                Naslov       = m.Naslov,
                Vrsta        = m.Vrsta,
                Blob         = m.Blob,
                NazivPonude  = m.PonDokumentis.Where(k => k.DokumentId == m.DokumentId).First().Ponuda.Naslov,
                DatumPredaje = m.DatumPredaje
            })
                      .Skip((page - 1) * pagesize)
                      .Take(pagesize)
                      .ToListAsync();

            var model = new DokumentiViewModel
            {
                Dokumenti  = dok,
                PagingInfo = pagingInfo
            };

            return(View(model));
        }
 public DokumentiPage()
 {
     InitializeComponent();
     BindingContext = model = new DokumentiViewModel();
 }
Пример #3
0
        public IActionResult Index(string filter, int page = 1, int sort = 1, bool ascending = true)
        {
            int pagesize = appData.PageSize;

            var query = ctx.ViewDokumentInfo.AsNoTracking()
                        .FromSql(Constants.SqlViewDokumenti);

            DokumentFilter df = new DokumentFilter();

            if (!string.IsNullOrWhiteSpace(filter))
            {
                df = DokumentFilter.FromString(filter);
                if (!df.IsEmpty())
                {
                    if (df.IdPartnera.HasValue)
                    {
                        df.NazPartnera = ctx.vw_Partner
                                         .Where(p => p.IdPartnera == df.IdPartnera)
                                         .Select(vp => vp.Naziv)
                                         .FirstOrDefault();
                    }
                    query = df.Apply(query);
                }
            }

            int count = query.Count();

            var pagingInfo = new PagingInfo
            {
                CurrentPage  = page,
                Sort         = sort,
                Ascending    = ascending,
                ItemsPerPage = pagesize,
                TotalItems   = count
            };

            if (page > pagingInfo.TotalPages)
            {
                return(RedirectToAction(nameof(Index), new { page = pagingInfo.TotalPages, sort = sort, ascending = ascending }));
            }

            query = ApplySort(sort, ascending, query);

            var dokumenti = query
                            .Skip((page - 1) * pagesize)
                            .Take(pagesize)
                            .ToList();

            for (int i = 0; i < dokumenti.Count; i++)
            {
                dokumenti[i].Position = (page - 1) * pagesize + i;
            }
            var model = new DokumentiViewModel
            {
                Dokumenti  = dokumenti,
                PagingInfo = pagingInfo,
                Filter     = df
            };

            return(View(model));
        }