public int UpdatePwd(string Id, string Pwd) { using (var uow = new EFUnitOfWork <UserContext>(CurrentDbContext)) { //设置级联删除以后,取对象必须先InClude var entity = GetByKey(uow.DbContext, Id); entity.Password = Pwd; uow.RegisterModified(entity, true); return(uow.Commit()); } }
/// <summary> /// 更新记录 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override int Update(CompanyEntity entity) { using (var uow = new EFUnitOfWork <CompanyContext>(CurrentDbContext)) { //更新主表 uow.RegisterModified(entity, true); //得到现在所有的department var departments = uow.DbContext.Department .Where(it => it.CompanyId.Equals(entity.Id)); //读取出不在当前departments集合内的department,这部分作为删除对象 var departmentDeleted = departments .Where(it => !entity.Departments.Any(t => t.Id.Equals(it.Id))); //循环 foreach (var department in departmentDeleted) { //将这部分department作为删除 uow.RegisterDeleted(department); } //找出当前不在数据库内的departments,作为新增对象 var dptAdd = entity.Departments .Where(it => !departments.Any(t => t.Id.Equals(it.Id))); //循环 foreach (var button in dptAdd) { //将这部分department作为新增 uow.RegisterNew(button); } //得到更新部分 var departmentModify = entity.Departments .Where(it => departments.Any(t => t.Id.Equals(it.Id))); //循环 foreach (var department in departmentModify) { //将这部分department作为新增 uow.RegisterModified(department); } return(uow.Commit()); } }
/// <summary> /// 更新记录 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override int Update(DictionaryEntity entity) { using (var uow = new EFUnitOfWork <DictionaryContext>(CurrentDbContext)) { //更新主表 uow.RegisterModified(entity, true); //得到现在所有的button,column,form var Items = uow.DbContext.Detail .Where(it => it.ItemId.Equals(entity.Id)); var ItemsDeleted = Items .Where(it => !entity.DetailEntities.Any(t => t.Id.Equals(it.Id))); foreach (var item in ItemsDeleted) { uow.RegisterDeleted(item); } var ItemsAdd = entity.DetailEntities .Where(it => !Items.Any(t => t.Id.Equals(it.Id))); foreach (var item in ItemsAdd) { uow.RegisterNew(item); } var ItemsModify = entity.DetailEntities .Where(it => Items.Any(t => t.Id.Equals(it.Id))); foreach (var item in ItemsModify) { uow.RegisterModified(item); } return(uow.Commit()); } }
/// <summary> /// 更新记录 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override int Update(CustomerEntity entity) { using (var uow = new EFUnitOfWork <CustomerContext>(CurrentDbContext)) { //更新主表 uow.RegisterModified(entity, true); //得到现在所有的button,column,form var Owner = uow.DbContext.Owner .Where(it => it.CusId.Equals(entity.Id)); var OwnerDeleted = Owner .Where(it => !entity.OwnerEntities.Any(t => t.Id.Equals(it.Id))); foreach (var item in OwnerDeleted) { uow.RegisterDeleted(item); } var OwnerAdd = entity.OwnerEntities .Where(it => !Owner.Any(t => t.Id.Equals(it.Id))); foreach (var item in OwnerAdd) { uow.RegisterNew(item); } var OwnerModify = entity.OwnerEntities .Where(it => Owner.Any(t => t.Id.Equals(it.Id))); foreach (var item in OwnerModify) { uow.RegisterModified(item); } return(uow.Commit()); } }
/// <summary> /// 更新记录 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override int Update(WarehouseEntity entity) { using (var uow = new EFUnitOfWork <WarehouseContext>(CurrentDbContext)) { //更新主表 uow.RegisterModified(entity, true); //得到现在所有的button,column,form var Pos = uow.DbContext.Position .Where(it => it.WhCode.Equals(entity.Id)); var PosDeleted = Pos .Where(it => !entity.PositionEntities.Any(t => t.Id.Equals(it.Id))); foreach (var item in PosDeleted) { uow.RegisterDeleted(item); } var PosAdd = entity.PositionEntities .Where(it => !Pos.Any(t => t.Id.Equals(it.Id))); foreach (var item in PosAdd) { uow.RegisterNew(item); } var PosModify = entity.PositionEntities .Where(it => Pos.Any(t => t.Id.Equals(it.Id))); foreach (var item in PosModify) { uow.RegisterModified(item); } return(uow.Commit()); } }
/// <summary> /// 更新记录 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override int Update(ModuleEntity entity) { using (var uow = new EFUnitOfWork <ModuleContext>(CurrentDbContext)) { //更新主表 uow.RegisterModified(entity, true); //得到现在所有的button,column,form var buttons = uow.DbContext.Button .Where(it => it.ModuleId.Equals(entity.Id)); var columns = uow.DbContext.Column .Where(it => it.ModuleId.Equals(entity.Id)); var forms = uow.DbContext.Form .Where(it => it.ModuleId.Equals(entity.Id)); //读取出不在当前buttons/columns/forms集合内的button/column/form,这部分作为删除对象 var btnDeleted = buttons .Where(it => !entity.ButtonEntities.Any(t => t.Id.Equals(it.Id))); var columnDeleted = columns .Where(it => !entity.ColumnEntities.Any(t => t.Id.Equals(it.Id))); var formDeleted = forms .Where(it => !entity.FormEntities.Any(t => t.Id.Equals(it.Id))); ////循环 foreach (var button in btnDeleted) { //将这部分button作为删除 uow.RegisterDeleted(button); } foreach (var column in columnDeleted) { //将这部分column作为删除 uow.RegisterDeleted(column); } foreach (var form in formDeleted) { //将这部分form作为删除 uow.RegisterDeleted(form); } //找出当前不在数据库内的buttons/columns/forms,作为新增对象 var btnAdd = entity.ButtonEntities .Where(it => !buttons.Any(t => t.Id.Equals(it.Id))); var columnAdd = entity.ColumnEntities .Where(it => !columns.Any(t => t.Id.Equals(it.Id))); var formAdd = entity.FormEntities .Where(it => !forms.Any(t => t.Id.Equals(it.Id))); //循环 foreach (var button in btnAdd) { //将这部分button作为新增 uow.RegisterNew(button); } foreach (var column in columnAdd) { //将这部分column作为新增 uow.RegisterNew(column); } foreach (var form in formAdd) { //将这部分form作为新增 uow.RegisterNew(form); } //得到更新部分 var btnModify = entity.ButtonEntities .Where(it => buttons.Any(t => t.Id.Equals(it.Id))); var columnModify = entity.ColumnEntities .Where(it => columns.Any(t => t.Id.Equals(it.Id))); var formModify = entity.FormEntities .Where(it => forms.Any(t => t.Id.Equals(it.Id))); //循环 foreach (var button in btnModify) { //将这部分button作为新增 uow.RegisterModified(button); } foreach (var column in columnModify) { //将这部分column作为新增 uow.RegisterModified(column); } foreach (var form in formModify) { //将这部分form作为新增 uow.RegisterModified(form); } return(uow.Commit()); } }
/// <summary> /// 更新记录 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override int Update(RoleEntity entity) { using (var uow = new EFUnitOfWork <RoleContext>(CurrentDbContext)) { //更新主表 uow.RegisterModified(entity, true); //得到现在所有的button,column,Moduls var buttons = uow.DbContext.RoleButton .Where(it => it.RoleId.Equals(entity.Id)); var columns = uow.DbContext.RoleColumn .Where(it => it.RoleId.Equals(entity.Id)); var moduls = uow.DbContext.RoleModule .Where(it => it.RoleId.Equals(entity.Id)); //读取出不在当前buttons/columns/Moduls集合内的button/column/Moduls,这部分作为删除对象 var btnDeleted = buttons .Where(it => !entity.Buttons.Any(t => t.Id.Equals(it.Id))); var columnDeleted = columns .Where(it => !entity.Columns.Any(t => t.Id.Equals(it.Id))); var modulDeleted = moduls .Where(it => !entity.Modules.Any(t => t.Id.Equals(it.Id))); ////循环 foreach (var button in btnDeleted) { //将这部分button作为删除 uow.RegisterDeleted(button); } foreach (var column in columnDeleted) { //将这部分column作为删除 uow.RegisterDeleted(column); } foreach (var modul in modulDeleted) { //将这部分modul作为删除 uow.RegisterDeleted(modul); } //找出当前不在数据库内的buttons/columns/moduls,作为新增对象 var btnAdd = entity.Buttons .Where(it => !buttons.Any(t => t.Id.Equals(it.Id))); var columnAdd = entity.Columns .Where(it => !columns.Any(t => t.Id.Equals(it.Id))); var modulAdd = entity.Modules .Where(it => !moduls.Any(t => t.Id.Equals(it.Id))); //循环 foreach (var button in btnAdd) { //将这部分button作为新增 uow.RegisterNew(button); } foreach (var column in columnAdd) { //将这部分column作为新增 uow.RegisterNew(column); } foreach (var modul in modulAdd) { //将这部分modul作为新增 uow.RegisterNew(modul); } //得到更新部分 var btnModify = entity.Buttons .Where(it => buttons.Any(t => t.Id.Equals(it.Id))); var columnModify = entity.Columns .Where(it => columns.Any(t => t.Id.Equals(it.Id))); var formModify = entity.Modules .Where(it => moduls.Any(t => t.Id.Equals(it.Id))); //循环 foreach (var button in btnModify) { //将这部分button作为新增 uow.RegisterModified(button); } foreach (var column in columnModify) { //将这部分column作为新增 uow.RegisterModified(column); } foreach (var modul in formModify) { //将这部分modul作为新增 uow.RegisterModified(modul); } return(uow.Commit()); } }