Exemplo n.º 1
0
        /// <summary>
        /// This is the logic which will Display All Landlords and will separate them in pages and each page will show 20 items.
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public LandlordsViewModel GetAllLandlords(int?page)
        {
            LandlordsViewModel       model         = new LandlordsViewModel();
            List <LandlordViewModel> landlordsList = new List <LandlordViewModel>();

            var lords = this.Context.Landlords.OrderBy(m => m.Id).ToArray();

            if (page == null)
            {
                model.Pager = new Pager(lords.Count(), 1, NumberOfItemsInPage);

                foreach (var item in lords.Take(20))
                {
                    LandlordViewModel landlord = Mapper.Map <Landlord, LandlordViewModel>(item);
                    landlordsList.Add(landlord);
                }
                model.Landlords = landlordsList;
            }
            else
            {
                model.Pager = new Pager(lords.Count(), (int)page, NumberOfItemsInPage);

                model.Landlords = Mapper.Instance.Map <IEnumerable <Landlord>, IEnumerable <LandlordViewModel> >(
                    lords.Skip((model.Pager.CurrentPage - 1) * model.Pager.PageSize).Take(model.Pager.PageSize));
            }
            return(model);
        }
Exemplo n.º 2
0
        public ActionResult Landlords(int?page)
        {
            LandlordsViewModel model = this.landlordService.GetAllLandlords(page);

            return(this.View(model));
        }