public IActionResult Entry(Trainee model)
 {
     if (ModelState.IsValid)
     {
         TrainingDbContext db = new TrainingDbContext();
         db.Trainees.Add(model);
         db.SaveChanges();
     }
     return(View());
 }
示例#2
0
        public static void SeedHostDb(TrainingDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
示例#3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrainingDbContext context)
        {
            //TrainingSeedData.Initialize(context);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                //app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                //{
                //    HotModuleReplacement = true
                //});
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
            app.UseCors("angular");
            app.UseStaticFiles();


            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var dbContext   = serviceScope.ServiceProvider.GetService <ApplicationDbContext>();
                var roleManager = serviceScope.ServiceProvider.GetService <RoleManager <ApplicationRole> >();
                var userManager = serviceScope.ServiceProvider.GetService <UserManager <ApplicationUser> >();

                dbContext.Database.Migrate();
                UserDataSeeder.SeedIdentityData(dbContext, roleManager, userManager);
            }
            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
示例#4
0
 public InitialHostDbBuilder(TrainingDbContext context)
 {
     _context = context;
 }
示例#5
0
 public SectionRepository(TrainingDbContext context)
 {
     db = context;
 }
 public DefaultSettingsCreator(TrainingDbContext context)
 {
     _context = context;
 }
 public TopicController(TrainingDbContext dbContext)
 {
     context = dbContext;
 }
 public TenantRoleAndUserBuilder(TrainingDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
示例#9
0
 public DefaultEditionCreator(TrainingDbContext context)
 {
     _context = context;
 }
 public TrainingService(TrainingDbContext dbContext)
 {
     _dbContext = dbContext;
 }
示例#11
0
 public DefaultLanguagesCreator(TrainingDbContext context)
 {
     _context = context;
 }
 public TrainingApplication(TrainingDbContext context, IMapper mapper)
 {
     this.Context = context;
     this.Mapper  = mapper;
 }
示例#13
0
 public SearchRepository(TrainingDbContext _db)
 {
     db = _db;
 }
示例#14
0
        //private readonly IHttpContextAccessor _httpContextAccessor;
        #endregion

        #region ctor
        public UnitOfWork(TrainingDbContext _context)
        {
            //Disposetransaction = false;
            Context = _context;
            //  _httpContextAccessor = httpContextAccessor;
        }
示例#15
0
 public StudentRepository(TrainingDbContext _context)
 {
     db = _context;
 }
示例#16
0
 public HostRoleAndUserCreator(TrainingDbContext context)
 {
     _context = context;
 }
示例#17
0
 public BatchImportController(TrainingDbContext _db)
 {
     db = _db;
 }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region DbContext
            services.AddDbContext <TrainingDbContext>(o => o.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddDbContext <ApplicationDbContext>(o => o.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <IRepository <TrainingDbContext>, Repository <TrainingDbContext> >();


            using (var context = new TrainingDbContext())
            {
                context.Database.Migrate();
            }

            #endregion

            #region Localization
            //services.Configure<RequestLocalizationOptions>(o =>
            //{
            //    var SupportedCultrues = new List<CultureInfo>
            //    {
            //        new CultureInfo("ar-SA"),
            //        new CultureInfo("en-US")
            //    };
            //    o.DefaultRequestCulture =new RequestCulture( ArCustomCulture.GetCustomCulture();
            //    //o.DefaultRequestCulture.Culture.DateTimeFormat = new CultureInfo("en-GB").DateTimeFormat;
            //    //o.DefaultRequestCulture.UICulture.DateTimeFormat = new CultureInfo("en-GB").DateTimeFormat;
            //    o.SupportedCultures = SupportedCultrues;
            //    o.SupportedUICultures = SupportedCultrues;

            //    o.RequestCultureProviders = new[] { new RouteDataRequestCultureProvider { } };
            //});
            services.AddLocalization(options => options.ResourcesPath = nameof(Resource));

            #endregion

            #region Jwt
            var key = Encoding.ASCII.GetBytes(Jwt.Key);

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(o =>
            {
                o.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateIssuerSigningKey = true,
                    RequireExpirationTime    = true,
                    ValidIssuer      = Jwt.Issuer,
                    ValidAudience    = Jwt.Audience,
                    IssuerSigningKey = new SymmetricSecurityKey(key)
                };
            });
            services.ConfigureApplicationCookie(o =>
            {
                o.Events = new CookieAuthenticationEvents()
                {
                    OnRedirectToLogin = (ctx) =>
                    {
                        ctx.Response.StatusCode = 401;
                        return(Task.CompletedTask);
                    }
                };
            });
            #endregion

            #region Cors
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll", builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .SetIsOriginAllowed(isOriginAllowed: _ => true);        //for all origins;
                    //builder.SetIsOriginAllowed(isOriginAllowed: _ => true); //for all origins
                });

                IConfigurationSection CorsWebsite = Configuration.GetSection("AllowAll");
                string[] itemArray = CorsWebsite.AsEnumerable().ToList().Where(x => !string.IsNullOrEmpty(x.Value)).Select(x => x.Value).ToArray();

                options.AddPolicy("Client4200", builder =>
                {
                    builder.WithOrigins(itemArray).AllowAnyHeader().AllowAnyMethod().AllowCredentials()
                    .SetIsOriginAllowed(isOriginAllowed: _ => true); //for all origins;;
                });
            });


            #endregion

            #region JasonResponseFormate and Filters


