public override bool DoBatchDelete() { using (var trans = DC.BeginTransaction()) { var userorleids = DC.Set <FrameworkUserGroup>().AsNoTracking().Where(y => DC.Set <FrameworkGroup>().CheckIDs(Ids.ToList(), null).Select(x => x.GroupCode).Contains(y.GroupCode)).Select(x => x.ID); foreach (var item in userorleids) { FrameworkUserGroup f = new FrameworkUserGroup { ID = item }; DC.DeleteEntity(f); } DC.SaveChanges(); base.DoBatchDelete(); if (MSD.IsValid == true) { trans.Commit(); } else { trans.Rollback(); } } return(base.DoBatchDelete()); }
public override async Task DoAddAsync() { using (var trans = DC.BeginTransaction()) { if (SelectedRolesCodes != null) { foreach (var rolecode in SelectedRolesCodes) { FrameworkUserRole r = new FrameworkUserRole { RoleCode = rolecode, UserCode = Entity.ITCode }; DC.AddEntity(r); } } if (SelectedGroupCodes != null) { foreach (var groupcode in SelectedGroupCodes) { FrameworkUserGroup g = new FrameworkUserGroup { GroupCode = groupcode, UserCode = Entity.ITCode }; DC.AddEntity(g); } } Entity.IsValid = true; Entity.Password = Utils.GetMD5String(Entity.Password); await base.DoAddAsync(); if (MSD.IsValid) { trans.Commit(); } else { trans.Rollback(); } } }
public override async Task DoEditAsync(bool updateAllFields = false) { if (FC.ContainsKey("Entity.ITCode")) { FC.Remove("Entity.ITCode"); } using (var trans = DC.BeginTransaction()) { if (SelectedRolesCodes != null) { List <Guid> todelete = new List <Guid>(); todelete.AddRange(DC.Set <FrameworkUserRole>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID)); foreach (var item in todelete) { DC.DeleteEntity(new FrameworkUserRole { ID = item }); } } if (SelectedGroupCodes != null) { List <Guid> todelete = new List <Guid>(); todelete.AddRange(DC.Set <FrameworkUserGroup>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID)); foreach (var item in todelete) { DC.DeleteEntity(new FrameworkUserGroup { ID = item }); } } if (SelectedRolesCodes != null) { foreach (var rolecode in SelectedRolesCodes) { FrameworkUserRole r = new FrameworkUserRole { RoleCode = rolecode, UserCode = Entity.ITCode }; DC.AddEntity(r); } } if (SelectedGroupCodes != null) { foreach (var groupcode in SelectedGroupCodes) { FrameworkUserGroup g = new FrameworkUserGroup { GroupCode = groupcode, UserCode = Entity.ITCode }; DC.AddEntity(g); } } await base.DoEditAsync(updateAllFields); if (MSD.IsValid) { trans.Commit(); await Wtm.RemoveUserCache(Entity.ID.ToString()); } else { trans.Rollback(); } } }