public ActionResult DoBatchDelete(WxProductBatchVM vm, IFormCollection nouse) { if (!ModelState.IsValid || !vm.DoBatchDelete()) { return(PartialView("BatchDelete", vm)); } else { return(FFResult().CloseDialog().RefreshGrid().Alert("操作成功,共有" + vm.Ids.Length + "条数据被删除")); } }
public void BatchDeleteTest() { WxProduct v1 = new WxProduct(); WxProduct v2 = new WxProduct(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.ID = 41; v1.Name = "2QFM62s3"; v1.VenueId = AddVenue(); v1.Price = 33; v1.AvailableStock = 24; v1.Description = "XhKg7NCQK"; v2.Name = "pmOS9wR"; v2.VenueId = v1.VenueId; v2.Price = 83; v2.AvailableStock = 94; v2.Description = "RG1wBqk"; context.Set <WxProduct>().Add(v1); context.Set <WxProduct>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv.Model, typeof(WxProductBatchVM)); WxProductBatchVM vm = rv.Model as WxProductBatchVM; 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 <WxProduct>().Count(), 2); } }