public ActionResult Tags(Int32?tagId, int?page, int?sort)
        {
            if (tagId == null ||
                !tagId.HasValue)
            {
                return(RedirectToAction(
                           WebUi.ViewModels.NavigationKeys.SecurityBadInputAction,
                           WebUi.ViewModels.NavigationKeys.SecurityController));
            }

            if (sort == null || !sort.HasValue)
            {
                sort = 1;
            }

            string     listTitle = UiResources.UiTexts.related_tags;
            ProductTag tag       = DomainModel.Repository.Sql.Tags.GetById(
                tagId.Value,
                WebUi.Models.AppCulture.CurrentCulture.Id);

            if (tag != null)
            {
                listTitle += " - " + tag.Name;
            }

            WebUi.ViewModels.PagingInfo pagingInf = new ViewModels.PagingInfo();
            int startRow = (page.Value - 1) * pagingInf.ItemsPerPage + 1;

            GeneralDatabaseList list =
                DomainModel.Repository.Sql.Products.GetByTagId(
                    WebUi.Models.AppCulture.CurrentCulture.Id,
                    tagId.Value,
                    startRow,
                    startRow + pagingInf.ItemsPerPage - 1,
                    sort.Value);

            pagingInf.CurrentSortOption = sort.Value;
            pagingInf.CurrentPage       = page.Value;
            pagingInf.TotalItems        = list.TotalCount;
            pagingInf.listTitle         = listTitle;

            ViewData[ViewModels.ViewDataKeys.ListPagingDetails] = pagingInf;

            return(View("List", list.List));
        }
