From 02ef43c0d13319e38d71c14ebb03fa5b4edfd330 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Fri, 6 Nov 2015 22:56:26 +0800 Subject: [PATCH] Routine Update --- OpenAuth.App/OrgManagerApp.cs | 2 +- OpenAuth.Domain/Interface/IRepository.cs | 3 +++ OpenAuth.Mvc/Views/OrgManager/Index.cshtml | 3 +-- OpenAuth.Repository/BaseRepository.cs | 7 ++++++- OpenAuth.UnitTest/TestOrgApp.cs | 12 ++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/OpenAuth.App/OrgManagerApp.cs b/OpenAuth.App/OrgManagerApp.cs index d46eb9a0..5175d6ac 100644 --- a/OpenAuth.App/OrgManagerApp.cs +++ b/OpenAuth.App/OrgManagerApp.cs @@ -88,7 +88,7 @@ namespace OpenAuth.App public void ModifyOrg(Org org) { - _repository.Update(u =>u.Id == org.Id,org); + _repository.Update(org); } /// diff --git a/OpenAuth.Domain/Interface/IRepository.cs b/OpenAuth.Domain/Interface/IRepository.cs index f0543e58..33f58a07 100644 --- a/OpenAuth.Domain/Interface/IRepository.cs +++ b/OpenAuth.Domain/Interface/IRepository.cs @@ -31,6 +31,9 @@ namespace OpenAuth.Domain.Interface void Add(T entity); + /// + /// 更新一个实体的所有属性 + /// void Update(T entity); void Delete(T entity); diff --git a/OpenAuth.Mvc/Views/OrgManager/Index.cshtml b/OpenAuth.Mvc/Views/OrgManager/Index.cshtml index 878f058c..98a462fd 100644 --- a/OpenAuth.Mvc/Views/OrgManager/Index.cshtml +++ b/OpenAuth.Mvc/Views/OrgManager/Index.cshtml @@ -25,8 +25,7 @@ showToolbar: true, toolbarItem: 'refresh, |, del,edit', toolbarCustom: '添加' + - '', + 'data-toggle="dialog" data-id="dialog-mask" data-mask="true">添加' , columns: [ { name: 'Id', diff --git a/OpenAuth.Repository/BaseRepository.cs b/OpenAuth.Repository/BaseRepository.cs index f444c6e8..f1cf9b91 100644 --- a/OpenAuth.Repository/BaseRepository.cs +++ b/OpenAuth.Repository/BaseRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Data.Entity; using System.Data.Entity.Migrations; using System.Linq; using System.Linq.Expressions; @@ -61,7 +62,10 @@ namespace OpenAuth.Repository public void Update(T entity) { - Context.Set().AddOrUpdate(entity); + var entry = this.Context.Entry(entity); + + entry.State = EntityState.Modified; + Save(); } @@ -73,6 +77,7 @@ namespace OpenAuth.Repository public void Update(Expression> exp, T entity) { + //TODO: 暂时有问题,EntityFramework.Extension的Update必须有new操作 Context.Set().Where(exp).Update(u => entity); } diff --git a/OpenAuth.UnitTest/TestOrgApp.cs b/OpenAuth.UnitTest/TestOrgApp.cs index 277e676d..a0f3284a 100644 --- a/OpenAuth.UnitTest/TestOrgApp.cs +++ b/OpenAuth.UnitTest/TestOrgApp.cs @@ -125,5 +125,17 @@ namespace OpenAuth.UnitTest Console.WriteLine(org.Name); } } + + [TestMethod] + public void TestEdit() + { + var org = new Org + { + Id = 60, + Name = "test" + + }; + _app.ModifyOrg(org); + } } }