-
Notifications
You must be signed in to change notification settings - Fork 1
/
Startup.cs
103 lines (95 loc) · 4.54 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SchoolManagementSystem.Data;
using SchoolManagementSystem.Data.Repository;
using SchoolManagementSystem.Helpers;
using SchoolManagementSystem.Models;
namespace SchoolManagementSystem
{
public class Startup
{
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration)
{
_configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// services.AddMvc(options => {
// var policy = new AuthorizationPolicyBuilder()
// .RequireAuthenticatedUser()
// .Build();
// options.Filters.Add(new AuthorizeFilter(policy));
// });
services.Configure<CookiePolicyOptions>(options => {
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContextPool<AppDbContext>(options =>
options.UseSqlServer(_configuration.GetConnectionString("SchoolManagementDB"))
);
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>();
services.ConfigureApplicationCookie(options =>{
options.LoginPath = "/Administrator/Account/Login";
options.Cookie.IsEssential = true;
});
services.AddMvc();
services.AddTransient<IAttendanceRepository, AttendanceRepository>();
services.AddTransient<IStudentRepository, StudentRepository>();
services.AddTransient<IMessageRepository, MessageRepository>();
services.AddTransient<IEntityRepository<Admin>, EntityRepository<Admin>>();
services.AddTransient<IEntityRepository<AdminTask>, EntityRepository<AdminTask>>();
services.AddTransient<IEventRepository, EventRepository>();
services.AddTransient<IEntityRepository<Faculty>, EntityRepository<Faculty>>();
services.AddTransient<IEntityRepository<Department>, EntityRepository<Department>>();
services.AddTransient<IEntityRepository<CourseYear>, EntityRepository<CourseYear>>();
services.AddTransient<IEntityRepository<Course>, EntityRepository<Course>>();
services.AddTransient<ILocation, LocationRepository>();
services.AddTransient<IEntityRepository<LocationCategory>, EntityRepository<LocationCategory>>();
services.AddTransient<ITeacherRepository, TeacherRepository>();
services.AddTransient<ICountryRepository, CountryRepository>();
services.AddScoped<IPasswordGenerator, PasswordGenerator>();
services.AddScoped<IProcessFileUpload, ProcessUploadFile>();
services.AddTransient<IStateRepository, StateRepository>();
services.AddTransient<ITaskRepository, TaskRepository>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseStatusCodePagesWithReExecute("/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "Administrator",
template: "{area:exists}/{controller=dashboard}/{action=index}/{id?}"
);
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
}
}
}