//o =>{o.Filters.Add(typeof(SetLanguage));}
            services.AddMvc().AddNewtonsoftJson()
            .AddNewtonsoftJson(options =>
                               options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                               ).AddJsonOptions(opts =>
            {
                //opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
            })
            ;
            #endregion

            #region Swagger
            services.AddSwaggerGen();

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Api 1", Version = "v1"
                });
                options.OperationFilter <CustomHeaderSwaggerAttribute>();
                options.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); //This line

                //options.OperationFilter<SwaggerFileOperationFilter>();
                options.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme, new OpenApiSecurityScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey,
                    Scheme      = JwtBearerDefaults.AuthenticationScheme,
                    Name        = "Authorization"
                });
                options.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            },
                            Scheme = "oauth2",
                            Name   = "Bearer",
                            In     = ParameterLocation.Header,
                        },
                        new List <string>()
                    }
                });

                //var security = new Dictionary<string, IEnumerable<string>>
                //{
                //{"Bearer", new string[] { }},
            });
            #endregion

            #region Mapping

            // Auto Mapper Configurations
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MapProfile());
            });

            IMapper mapper = mappingConfig.CreateMapper();
            services.AddSingleton(mapper);

            #endregion Mapping

            #region Debdancy Injection

            services.AddScoped <IJwt, ValidateJwt>();

            services.AddScoped <IEncryption, Encryption>();
            services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));

            services.AddScoped <ICategoryService, CategoryService>();
            services.AddScoped <IProductService, ProductService>();
            #endregion
        }
 public DefaultAuthorCreator(TrainingDbContext context)
 {
     _context = context;
 }
 public UsersController(TrainingDbContext context, IConfiguration configuration)
 {
     _context      = context;
     Configuration = configuration;
 }
 public TopicService(TrainingDbContext trainingDb)
 {
     _dbContext = trainingDb;
 }
示例#22
0
 public DefaultCategoryCreator(TrainingDbContext context)
 {
     _context = context;
 }
