diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj index 823ca174..b3133b17 100644 --- a/OpenAuth.App/OpenAuth.App.csproj +++ b/OpenAuth.App/OpenAuth.App.csproj @@ -113,6 +113,7 @@ + diff --git a/OpenAuth.App/WorkflowSchemasManagerApp.cs b/OpenAuth.App/WorkflowSchemasManagerApp.cs new file mode 100644 index 00000000..d040a0dc --- /dev/null +++ b/OpenAuth.App/WorkflowSchemasManagerApp.cs @@ -0,0 +1,37 @@ +using System.Linq; +using Infrastructure; +using OpenAuth.App.ViewModel; +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; + +namespace OpenAuth.App +{ + /// + /// 工作流模板 + /// + public class WorkflowSchemasManagerApp + { + private IWorkflowSchemeRepository _repository; + + public WorkflowSchemasManagerApp(IWorkflowSchemeRepository repository) + { + _repository = repository; + } + public GridData Load(int pageCurrent, int pageSize) + { + var result = new GridData + { + pageCurrent = pageCurrent, + total = _repository.GetCount(), + list = _repository.Find(pageCurrent, pageSize, "Code", null).ToList() + }; + + return result; + } + + public void Del(string code) + { + _repository.Delete(u =>u.Code == code); + } + } +} \ No newline at end of file diff --git a/OpenAuth.Domain/Interface/IWorkflowSchemeRepository.cs b/OpenAuth.Domain/Interface/IWorkflowSchemeRepository.cs new file mode 100644 index 00000000..cc64af3d --- /dev/null +++ b/OpenAuth.Domain/Interface/IWorkflowSchemeRepository.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.Domain.Interface +{ + public interface IWorkflowSchemeRepository : IRepository + { + + + } +} \ No newline at end of file diff --git a/OpenAuth.Domain/OpenAuth.Domain.csproj b/OpenAuth.Domain/OpenAuth.Domain.csproj index 4cfdf300..f3dbdb3f 100644 --- a/OpenAuth.Domain/OpenAuth.Domain.csproj +++ b/OpenAuth.Domain/OpenAuth.Domain.csproj @@ -49,6 +49,7 @@ + @@ -73,6 +74,7 @@ + - diff --git a/OpenAuth.Repository/Models/OpenAuthDBContext.cs b/OpenAuth.Repository/Models/OpenAuthDBContext.cs index aac61961..ae003cc3 100644 --- a/OpenAuth.Repository/Models/OpenAuthDBContext.cs +++ b/OpenAuth.Repository/Models/OpenAuthDBContext.cs @@ -10,6 +10,7 @@ using System.Data.Entity; using OpenAuth.Domain; using OpenAuth.Repository.Models.Mapping; +using OpenAuth.Repository.Workflow.Mapping; namespace OpenAuth.Repository.Models { @@ -42,6 +43,8 @@ namespace OpenAuth.Repository.Models public DbSet ApplyTransitionHistories { get; set; } + public System.Data.Entity.DbSet WorkflowSchemes { get; set; } + protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new CategoryMap()); @@ -57,6 +60,7 @@ namespace OpenAuth.Repository.Models modelBuilder.Configurations.Add(new StockMap()); modelBuilder.Configurations.Add(new UserMap()); modelBuilder.Configurations.Add(new ApplyTransitionHistoryMap()); + modelBuilder.Configurations.Add(new WorkflowSchemeMap()); } } diff --git a/OpenAuth.Repository/OpenAuth.Repository.csproj b/OpenAuth.Repository/OpenAuth.Repository.csproj index 29f5b846..e4e9438d 100644 --- a/OpenAuth.Repository/OpenAuth.Repository.csproj +++ b/OpenAuth.Repository/OpenAuth.Repository.csproj @@ -57,6 +57,7 @@ + @@ -80,6 +81,9 @@ + + + diff --git a/OpenAuth.Repository/Workflow/Mapping/WorkflowSchemeMap.cs b/OpenAuth.Repository/Workflow/Mapping/WorkflowSchemeMap.cs new file mode 100644 index 00000000..49587103 --- /dev/null +++ b/OpenAuth.Repository/Workflow/Mapping/WorkflowSchemeMap.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a CodeSmith Template. +// +// DO NOT MODIFY contents of this file. Changes to this +// file will be lost if the code is regenerated. +// +//------------------------------------------------------------------------------ + +using OpenAuth.Domain; + +namespace OpenAuth.Repository.Workflow.Mapping +{ + public partial class WorkflowSchemeMap + : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration + { + public WorkflowSchemeMap() + { + // table + ToTable("WorkflowScheme", "dbo"); + + // keys + HasKey(t => t.Code); + + // Properties + Property(t => t.Code) + .HasColumnName("Code") + .HasMaxLength(256) + .IsRequired(); + Property(t => t.Scheme) + .HasColumnName("Scheme") + .IsRequired(); + + // Relationships + } + } +} diff --git a/OpenAuth.Repository/Workflow/WorkflowBaseRepository.cs b/OpenAuth.Repository/Workflow/WorkflowBaseRepository.cs new file mode 100644 index 00000000..a4f15f81 --- /dev/null +++ b/OpenAuth.Repository/Workflow/WorkflowBaseRepository.cs @@ -0,0 +1,134 @@ +using System; +using System.Data.Entity; +using System.Data.Entity.Migrations; +using System.Linq; +using System.Linq.Expressions; +using EntityFramework.Extensions; +using Infrastructure; +using OpenAuth.Domain.Interface; + +namespace OpenAuth.Repository.Workflow +{ + public class WorkflowBaseRepository :IRepository where T:class + { + protected WorkflowContext Context = new WorkflowContext(); + + + /// + /// 根据过滤条件,获取记录 + /// + /// The exp. + public IQueryable Find(Expression> exp = null) + { + return Filter(exp); + } + + public bool IsExist(Expression> exp) + { + return Context.Set().Any(exp); + } + + /// + /// 查找单个 + /// + public T FindSingle(Expression> exp) + { + return Context.Set().AsNoTracking().FirstOrDefault(exp); + } + + /// + /// 得到分页记录 + /// + /// The pageindex. + /// The pagesize. + /// 排序,格式如:"Id"/"Id descending" + public IQueryable Find(int pageindex, int pagesize, string orderby = "", Expression> exp = null) + { + if (pageindex < 1) pageindex = 1; + if (string.IsNullOrEmpty(orderby)) + orderby = "Id descending"; + + return Filter(exp).OrderBy(orderby).Skip(pagesize * (pageindex - 1)).Take(pagesize); + } + + /// + /// 根据过滤条件获取记录数 + /// + public int GetCount(Expression> exp = null) + { + return Filter(exp).Count(); + } + + public void Add(T entity) + { + Context.Set().Add(entity); + Save(); + } + + /// + /// 批量添加 + /// + /// The entities. + public void BatchAdd(T[] entities) + { + Context.Set().AddRange(entities); + Save(); + } + + public void Update(T entity) + { + var entry = this.Context.Entry(entity); + //todo:如果状态没有任何更改,会报错 + entry.State = EntityState.Modified; + + Save(); + } + + public void Delete(T entity) + { + Context.Set().Remove(entity); + Save(); + } + + /// + /// 按指定id更新实体,会更新整个实体 + /// + /// The identity exp. + /// The entity. + public void Update(Expression> identityExp, T entity) + { + Context.Set().AddOrUpdate(identityExp, entity); + Save(); + } + + /// + /// 实现按需要只更新部分更新 + /// 如:Update(u =>u.Id==1,u =>new User{Name="ok"}); + /// + /// The where. + /// The entity. + public void Update(Expression> where, Expression> entity) + { + Context.Set().Where(where).Update(entity); + } + + public virtual void Delete(Expression> exp) + { + Context.Set().Where(exp).Delete(); + } + + public void Save() + { + Context.SaveChanges(); + } + + private IQueryable Filter(Expression> exp) + { + var dbSet = Context.Set().AsQueryable(); + if (exp != null) + dbSet = dbSet.Where(exp); + return dbSet; + } + + } +} diff --git a/OpenAuth.Repository/Workflow/WorkflowContext.cs b/OpenAuth.Repository/Workflow/WorkflowContext.cs new file mode 100644 index 00000000..3dcfc01a --- /dev/null +++ b/OpenAuth.Repository/Workflow/WorkflowContext.cs @@ -0,0 +1,41 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a CodeSmith Template. +// +// DO NOT MODIFY contents of this file. Changes to this +// file will be lost if the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System.Data.Entity; +using OpenAuth.Domain; +using OpenAuth.Repository.Models; +using OpenAuth.Repository.Models.Mapping; +using OpenAuth.Repository.Workflow.Mapping; + +namespace OpenAuth.Repository.Workflow +{ + public partial class WorkflowContext: DbContext + { + static WorkflowContext() + { + Database.SetInitializer< OpenAuthDBContext>(null); + } + public WorkflowContext() + :base("Name=WorkFlow") + { } + + public WorkflowContext(string nameOrConnectionString) + : base(nameOrConnectionString) + { } + + + public System.Data.Entity.DbSet WorkflowSchemes { get; set; } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + modelBuilder.Configurations.Add(new WorkflowSchemeMap()); + + } + } +} \ No newline at end of file diff --git a/OpenAuth.Repository/Workflow/WorkflowSchemeRepository.cs b/OpenAuth.Repository/Workflow/WorkflowSchemeRepository.cs new file mode 100644 index 00000000..9dd8ad99 --- /dev/null +++ b/OpenAuth.Repository/Workflow/WorkflowSchemeRepository.cs @@ -0,0 +1,11 @@ +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; + +namespace OpenAuth.Repository.Workflow +{ + public class WorkflowSchemeRepository:WorkflowBaseRepository,IWorkflowSchemeRepository + { + + + } +} diff --git a/OpenAuth.WebTest/Views/Home/Index.cshtml b/OpenAuth.WebTest/Views/Home/Index.cshtml index e031d14f..6b94ecbf 100644 --- a/OpenAuth.WebTest/Views/Home/Index.cshtml +++ b/OpenAuth.WebTest/Views/Home/Index.cshtml @@ -32,7 +32,7 @@ {

可访问的机构

    - @foreach (var org in ViewBag.CurrentUser.AccessedOrgs) + @foreach (var org in ViewBag.CurrentUser.Orgs) {
  • @org.Name
  • } diff --git a/建表&初始化数据.sql b/建表&初始化数据.sql index 17c35b73..6173cf7e 100644 Binary files a/建表&初始化数据.sql and b/建表&初始化数据.sql differ