Skip to content

Commit 8f99508

Browse files
committed
added remove old picture and others
1 parent 6cab458 commit 8f99508

43 files changed

Lines changed: 183086 additions & 65 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.config/dotnet-tools.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {}
5+
}

AcademyManager.csproj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
@@ -13,6 +13,20 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16+
<None Include="wwwroot\js\jspdf\dist\jspdf.es.js" />
17+
<None Include="wwwroot\js\jspdf\dist\jspdf.es.js.map" />
18+
<None Include="wwwroot\js\jspdf\dist\jspdf.es.min.js" />
19+
<None Include="wwwroot\js\jspdf\dist\jspdf.es.min.js.map" />
20+
<None Include="wwwroot\js\jspdf\dist\jspdf.node.js" />
21+
<None Include="wwwroot\js\jspdf\dist\jspdf.node.js.map" />
22+
<None Include="wwwroot\js\jspdf\dist\jspdf.node.min.js" />
23+
<None Include="wwwroot\js\jspdf\dist\jspdf.node.min.js.map" />
24+
<None Include="wwwroot\js\jspdf\dist\jspdf.umd.js" />
25+
<None Include="wwwroot\js\jspdf\dist\jspdf.umd.js.map" />
26+
<None Include="wwwroot\js\jspdf\dist\jspdf.umd.min.js" />
27+
<None Include="wwwroot\js\jspdf\dist\jspdf.umd.min.js.map" />
28+
<None Include="wwwroot\js\jspdf\dist\polyfills.es.js" />
29+
<None Include="wwwroot\js\jspdf\dist\polyfills.umd.js" />
1630
<None Include="wwwroot\webfonts\fa-brands-400.svg" />
1731
<None Include="wwwroot\webfonts\fa-brands-400.woff2" />
1832
<None Include="wwwroot\webfonts\fa-regular-400.svg" />

Controllers/AdministratorsController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Security.Claims;
45
using System.Threading.Tasks;
56
using AcademyManager.Contracts;
67
using AcademyManager.Models;
@@ -96,7 +97,10 @@ public async Task<IActionResult> CreateAdministrators(List<FacilitatorsVM> model
9697
}
9798
else if (!(result.Succeeded))
9899
{
99-
ModelState.AddModelError("", "An error occured while creating the administrators");
100+
foreach (var error in result.Errors)
101+
{
102+
ModelState.AddModelError("", error.Description);
103+
}
100104
return View(model);
101105
}
102106
}
@@ -351,7 +355,7 @@ public async Task<IActionResult> EditCourse(EditCourseVM model)
351355
ModelState.AddModelError("", "Please fill all the required fields correctly");
352356
return View(model);
353357
}
354-
if (model.FacilitatorId != "Select Facilitator")
358+
if (model.FacilitatorId != null)
355359
{
356360
course.FacilitatorId = model.FacilitatorId;
357361
}
@@ -412,6 +416,7 @@ public IActionResult RemoveFromFacilitatorRole(string id)
412416
}
413417

414418
// This method removes a user from the admin role
419+
[Authorize(Policy = "RootAdminPolicy")]
415420
public IActionResult RemoveFromAdminRole(string id)
416421
{
417422
var admin = _userManager.FindByIdAsync(id).Result;

Controllers/UserProfileController.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,19 @@ public async Task<IActionResult> EditProfile(EditProfileVM model)
9797
}
9898
else
9999
{
100-
if (model.PictureUrl != null)
100+
if (model.DeleteOldPicture)
101101
{
102-
string filePath = Path.Combine(_hostEnvironment.WebRootPath, "images", model.PictureUrl);
103-
System.IO.File.Delete(filePath);
102+
if (model.PictureUrl != null)
103+
{
104+
string filePath = Path.Combine(_hostEnvironment.WebRootPath, "images", model.PictureUrl);
105+
System.IO.File.Delete(filePath);
106+
editedUser.PictureUrl = null;
107+
}
108+
else
109+
{
110+
editedUser.PictureUrl = null;
111+
}
104112
}
105-
editedUser.PictureUrl = null;
106113
}
107114
var result = await userManager.UpdateAsync(editedUser);
108115
if (result.Succeeded)

Properties/launchSettings.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{
1+
{
22
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
55
"iisExpress": {
66
"applicationUrl": "http://localhost:3337",
77
"sslPort": 44338
@@ -18,10 +18,10 @@
1818
"AcademyManager": {
1919
"commandName": "Project",
2020
"launchBrowser": true,
21-
"applicationUrl": "https://localhost:5001;http://localhost:5000",
2221
"environmentVariables": {
2322
"ASPNETCORE_ENVIRONMENT": "Development"
24-
}
23+
},
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
2525
}
2626
}
27-
}
27+
}

Repository/CoursesRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using AcademyManager.Contracts;
22
using AcademyManager.Models;
3+
using Microsoft.EntityFrameworkCore;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;

Startup.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ public void ConfigureServices(IServiceCollection services)
4545
//services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
4646
// .AddEntityFrameworkStores<AppDbContext>();
4747
services.AddControllersWithViews();
48+
services.AddAuthorization(option =>
49+
{
50+
option.AddPolicy("RootAdminPolicy", policy => policy.RequireUserName("admin@localhost.com"));
51+
});
4852
services.AddRazorPages();
53+
54+
//services.Configure<IISServerOptions>(options =>
55+
//{
56+
// options.AutomaticAuthentication = false;
57+
//});
4958
}
5059

5160
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

ViewModels/TestAndExamVM.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.Linq;
45
using System.Threading.Tasks;
56

@@ -8,6 +9,7 @@ namespace AcademyManager.ViewModels
89
public class TestAndExamVM
910
{
1011
public int Id { get; set; }
12+
[Display(Name = "Test or Exam Name")]
1113
public string TestOrExamName { get; set; }
1214
public CourseVM Course { get; set; }
1315
public int CourseId { get; set; }

ViewModels/UserProfileVM.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ChangePasswordVM
3535
[Display(Name = "New Password")]
3636
public string NewPassword { get; set; }
3737
[Required]
38-
[DataType(DataType.Password, ErrorMessage = "Wrong password format")]
38+
[Compare("NewPassword", ErrorMessage = "The password fields must match")]
3939
[Display(Name = "Confirm New Password")]
4040
public string ConfiremNewPassword { get; set; }
4141
}
@@ -53,6 +53,8 @@ public class EditProfileVM
5353
[Display(Name = "Phone:")]
5454
[Phone]
5555
public string PhoneNumber { get; set; }
56+
[Display(Name ="Delete Old Picture")]
57+
public bool DeleteOldPicture { get; set; }
5658
public string PictureUrl { get; set; }
5759
public IFormFile Picture { get; set; }
5860
}

Views/Administrators/EditCourse.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="form-group">
2323
<label asp-for="FacilitatorId"></label>
2424
<select asp-for="FacilitatorId" asp-items="@Model.Facilitators">
25-
<option>Select Facilitator</option>
25+
<option value="">Select Facilitator</option>
2626
</select>
2727
@*@Html.DropDownListFor(m => m.Facilitators, new SelectList(Model.Facilitators, "Value", "Text"),"Select Facilitator",
2828
new { @class = "form-control"})*@

0 commit comments

Comments
 (0)