public async Task <ActionResult> Edit(string id, SysController collection) { if (!ModelState.IsValid) { Edit(id); return(View(collection)); } if (!string.IsNullOrEmpty(id)) { //清除原有数据 _sysControllerSysActionService.Delete(a => a.SysControllerId.Equals(id) && !collection.SysActionsId.Contains(a.SysActionId)); } _sysControllerService.Save(id, collection); if (collection.SysActionsId != null) { foreach ( var actionid in collection.SysActionsId.Where( actionid => !_sysControllerSysActionService.GetAll() .Where(b => b.SysControllerId.Equals(id)) .Select(b => b.SysActionId) .Contains(actionid))) { _sysControllerSysActionService.Save(null, new SysControllerSysAction { SysControllerId = collection.Id, SysActionId = actionid }); } } await _unitOfWork.CommitAsync(); return(new EditSuccessResult(id)); }
public ActionResult Edit(Guid?id, SysController collection) { if (!ModelState.IsValid) { Edit(id); return(View(collection)); } if (id.HasValue) { //清除原有数据 _sysControllerSysActionService.Delete(a => a.SysControllerId.Equals(id.Value) && !collection.SysActionsId.Contains(a.SysActionId)); } _sysControllerService.Save(id, collection); if (collection.SysActionsId != null) { foreach ( var actionid in collection.SysActionsId.Where( actionid => !_sysControllerSysActionService.GetAll() .Where(b => b.SysControllerId.Equals(id.Value)) .Select(b => b.SysActionId) .Contains(actionid))) { _sysControllerSysActionService.Save(null, new SysControllerSysAction { SysControllerId = collection.Id, SysActionId = actionid }); } } _unitOfWork.Commit(); return(RedirectToAction("Index")); }