コード例 #1
0
        public void BatchDeleteTest()
        {
            Product v1 = new Product();
            Product v2 = new Product();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v1.ID        = 75;
                v1.Name      = "nXNX";
                v1.CompanyId = AddCompany();
                v2.Name      = "WOAO2";
                v2.CompanyId = v1.CompanyId;
                context.Set <Product>().Add(v1);
                context.Set <Product>().Add(v2);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() });

            Assert.IsInstanceOfType(rv.Model, typeof(ProductBatchVM));

            ProductBatchVM vm = rv.Model as ProductBatchVM;

            vm.Ids = new string[] { v1.ID.ToString(), v2.ID.ToString() };
            _controller.DoBatchDelete(vm, null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <Product>().Count(), 2);
            }
        }
コード例 #2
0
 public ActionResult DoBatchDelete(ProductBatchVM vm, IFormCollection nouse)
 {
     if (!ModelState.IsValid || !vm.DoBatchDelete())
     {
         return(PartialView("BatchDelete", vm));
     }
     else
     {
         return(FFResult().CloseDialog().RefreshGrid().Alert("操作成功,共有" + vm.Ids.Length + "条数据被删除"));
     }
 }