// GET: 查看待审核的捐赠物品列表
        // 修改时间: 2019年5月3日 15点06分
        public ActionResult CheckThings(int currentPage = 1)
        {
            //新建视图模型列表
            var res = new List <ThingsListViewModel>();

            using (SSDBEntities db = new SSDBEntities())
            {
                //所有待审核的捐赠物品
                var ts = db.Things.Where(x => x.Status == "正在审核中");
                //1.分页
                int totalThings = ts.Count();                                             //总共条目数目
                ViewBag.totalPages = (int)Math.Ceiling(totalThings / (double)numPerPage); //总共页数
                int start = (currentPage - 1) * numPerPage;                               //开始的条目
                ts = ts.OrderByDescending(x => x.ReleaseTime).Skip(start).Take(numPerPage);
                ViewBag.currentPage = currentPage;
                //给视图模型赋值
                foreach (var t in ts)
                {
                    //新建一个视图模型并赋值
                    var tmp = new ThingsListViewModel();
                    tmp.Thing = t;
                    //添加到列表中
                    res.Add(tmp);
                }
            }
            return(View(res));
        }
        public void Can_Send_Pagination_View_Model()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            ThingsListViewModel result = (ThingsListViewModel)controller.List(null, 2).Model;

            PagingInfo pagingInfo = result.PagingInfo;

            Assert.AreEqual(pagingInfo.CurrentPage, 2);
            Assert.AreEqual(pagingInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagingInfo.TotalItems, 5);
            Assert.AreEqual(pagingInfo.TotalPages, 2);
        }
        public void Can_Paginate()
        {
            Mock <IThingRepository> mock = new Mock <IThingRepository>();

            mock.Setup(m => m.Things).Returns(new List <Thing>
            {
                new Thing {
                    ThingId = 1, Name = "Thing1"
                },
                new Thing {
                    ThingId = 2, Name = "Thing2"
                },
                new Thing {
                    ThingId = 3, Name = "Thing3"
                },
                new Thing {
                    ThingId = 4, Name = "Thing4"
                },
                new Thing {
                    ThingId = 5, Name = "Thing5"
                }
            });
            ThingsController controller = new ThingsController(mock.Object);

            controller.pageSize = 3;

            ThingsListViewModel result = (ThingsListViewModel)controller.List(null, 2).Model;

            List <Thing> things = result.Things.ToList();

            Assert.IsTrue(things.Count == 2);
            Assert.AreEqual(things[0].Name, "Thing4");
            Assert.AreEqual(things[1].Name, "Thing5");
        }
Beispiel #4
0
        public ViewResult List(string category, int page = 1)
        {
            ThingsListViewModel model = new ThingsListViewModel
            {
                Things = repository.Things
                         .Where(p => category == null || p.Category == category)
                         .OrderBy(thing => thing.ThingId)
                         .Skip((page - 1) * pageSize)
                         .Take(pageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = category == null?
                                   repository.Things.Count() :
                                       repository.Things.Where(thing => thing.Category == category).Count()
                },
                CurrentCategory = category
            };

            return(View(model));
        }
        public ViewResult List(string kind, int page = 1)
        {
            ThingsListViewModel model = new ThingsListViewModel
            {
                Things = repository.Things
                         .Where(b => kind == null || b.Kind == kind)
                         .OrderBy(thing => thing.ThingId)
                         .Skip((page - 1) * pageSize)
                         .Take(pageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = kind == null
                         ? repository.Things.Count() :
                                   repository.Things.Where(thing => thing.Kind == kind).Count()
                },
                CurrentKind = kind
            };

            return(View(model));
        }
Beispiel #6
0
        // GET: 显示用户捐赠物品列表
        // 修改时间: 2019年5月1日 13点29分
        public ActionResult MyThingsList(string keywords, string status, int currentPage = 1)
        {
            //获取当前用户id
            int usrId = (int)HttpContext.Session["usrId"];
            //新建视图模型列表
            var res = new List <ThingsListViewModel>();

            using (SSDBEntities db = new SSDBEntities())
            {
                //查找该用户发布的所有捐赠物品
                var ts = db.Things.Where(x => x.DonatorId == usrId);
                //1.按照关键字搜索
                if (keywords != null)
                {
                    ts = ts.Where(x => x.Name.Contains(keywords));
                }
                //2.按照状态筛选
                switch (status)
                {
                case "All":
                    break;

                case "1":
                    ts = ts.Where(x => x.Status == "正在审核中");
                    break;

                case "2":
                    ts = ts.Where(x => x.Status == "审核未通过");
                    break;

                case "3":
                    ts = ts.Where(x => x.Status == "物品闲置中");
                    break;

                case "4":
                    ts = ts.Where(x => x.Status == "已接受捐赠");
                    break;

                case "5":
                    ts = ts.Where(x => x.Status == "捐赠已成功");
                    break;
                }
                //3.分页
                int totalThings = ts.Count();                                             //总共条目数目
                ViewBag.totalPages = (int)Math.Ceiling(totalThings / (double)numPerPage); //总共页数
                int start = (currentPage - 1) * numPerPage;                               //开始的条目
                ts = ts.OrderByDescending(x => x.ReleaseTime).Skip(start).Take(numPerPage);
                ViewBag.searchString = keywords;
                ViewBag.Status       = status;
                ViewBag.currentPage  = currentPage;
                //给视图模型赋值
                foreach (var t in ts)
                {
                    //新建一个视图模型并赋值
                    var tmp = new ThingsListViewModel();
                    tmp.Thing = t;
                    //添加到列表中
                    res.Add(tmp);
                }
            }
            return(View(res));
        }