public void BatchDeleteTest() { VOS_User v1 = new VOS_User(); VOS_User v2 = new VOS_User(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.ITCode = "lAoh1Z"; v1.Password = "******"; v1.Name = "fhOE1"; v2.ITCode = "QUFpT7"; v2.Password = "******"; v2.Name = "U4OiX"; context.Set <VOS_User>().Add(v1); context.Set <VOS_User>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv.Model, typeof(VOS_UserBatchVM)); VOS_UserBatchVM vm = rv.Model as VOS_UserBatchVM; 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 <VOS_User>().Count(), 0); } }
public ActionResult DoBatchDelete(VOS_UserBatchVM vm, IFormCollection nouse) { if (!ModelState.IsValid || !vm.DoBatchDelete()) { return(PartialView("BatchDelete", vm)); } else { return(FFResult().CloseDialog().RefreshGrid().Alert(WalkingTec.Mvvm.Core.Program._localizer?["OprationSuccess"])); } }
public ActionResult DoBatchEdit(VOS_UserBatchVM vm, IFormCollection nouse) { using (var transaction = DC.BeginTransaction()) { try { var UserList = DC.Set <VOS_User>().Where(x => vm.Ids.Contains(x.ID.ToString())).ToList(); foreach (var item in UserList) { item.Password = Utils.GetMD5String(GetAppointValue(vm.FC, "LinkedVM.Password").ToString()); DC.Set <VOS_User>().Update(item); } DC.SaveChanges(); transaction.Commit(); return(FFResult().CloseDialog().Alert("已修改")); } catch (Exception) { transaction.Rollback(); return(FFResult().CloseDialog().RefreshGridRow(vm.Ids[0]).Alert("修改密码失败")); } } }