|
|
using System;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
//using Application.Domain.Entities;
|
|
|
using Infrastructure.Email;
|
|
|
using Infrastructure.Sms;
|
|
|
using Infrastructure.Web;
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using Ocelot.DependencyInjection;
|
|
|
using Ocelot.Middleware;
|
|
|
using Raven.Embedded;
|
|
|
|
|
|
namespace ApiGateway
|
|
|
{
|
|
|
public class Startup : BaseStartup
|
|
|
{
|
|
|
public Startup(IConfiguration configuration, IHostingEnvironment env) : base(configuration, env)
|
|
|
{
|
|
|
EmbeddedServer.Instance.StartServer();
|
|
|
}
|
|
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
|
{
|
|
|
services.AddTransient<IEmailSender, EmptyEmailSender>();
|
|
|
services.AddTransient<ISmsSender, EmptySmsSender>();
|
|
|
services.AddSignalR(o => o.EnableDetailedErrors = true);
|
|
|
base.ConfigureServices(services);
|
|
|
services.AddOcelot();
|
|
|
}
|
|
|
|
|
|
public override void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
|
{
|
|
|
base.Configure(app, env, loggerFactory);
|
|
|
app.UseOcelot().Wait();
|
|
|
}
|
|
|
|
|
|
public override Task ValidatePrincipal(CookieValidatePrincipalContext arg)
|
|
|
{
|
|
|
return Task.Run(() =>
|
|
|
{
|
|
|
//var userRepo = arg.HttpContext.RequestServices.GetService<IRepository<User>>();
|
|
|
|
|
|
//var userName = arg.Principal.Identity.Name;
|
|
|
//var userPermissions = userRepo.ReadOnlyTable().Where(o => o.UserName == userName)
|
|
|
// .SelectMany(o => o.UserRoles)
|
|
|
// .Select(o => o.Role)
|
|
|
// .SelectMany(o => o.RolePermissions)
|
|
|
// .Select(o => o.Permission.Number)
|
|
|
// .ToList();
|
|
|
//var currentPermissions = arg.Principal.Claims.Where(o => o.Type == "Role").Select(o => o.Value).ToList();
|
|
|
//if (!currentPermissions.SequenceEqual(userPermissions))
|
|
|
//{
|
|
|
// arg.HttpContext.SignOutAsync();
|
|
|
// arg.HttpContext.SignIn(userName, userPermissions, arg.Properties.IsPersistent);
|
|
|
//}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
{
|
|
|
//modelBuilder.Entity<PermissionCategory>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId);
|
|
|
//modelBuilder.Entity<Permission>().HasOne(o => o.Category).WithMany(o => o.Permissions).HasForeignKey(o => o.CategoryId);
|
|
|
//modelBuilder.Entity<UserRole>().HasOne(o => o.User).WithMany(o => o.UserRoles).HasForeignKey(o => o.UserId);
|
|
|
//modelBuilder.Entity<UserRole>().HasOne(o => o.Role).WithMany(o => o.UserRoles).HasForeignKey(o => o.RoleId);
|
|
|
//modelBuilder.Entity<RolePermission>().HasOne(o => o.Role).WithMany(o => o.RolePermissions).HasForeignKey(o => o.RoleId);
|
|
|
//modelBuilder.Entity<RolePermission>().HasOne(o => o.Permission).WithMany(o => o.RolePermissions).HasForeignKey(o => o.PermissionId);
|
|
|
//modelBuilder.Entity<User>().HasIndex(o => o.UserName).IsUnique();
|
|
|
//modelBuilder.Entity<Role>().HasIndex(o => o.Name).IsUnique();
|
|
|
//modelBuilder.Entity<PermissionCategory>().HasIndex(o => o.Number).IsUnique();
|
|
|
//modelBuilder.Entity<Permission>().HasIndex(o => o.Number).IsUnique();
|
|
|
//modelBuilder.Entity<UserRole>().HasIndex(o => new { o.UserId, o.RoleId }).IsUnique();
|
|
|
//modelBuilder.Entity<RolePermission>().HasIndex(o => new { o.RoleId, o.PermissionId }).IsUnique();
|
|
|
////学校课程
|
|
|
////专业分类用来组织学校、学院、系等
|
|
|
//modelBuilder.Entity<MajorCategory>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId);
|
|
|
//modelBuilder.Entity<MajorCategory>().HasIndex(o => new { o.ParentId, o.Number }).IsUnique();
|
|
|
////专业用来组织不同学制,如3年专科、4年本科
|
|
|
//modelBuilder.Entity<Major>().HasOne(o => o.Category).WithMany(o => o.Majors).HasForeignKey(o => o.CategoryId);
|
|
|
////每批次入学的学生,按照学制、就业方向等制定不同的教学计划
|
|
|
//modelBuilder.Entity<TeachingPlan>().HasOne(o => o.Major).WithMany(o => o.Plans).HasForeignKey(o => o.MajorId);
|
|
|
////每个教学计划包含不同个学期和就业方向
|
|
|
//modelBuilder.Entity<Semester>().HasOne(o => o.Plan).WithMany(o => o.Semesters).HasForeignKey(o => o.PlanId);
|
|
|
////每个学期包含多个学期课程
|
|
|
//modelBuilder.Entity<SemesterCourse>().HasOne(o => o.Semester).WithMany(o => o.Courses).HasForeignKey(o => o.SemesterId);
|
|
|
////一个课程期对应多个教学计划学期中的课程,这样将学校的学期课程和课程的期统一起来
|
|
|
//modelBuilder.Entity<SemesterCourse>().HasOne(o => o.Term).WithMany(o => o.SemesterCourses).HasForeignKey(o => o.TermId);
|
|
|
|
|
|
////课程分类
|
|
|
//modelBuilder.Entity<CourseCategory>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId);
|
|
|
//modelBuilder.Entity<CourseCategory>().HasIndex(o => new { o.ParentId, o.Number }).IsUnique();
|
|
|
|
|
|
////课程分类
|
|
|
//modelBuilder.Entity<BookCategory>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId);
|
|
|
//modelBuilder.Entity<BookCategory>().HasIndex(o => new { o.ParentId, o.Number }).IsUnique();
|
|
|
//modelBuilder.Entity<Book>().HasOne(o => o.BookCategory).WithMany(o => o.Books).HasForeignKey(o => o.BookCategoryId);
|
|
|
//modelBuilder.Entity<Section>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId);
|
|
|
//modelBuilder.Entity<Section>().HasIndex(o => new { o.ParentId, o.Number }).IsUnique();
|
|
|
|
|
|
////每本书有多个章节
|
|
|
//modelBuilder.Entity<Section>().HasOne(o => o.Book).WithMany(o => o.Sections).HasForeignKey(o => o.BookId);
|
|
|
|
|
|
////课程
|
|
|
//modelBuilder.Entity<Course>().HasOne(o => o.Category).WithMany(o => o.Courses).HasForeignKey(o => o.CategoryId);
|
|
|
////每个课程有多个期
|
|
|
//modelBuilder.Entity<Term>().HasOne(o => o.Course).WithMany(o => o.Terms).HasForeignKey(o => o.CourseId);
|
|
|
//modelBuilder.Entity<Term>().HasOne(o => o.Book).WithMany(o => o.Terms).HasForeignKey(o => o.BookId);
|
|
|
////每期有多个课时
|
|
|
//modelBuilder.Entity<Lesson>().HasOne(o => o.Term).WithMany(o => o.Lessons).HasForeignKey(o => o.TermId);
|
|
|
|
|
|
////课时和资源多对多多对多
|
|
|
//modelBuilder.Entity<LessonResource>().HasOne(o => o.Lesson).WithMany(o => o.LessonResources).HasForeignKey(o => o.LessionId);
|
|
|
//modelBuilder.Entity<LessonResource>().HasOne(o => o.Resource).WithMany(o => o.LessonResources).HasForeignKey(o => o.ResourceId);
|
|
|
//modelBuilder.Entity<LessonResource>().HasIndex(o => new { o.LessionId, o.ResourceId }).IsUnique();
|
|
|
|
|
|
////学生和课程的期多对多
|
|
|
//modelBuilder.Entity<TermUser>().HasOne(o => o.Term).WithMany(o => o.TermUsers).HasForeignKey(o => o.TermId);
|
|
|
//modelBuilder.Entity<TermUser>().HasOne(o => o.User).WithMany(o => o.TermUsers).HasForeignKey(o => o.UserId);
|
|
|
//modelBuilder.Entity<TermUser>().HasIndex(o => new { o.TermId, o.UserId }).IsUnique();
|
|
|
|
|
|
//modelBuilder.Entity<ResourceCategory>().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId);
|
|
|
//modelBuilder.Entity<Resource>().HasOne(o => o.User).WithMany(o => o.Resources).HasForeignKey(o => o.UserId);
|
|
|
//modelBuilder.Entity<Resource>().HasOne(o => o.Category).WithMany(o => o.Resources).HasForeignKey(o => o.CategoryId);
|
|
|
//modelBuilder.Entity<Resource>().HasOne(o => o.Course).WithMany(o => o.Resources).HasForeignKey(o => o.CourseId);
|
|
|
//modelBuilder.Entity<Resource>().HasOne(o => o.Section).WithMany(o => o.Resources).HasForeignKey(o => o.SectionId);
|
|
|
//modelBuilder.Entity<Resource>().Property(o => o.Name).IsRequired().HasMaxLength(255);
|
|
|
////习题
|
|
|
//modelBuilder.Entity<Question>().HasOne(o => o.User).WithMany(o => o.Questions).HasForeignKey(o => o.UserId);
|
|
|
//modelBuilder.Entity<Question>().HasOne(o => o.Course).WithMany(o => o.Questions).HasForeignKey(o => o.CourseId);
|
|
|
//modelBuilder.Entity<Question>().HasOne(o => o.Section).WithMany(o => o.Questions).HasForeignKey(o => o.SectionId);
|
|
|
////习题答题记录
|
|
|
//modelBuilder.Entity<UserQuestion>().HasOne(o => o.User).WithMany(o => o.UserQuestions).HasForeignKey(o => o.UserId);
|
|
|
//modelBuilder.Entity<UserQuestion>().HasOne(o => o.Question).WithMany(o => o.UserQuestions).HasForeignKey(o => o.QuestionId);
|
|
|
//modelBuilder.Entity<UserQuestion>().HasIndex(o => new { o.UserId, o.QuestionId }).IsUnique();
|
|
|
////试题答题记录
|
|
|
//modelBuilder.Entity<UserPaperQuestion>().HasOne(o => o.User).WithMany(o => o.UserPaperQuestions).HasForeignKey(o => o.UserId);
|
|
|
//modelBuilder.Entity<UserPaperQuestion>().HasOne(o => o.PaperQuestion).WithMany(o => o.UserPaperQuestions).HasForeignKey(o => o.PaperQuestionId);
|
|
|
//modelBuilder.Entity<UserPaperQuestion>().HasIndex(o => new { o.UserId, o.PaperQuestionId }).IsUnique();
|
|
|
////试卷答题记录
|
|
|
//modelBuilder.Entity<UserPaper>().HasOne(o => o.User).WithMany(o => o.UserPapers).HasForeignKey(o => o.UserId);
|
|
|
//modelBuilder.Entity<UserPaper>().HasOne(o => o.Paper).WithMany(o => o.UserPapers).HasForeignKey(o => o.PaperId);
|
|
|
//modelBuilder.Entity<UserPaper>().HasIndex(o => new { o.UserId, o.PaperId }).IsUnique();
|
|
|
|
|
|
////考题是具有习题的属性和分值等其他和试卷相关的属性
|
|
|
//modelBuilder.Entity<PaperQuestion>().HasOne(o => o.Paper).WithMany(o => o.Questions).HasForeignKey(o => o.PaperId);
|
|
|
}
|
|
|
|
|
|
public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration)
|
|
|
{
|
|
|
//dbContext.Set<PermissionCategory>().Add(new PermissionCategory
|
|
|
//{
|
|
|
// Name = "配置",
|
|
|
// Number = "Configuration",
|
|
|
// Permissions = new List<Permission> {
|
|
|
// new Permission { Name = "查询配置", Number = "ListConfiguration",DisplayOrder =1 },
|
|
|
// new Permission { Name = "修改配置", Number = "EditConfiguration",DisplayOrder =2 }
|
|
|
// }
|
|
|
//});
|
|
|
//int i = 1;
|
|
|
//var skipReadCollection = new string[] { "Permission" };
|
|
|
//var skipAddCollection = new string[] { "Permission", "Setting", "Node", "Device", "Data", "Api", "Parameter" };
|
|
|
//foreach (var item in dbContext.Model.GetEntityTypes())
|
|
|
//{
|
|
|
// var type = item.ClrType;
|
|
|
// var name = type.GetDisplayName();
|
|
|
// var number = type.Name;
|
|
|
// var category = new PermissionCategory
|
|
|
// {
|
|
|
// Name = name,
|
|
|
// Number = type.Name,
|
|
|
// DisplayOrder = i
|
|
|
// };
|
|
|
// category.Permissions.Add(new Permission { Name = $"查询{name}", Number = $"List{number}", DisplayOrder = 10 * i + 1 });
|
|
|
// if (!skipReadCollection.Contains(type.Name))
|
|
|
// {
|
|
|
// category.Permissions.Add(new Permission { Name = $"查看{name}", Number = $"Read{number}", DisplayOrder = 10 * i + 2 });
|
|
|
// }
|
|
|
// if (!skipAddCollection.Contains(type.Name))
|
|
|
// {
|
|
|
// category.Permissions.Add(new Permission { Name = $"添加{name}", Number = $"Add{number}", DisplayOrder = 10 * i + 3 });
|
|
|
// }
|
|
|
// if (!typeof(IDisableUpdate).IsAssignableFrom(type))
|
|
|
// {
|
|
|
// category.Permissions.Add(new Permission { Name = $"修改{name}", Number = $"Edit{number}", DisplayOrder = 10 * i + 4 });
|
|
|
// }
|
|
|
// if (!typeof(IDisableDelete).IsAssignableFrom(type))
|
|
|
// {
|
|
|
// category.Permissions.Add(new Permission { Name = $"删除{name}", Number = $"Delete{number}", DisplayOrder = 10 * i + 5 });
|
|
|
// }
|
|
|
// dbContext.Set<PermissionCategory>().Add(category);
|
|
|
// i += 1;
|
|
|
//}
|
|
|
//dbContext.SaveChanges();
|
|
|
//var adminRole = new Role { Name = "管理员", IsReadOnly = true };
|
|
|
//foreach (var item in dbContext.Set<Permission>())
|
|
|
//{
|
|
|
// adminRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true });
|
|
|
//}
|
|
|
//var user1Id = dbContext.Set<User>().Add(new User
|
|
|
//{
|
|
|
// UserName = "admin",
|
|
|
// UserRoles = new List<UserRole> { new UserRole { Role = adminRole } }
|
|
|
//}).Entity.Id;
|
|
|
//dbContext.SaveChanges();
|
|
|
////课程分类
|
|
|
//dbContext.Set<CourseCategory>().Add(new CourseCategory { Name = "高职高专", Number = "2", DisplayOrder = 2 });
|
|
|
//dbContext.Set<CourseCategory>().Add(new CourseCategory { Name = "大学大专", Number = "3", DisplayOrder = 3 });
|
|
|
//dbContext.Set<CourseCategory>().Add(new CourseCategory { Name = "大学", Number = "4", DisplayOrder = 4 });
|
|
|
//dbContext.Set<CourseCategory>().Add(new CourseCategory { Name = "研究生", Number = "5", DisplayOrder = 5 });
|
|
|
//dbContext.Set<CourseCategory>().Add(new CourseCategory { Name = "成人教育", Number = "6", DisplayOrder = 6 });
|
|
|
//dbContext.Set<CourseCategory>().Add(new CourseCategory { Name = "职业培训", Number = "7", DisplayOrder = 7 });
|
|
|
//dbContext.SaveChanges();
|
|
|
////教学计划
|
|
|
//var major1 =
|
|
|
//dbContext.Set<MajorCategory>().Add(new MajorCategory
|
|
|
//{
|
|
|
// Name = "计算机学院",
|
|
|
// Number = "0",
|
|
|
// Majors = new List<Major>
|
|
|
// {
|
|
|
// new Major{
|
|
|
// Name="计算机科学与技术",
|
|
|
// Plans = new List<TeachingPlan>
|
|
|
// {
|
|
|
// new TeachingPlan
|
|
|
// {
|
|
|
// Start=DateTime.Now.Date,
|
|
|
// Years=4,
|
|
|
// Degree="学士",
|
|
|
// Career="软件工程方向",
|
|
|
// Semesters = new List<Semester>
|
|
|
// {
|
|
|
// new Semester
|
|
|
// {
|
|
|
// Name="第1学期",
|
|
|
// Courses = new List<SemesterCourse>
|
|
|
// {
|
|
|
// new SemesterCourse
|
|
|
// {
|
|
|
// Name="计算机应用",
|
|
|
// Number ="106090100",
|
|
|
// Category="学科基础课",
|
|
|
// Type="必修课",
|
|
|
// Score=4
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//});
|
|
|
//dbContext.SaveChanges();
|
|
|
////资源类型初始化
|
|
|
//var resourceTypeId1 = dbContext.Set<ResourceCategory>().Add(new ResourceCategory { Name = "文档", Number = "01", DisplayOrder = 01 }).Entity.Id;
|
|
|
//dbContext.Set<ResourceCategory>().Add(new ResourceCategory { Name = "音频", Number = "01", DisplayOrder = 01 });
|
|
|
//dbContext.Set<ResourceCategory>().Add(new ResourceCategory { Name = "视频", Number = "01", DisplayOrder = 01 });
|
|
|
//dbContext.Set<ResourceCategory>().Add(new ResourceCategory { Name = "动画", Number = "01", DisplayOrder = 01 });
|
|
|
//dbContext.Set<ResourceCategory>().Add(new ResourceCategory { Name = "虚拟仿真", Number = "01", DisplayOrder = 01 });
|
|
|
////资源分类初始化
|
|
|
//dbContext.SaveChanges();
|
|
|
//dbContext.Set<CourseCategory>().Add(new CourseCategory
|
|
|
//{
|
|
|
// Name = "中职中专",
|
|
|
// Number = "1",
|
|
|
// DisplayOrder = 1,
|
|
|
// Children = new List<CourseCategory> {
|
|
|
// new CourseCategory
|
|
|
// {
|
|
|
// Name="公开课",
|
|
|
// Number="1",
|
|
|
// DisplayOrder=1
|
|
|
// },
|
|
|
// new CourseCategory
|
|
|
// {
|
|
|
// Name="专业课",
|
|
|
// Number="2",
|
|
|
// DisplayOrder=2,
|
|
|
// Children=new List<CourseCategory>
|
|
|
// {
|
|
|
// new CourseCategory
|
|
|
// {
|
|
|
// Name = "信息技术类",
|
|
|
// Number = "10609",
|
|
|
// DisplayOrder = 106,
|
|
|
// Children = new List<CourseCategory>
|
|
|
// {
|
|
|
// new CourseCategory
|
|
|
// {
|
|
|
// Name="计算机应用",
|
|
|
// Number="106090100",
|
|
|
// DisplayOrder=106010100,
|
|
|
// Courses = new List<Course>
|
|
|
// {
|
|
|
// new Course
|
|
|
// {
|
|
|
// Name="Java基础",
|
|
|
// Number="10001",
|
|
|
// Image="/upload/1.jpg",
|
|
|
// Description="本课程是以Java语言来讲授程序设计的入门知识,而非具体教授Java语言,关于Java语言的全面知识,还需要学习本课程的后续课程——“Java语言程序设计进阶”。",
|
|
|
// Terms = new List<Term>
|
|
|
// {
|
|
|
// new Term
|
|
|
// {
|
|
|
// Name="2018-2019学年下学期",
|
|
|
// Start= new DateTime(2018,9,1),
|
|
|
// End=new DateTime(2019,1,1),
|
|
|
// Lessons=new List<Lesson>
|
|
|
// {
|
|
|
// new Lesson
|
|
|
// {
|
|
|
// Name="导论",
|
|
|
// DisplayOrder=1
|
|
|
// },
|
|
|
// new Lesson
|
|
|
// {
|
|
|
// Name="基础",
|
|
|
// DisplayOrder=2
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//});
|
|
|
//dbContext.SaveChanges();
|
|
|
//dbContext.Set<BookCategory>().Add(new BookCategory
|
|
|
//{
|
|
|
// Name = "理科教材",
|
|
|
// Number = "0000",
|
|
|
// Books = new List<Book>
|
|
|
// {
|
|
|
// new Book
|
|
|
// {
|
|
|
// Name="计算机应用基础",
|
|
|
// Number="ISBN 0000",
|
|
|
// Sections = new List<Section>
|
|
|
// {
|
|
|
// new Section
|
|
|
// {
|
|
|
// Name="导论上",
|
|
|
// Number="1.1"
|
|
|
// },
|
|
|
// new Section
|
|
|
// {
|
|
|
// Name="导论下",
|
|
|
// Number="1.2"
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//});
|
|
|
//dbContext.SaveChanges();
|
|
|
//dbContext.Set<Resource>().Add(new Resource
|
|
|
//{
|
|
|
// CategoryId = dbContext.Set<ResourceCategory>().FirstOrDefault(o => o.Name == "视频").Id,
|
|
|
// Name = "导论",
|
|
|
// File = "/upload/1.mp4",
|
|
|
// UserId = user1Id,
|
|
|
// CourseId = dbContext.Set<Course>().FirstOrDefault(o => o.Name == "Java基础").Id,
|
|
|
// SectionId = dbContext.Set<Section>().FirstOrDefault(o => o.Name == "导论上").Id,
|
|
|
//});
|
|
|
//dbContext.SaveChanges();
|
|
|
//dbContext.Set<LessonResource>().Add(new LessonResource
|
|
|
//{
|
|
|
// Name = "视频",
|
|
|
// LessionId = dbContext.Set<Lesson>().FirstOrDefault(o => o.Name == "导论").Id,
|
|
|
// ResourceId = dbContext.Set<Resource>().FirstOrDefault(o => o.Name == "导论").Id,
|
|
|
//});
|
|
|
//dbContext.SaveChanges();
|
|
|
//foreach (var item in dbContext.Set<CourseCategory>())
|
|
|
//{
|
|
|
// item.UpdatePath();
|
|
|
//}
|
|
|
//dbContext.SaveChanges();
|
|
|
}
|
|
|
}
|
|
|
} |