Routine Update

This commit is contained in:
yubaolee 2015-11-06 22:56:26 +08:00
parent 3170191db6
commit 02ef43c0d1
5 changed files with 23 additions and 4 deletions

View File

@ -88,7 +88,7 @@ namespace OpenAuth.App
public void ModifyOrg(Org org) public void ModifyOrg(Org org)
{ {
_repository.Update(u =>u.Id == org.Id,org); _repository.Update(org);
} }
/// <summary> /// <summary>

View File

@ -31,6 +31,9 @@ namespace OpenAuth.Domain.Interface
void Add(T entity); void Add(T entity);
/// <summary>
/// 更新一个实体的所有属性
/// </summary>
void Update(T entity); void Update(T entity);
void Delete(T entity); void Delete(T entity);

View File

@ -25,8 +25,7 @@
showToolbar: true, showToolbar: true,
toolbarItem: 'refresh, |, del,edit', toolbarItem: 'refresh, |, del,edit',
toolbarCustom: '<a href="/OrgManager/AddOrg" class="btn btn-green" data-icon ="plus" ' + toolbarCustom: '<a href="/OrgManager/AddOrg" class="btn btn-green" data-icon ="plus" ' +
'data-toggle="dialog" data-id="dialog-mask" data-mask="true">添加</a>' + 'data-toggle="dialog" data-id="dialog-mask" data-mask="true">添加</a>' ,
'<button class=" btn-green" onclick="editOrg()" data-icon="pencil" type="button">编辑</button>',
columns: [ columns: [
{ {
name: 'Id', name: 'Id',

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Data.Entity;
using System.Data.Entity.Migrations; using System.Data.Entity.Migrations;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
@ -61,7 +62,10 @@ namespace OpenAuth.Repository
public void Update(T entity) public void Update(T entity)
{ {
Context.Set<T>().AddOrUpdate(entity); var entry = this.Context.Entry(entity);
entry.State = EntityState.Modified;
Save(); Save();
} }
@ -73,6 +77,7 @@ namespace OpenAuth.Repository
public void Update(Expression<Func<T, bool>> exp, T entity) public void Update(Expression<Func<T, bool>> exp, T entity)
{ {
//TODO: 暂时有问题EntityFramework.Extension的Update必须有new操作
Context.Set<T>().Where(exp).Update(u => entity); Context.Set<T>().Where(exp).Update(u => entity);
} }

View File

@ -125,5 +125,17 @@ namespace OpenAuth.UnitTest
Console.WriteLine(org.Name); Console.WriteLine(org.Name);
} }
} }
[TestMethod]
public void TestEdit()
{
var org = new Org
{
Id = 60,
Name = "test"
};
_app.ModifyOrg(org);
}
} }
} }