示例#23
0
        public static void Initialize(TrainingDbContext context)
        {
            context.Database.EnsureCreated();

            if (context.Courses.Any())
            {
                return;
            }

            //if (context.Sections.Any())
            //{
            //    return;
            //}

            //if (context.Students.Any())
            //{
            //    return;
            //}

            var c1 = new Course()
            {
                CourseId        = Guid.NewGuid(),
                CourseName      = "健康職場講座-姿勢好.運動對.痠痛說掰掰",
                CourseStartDate = "2017/12/12",
                CourseEndDate   = "2017/12/12",
                CreateDate      = new DateTime(2017, 12, 12),
                TrainHours      = 2.0
            };
            var c2 = new Course()
            {
                CourseId        = Guid.NewGuid(),
                CourseName      = "106-1期「大型發電機測試及維護班」",
                CourseStartDate = "2017/12/04",
                CourseEndDate   = "2017/12/08",
                CreateDate      = new DateTime(2017, 12, 4),
                TrainHours      = 26.5
            };
            var c3 = new Course()
            {
                CourseId        = Guid.NewGuid(),
                CourseName      = "106-1期「軸承與潤滑班」",
                CourseStartDate = "2017/10/05",
                CourseEndDate   = "2017/10/13",
                CreateDate      = new DateTime(2017, 10, 05),
                TrainHours      = 28.5
            };
            var courses = new Course[]
            {
                c1,
                c2,
                c3
            };

            //var SectionM = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "機械組",
            //    SectionCode = "M"
            //};
            //var SectionN = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "核析組",
            //    SectionCode = "N"
            //};
            //var SectionE = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "電氣組",
            //    SectionCode = "E"
            //};
            //var SectionB = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "PE II",
            //    SectionCode = "B"
            //};
            //var SectionA = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "策劃組",
            //    SectionCode = "A"
            //};
            //var SectionJ = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "儀控組",
            //    SectionCode = "J",

            //};
            //var SectionV = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "處長室",
            //    SectionCode = "V",

            //};
            //var SectionO = new Section()
            //{
            //    //SectionId=1,
            //    SectionName = "移出",
            //    SectionCode = "O",

            //};
            //var sections = new Section[]
            //{
            //    SectionM,
            //    SectionN,
            //    SectionE,
            //    SectionB,
            //    SectionA,
            //    SectionJ,
            //    SectionV,
            //    SectionO
            //};

            //foreach (var course in courses)
            //{
            //    context.Courses.Add(course);
            //}

            //foreach (var section in sections)
            //{
            //    context.Sections.Add(section);
            //}

            //context.SaveChanges();

            //var SJ1 = new Student()
            //{
            //    //StudentId=1,
            //    StudentName = "李念中",
            //    SectionCode = "J",
            //    SectionName = "儀控組",
            //    Section=null,
            //    SectionId = SectionJ.SectionId
            //};
            //var SA1 = new Student()
            //{
            //    // StudentId=2,
            //    StudentName = "廖經政",
            //    SectionCode = "A",
            //    SectionName = "策劃組",
            //    Section = null,
            //    SectionId = SectionA.SectionId
            //};
            //var SN1 = new Student()
            //{
            //    //StudentId=3,
            //    StudentName = "李宗翰",
            //    SectionCode = "N",
            //    SectionName = "核析組",
            //    Section = null,
            //    SectionId = SectionN.SectionId
            //};
            //var SE1 = new Student()
            //{
            //    //
            //    StudentName = "謝文龍",
            //    SectionCode = "E",
            //    SectionName = "電氣組",
            //    Section = null,
            //    SectionId = SectionE.SectionId
            //};
            //var SB1 = new Student()
            //{
            //    //
            //    StudentName = "張漢清",
            //    SectionCode = "B",
            //    SectionName = "PE_II",
            //    Section = null,
            //    SectionId = SectionB.SectionId
            //};
            //var SM1 = new Student()
            //{
            //    //StudentId=6,
            //    StudentName = "陳政瑋",
            //    SectionCode = "M",
            //    SectionName = "機械組",
            //    Section = null,
            //    SectionId = SectionM.SectionId
            //};
            //var SV1 = new Student()
            //{
            //    //StudentId=6,
            //    StudentName = "李瑞蓮",
            //    SectionCode = "V",
            //    SectionName = "處長室",
            //    Section = null,
            //    SectionId = SectionV.SectionId
            //};
            //var SO1 = new Student()
            //{
            //    //StudentId=6,
            //    StudentName = "賴逢裕",
            //    SectionCode = "O",
            //    SectionName = "移出",
            //    Section = null,
            //    SectionId = SectionO.SectionId
            //};
            //var students = new Student[]
            //{
            //   SJ1,
            //   SE1,
            //   SA1,
            //   SB1,
            //   SN1,
            //   SM1,
            //   SV1,
            //   SO1
            //};



            //SectionJ.Students = new List<Student>{
            //    SJ1
            //};
            //SectionE.Students = new List<Student> {
            //    SE1
            //};
            //SectionA.Students = new List<Student> {
            //    SA1
            //};
            //SectionB.Students = new List<Student> {
            //    SB1
            //};
            //SectionN.Students = new List<Student> {
            //    SN1
            //};
            //SectionM.Students = new List<Student> {
            //    SM1
            //};
            //SectionV.Students = new List<Student> {
            //    SV1
            //};
            //SectionO.Students = new List<Student> {
            //    SO1
            //};
            //foreach (var student in students)
            //{
            //    context.Students.Add(student);
            //}

            //context.SaveChanges();
            //var sc1 = new StudentCourse
            //{
            //    CourseId=c1.CourseId,
            //    StudentId=SJ1.StudentId,

            //};

            //var sc2 = new StudentCourse
            //{
            //    CourseId = c1.CourseId,
            //    StudentId = SJ1.StudentId,

            //};

            //var scs = new StudentCourse[]
            //{
            //    sc1
            //};
            //var scs = new StudentCourse[]
            //{
            //    sc1,
            //    sc2,
            //};

            //context.StudentCourses.AddRange(scs);
            //context.SaveChanges();
        }
示例#24
0
 public DefaultTenantBuilder(TrainingDbContext context)
 {
     _context = context;
 }
示例#25
0
 public TrainingRepository(TrainingDbContext context)
 {
     this.context = context;
 }
 public CategoryController(TrainingDbContext dbContext)
 {
     context = dbContext;
 }
示例#27
0
 public SubjectRepository(TrainingDbContext context) : base(context)
 {
 }
示例#28
0
 public AttendeesController(TrainingDbContext dbContext)
 {
     this._dbContext = dbContext;
 }
示例#29
0
 public CourseRepository(TrainingDbContext _context)
 {
     db = _context;
 }
示例#30
0
 public TrainingsController(TrainingDbContext context)
 {
     _context = context;
 }