Exemplo n.º 2
0
        //public IActionResult Index()
        //{
        //  var drzave = ctx.Drzava
        //                  .AsNoTracking()
        //                  .OrderBy(d => d.NazDrzave)
        //                  .ToList();
        //  return View("IndexSimple", drzave);
        //}


        public IActionResult Index(int page = 1, int sort = 1, bool ascending = true)
        {
            int pagesize = appData.PageSize;

            var query = ctx.Posao
                        .AsNoTracking();


            int count = query.Count();

            if (count == 0)
            {
                logger.LogInformation("Ne postoji nijedna država");
                TempData[Constants.Message]       = "Ne postoji niti jedna država.";
                TempData[Constants.ErrorOccurred] = false;
                return(RedirectToAction(nameof(Create)));
            }

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

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

            System.Linq.Expressions.Expression <Func <Posao, object> > orderSelector = null;
            switch (sort)
            {
            case 1:
                orderSelector = d => d.Id;
                break;

            case 2:
                orderSelector = d => d.UslugaId;
                break;

            case 3:
                orderSelector = d => d.Cijena;
                break;

            case 4:
                orderSelector = d => d.Troskovi;
                break;
            }
            if (orderSelector != null)
            {
                query = ascending ?
                        query.OrderBy(orderSelector) :
                        query.OrderByDescending(orderSelector);
            }
            var poslovi = query.Select(p => new PosaoViewModel
            {
                Id          = p.Id,
                Vrijeme     = p.Vrijeme,
                UslugaNaziv = p.UslugaNavigation.Naziv,
                MjestoNaziv = p.MjestoNavigation.Naziv,
                Cijena      = p.Cijena,
                Troskovi    = p.Troskovi
            })
                          .Skip((page - 1) * pagesize)
                          .Take(pagesize)
                          .ToList();
            var model = new PosloviViewModel
            {
                Poslovi    = poslovi,
                PagingInfo = pagingInfo
            };

            return(View(model));
        }
        public ActionResult List(string category, string subcategory, int?page, int?sort)
        {
            if (!DomainModel.Security.InputController.IsValid(category) ||
                !DomainModel.Security.InputController.IsValid(subcategory))
            {
                return(RedirectToAction(
                           WebUi.ViewModels.NavigationKeys.SecurityBadInputAction,
                           WebUi.ViewModels.NavigationKeys.SecurityController));
            }

            if (page == null)
            {
                page = 1;
            }
            if (sort == null)
            {
                sort = 1;
            }

            CategoryParent parent =
                DomainModel.Repository.Memory.Categories.Instance.Items
                [Models.AppCulture.CurrentCulture.CultureId];

            int?     categoryId = null;
            int?     parentId   = null;
            string   listTitle  = string.Empty;
            Category cat        = null;

            if (!string.IsNullOrWhiteSpace(category))
            {
                cat = parent[category];

                if (cat != null)
                {
                    parentId  = cat.CategoryId;
                    listTitle = cat.CategoryName;
                }
            }

            if (!string.IsNullOrWhiteSpace(subcategory) && cat != null)
            {
                cat = cat.SubCategories[subcategory];

                if (cat != null)
                {
                    categoryId = cat.CategoryId;

                    if (!string.IsNullOrWhiteSpace(listTitle))
                    {
                        listTitle += " - ";
                    }
                    listTitle += cat.CategoryName;
                }
            }

            WebUi.ViewModels.PagingInfo pagingInf = new ViewModels.PagingInfo();
            int startRow = (page.Value - 1) * pagingInf.ItemsPerPage + 1;

            GeneralDatabaseList list;

            if (string.IsNullOrEmpty(category) &&
                string.IsNullOrEmpty(subcategory))
            {
                list = DomainModel.Repository.Sql.Products.GetAll(
                    WebUi.Models.AppCulture.CurrentCulture.CultureId,
                    startRow,
                    startRow + pagingInf.ItemsPerPage - 1,
                    sort.Value);

                string sortName = UiResources.UiTexts.unsorted;

                if (DomainModel.Repository.Memory.ProductList.Instance.SortOptions.Keys.Contains(sort.Value))
                {
                    sortName = WebUi.Models.DynamicResources.GetText(
                        DomainModel.Repository.Memory.ProductList.Instance.SortOptions[sort.Value]);
                }

                string controller = ControllerContext.RouteData.Values["controller"].ToString();
                string section    = WebUi.Models.DynamicResources.GetText(controller.ToLower());

                listTitle = string.Format(
                    "{0} {1} ({2})",
                    UiResources.UiTexts.softwares,
                    section,
                    sortName);
            }
            else
            {
                list = DomainModel.Repository.Sql.Products.GetByCategory(
                    WebUi.Models.AppCulture.CurrentCulture.CultureId,
                    categoryId,
                    parentId,
                    startRow,
                    startRow + pagingInf.ItemsPerPage - 1,
                    sort.Value);
            }
            pagingInf.CurrentSortOption = sort.Value;
            pagingInf.CurrentPage       = page.Value;
            pagingInf.TotalItems        = list.TotalCount;
            pagingInf.listTitle         = listTitle;

            ViewData[ViewModels.ViewDataKeys.ListPagingDetails] = pagingInf;

            return(View("List", list.List));
        }
        public ActionResult List(string category, string subcategory, int?page, int?sort)
        {
            if (!DomainModel.Security.InputController.IsValid(category) ||
                !DomainModel.Security.InputController.IsValid(subcategory))
            {
                return(RedirectToAction(
                           WebUi.ViewModels.NavigationKeys.SecurityBadInputAction,
                           WebUi.ViewModels.NavigationKeys.SecurityController));
            }

            if (page == null)
            {
                page = 1;
            }
            if (sort == null)
            {
                sort = 1;
            }

            CategoryParent parent =
                DomainModel.Repository.Memory.Categories.Instance.Items
                [Models.AppCulture.CurrentCulture.CultureId];

            int?     categoryId = null;
            int?     parentId   = null;
            string   listTitle  = string.Empty;
            Category cat        = null;

            if (!string.IsNullOrWhiteSpace(category))
            {
                cat = parent[category];

                if (cat != null)
                {
                    parentId  = cat.CategoryId;
                    listTitle = cat.CategoryName;
                }
            }

            if (!string.IsNullOrWhiteSpace(subcategory) && cat != null)
            {
                cat = cat.SubCategories[subcategory];

                if (cat != null)
                {
                    categoryId = cat.CategoryId;

                    if (!string.IsNullOrWhiteSpace(listTitle))
                    {
                        listTitle += " - ";
                    }
                    listTitle += cat.CategoryName;
                }
            }

            WebUi.ViewModels.PagingInfo pagingInf = new ViewModels.PagingInfo();
            int startRow = (page.Value - 1) * pagingInf.ItemsPerPage + 1;

            GeneralDatabaseList list =
                DomainModel.Repository.Sql.Products.GetByCategory(
                    WebUi.Models.AppCulture.CurrentCulture.CultureId,
                    categoryId,
                    parentId,
                    startRow,
                    startRow + pagingInf.ItemsPerPage - 1,
                    sort.Value);

            pagingInf.CurrentSortOption = sort.Value;
            pagingInf.CurrentPage       = page.Value;
            pagingInf.TotalItems        = list.TotalCount;
            pagingInf.listTitle         = listTitle;

            ViewData[ViewModels.ViewDataKeys.ListPagingDetails] = pagingInf;

            return(View(list.List));
        }