Преглед на файлове

изменение адресации

WoI преди 5 месеца
родител
ревизия
ee11470bd7

+ 1 - 1
OnlineMetodist.API/Controllers/AccountController.cs

@@ -10,7 +10,7 @@ using OnlineMetodist.API.Services;
 
 namespace OnlineMetodist.API.Controllers
 {
-    [Route("api/[controller]")]
+    [Route("[controller]")]
 	[ApiController]
 	public class AccountController : ControllerBase
 	{

+ 2 - 7
OnlineMetodist.API/Controllers/AdministratorController.cs

@@ -10,7 +10,7 @@ using OnlineMetodist.API.Services;
 
 namespace OnlineMetodist.API.Controllers
 {
-	[Route("api/[controller]/[action]")]
+	[Route("[controller]/[action]")]
 	[ApiController]
 	[Authorize(Roles = "Администратор")]
 	public class AdministratorController : ControllerBase
@@ -111,8 +111,8 @@ namespace OnlineMetodist.API.Controllers
 				return StatusCode(500, "Internal server error");
 			}
 		}
+
         [HttpPut]
-        [Route("SetAdministrator")]
         [Authorize(Roles = "Администратор")]
         public async Task<IActionResult> SetAdministrator(Guid idEmploeyy)
         {
@@ -136,7 +136,6 @@ namespace OnlineMetodist.API.Controllers
         }
 
         [HttpDelete]
-        [Route("DeleteAdministrator")]
         [Authorize(Roles = "Администратор")]
         public async Task<IActionResult> DeleteAdministrator(Guid idEmploeyy)
         {
@@ -160,7 +159,6 @@ namespace OnlineMetodist.API.Controllers
         }
 
         [HttpPut]
-        [Route("SetDelegateNMC")]
         [Authorize(Roles = "Администратор")]
         public async Task<IActionResult> SetDelegateNMC(Guid idEmploeyy)
         {
@@ -184,7 +182,6 @@ namespace OnlineMetodist.API.Controllers
         }
 
         [HttpDelete]
-        [Route("DeleteDelegateNMC")]
         [Authorize(Roles = "Администратор")]
         public async Task<IActionResult> DeleteDelegateNMC(Guid idEmploeyy)
         {
@@ -208,7 +205,6 @@ namespace OnlineMetodist.API.Controllers
         }
 
         [HttpPut]
-        [Route("SetHeadOfCorpuse")]
         [Authorize(Roles = "Администратор")]
         public async Task<IActionResult> SetHeadOfCorpuse(Guid idEmploeyy)
         {
@@ -232,7 +228,6 @@ namespace OnlineMetodist.API.Controllers
         }
 
         [HttpDelete]
-        [Route("DeleteHeadOfCorpuse")]
         [Authorize(Roles = "Администратор")]
         public async Task<IActionResult> DeleteHeadOfCorpuse(Guid idEmploeyy)
         {

+ 1 - 1
OnlineMetodist.API/Controllers/EmployeesController.cs

@@ -10,7 +10,7 @@ using OnlineMetodist.API.Services;
 
 namespace OnlineMetodist.API.Controllers
 {
-	[Route("api/[controller]")]
+	[Route("[controller]")]
 	[ApiController]
 	public class EmployeesController : ControllerBase
 	{

+ 5 - 3
OnlineMetodist.API/Controllers/EventsController.cs

@@ -15,7 +15,7 @@ using System.Text.Json;
 namespace OnlineMetodist.API.Controllers
 {
 	[Authorize]
-	[Route("api/[controller]/[action]")]
+	[Route("[controller]/[action]")]
 	[ApiController]
 	public class EventsController : ControllerBase
 	{
@@ -103,13 +103,15 @@ namespace OnlineMetodist.API.Controllers
 
         private bool EventExists(Guid id)
         {
-            return _context.MethodicaCommissions.Any(e => e.Id == id);
+            return _context.Events.Any(e => e.Id == id);
         }
         private async Task<Event?> FindEventAsync(Guid id)
         {
             if (EventExists(id))
             {
-                return await _context.Events.FindAsync(id);
+                return await _context.Events
+					.Include(e => e.FormOfWork)
+					.FirstOrDefaultAsync(e => e.Id == id);
             }
             return null;
         }

+ 1 - 1
OnlineMetodist.API/Controllers/FormOfWorksController.cs

@@ -11,7 +11,7 @@ using OnlineMetodist.API.Models;
 
 namespace OnlineMetodist.API.Controllers
 {
-    [Route("api/[controller]")]
+    [Route("[controller]")]
     [ApiController]
     public class FormOfWorksController : ControllerBase
     {

+ 1 - 1
OnlineMetodist.API/Controllers/HeadOfCorpuseController.cs

@@ -9,7 +9,7 @@ using OnlineMetodist.API.Services;
 
 namespace OnlineMetodist.API.Controllers
 {
-    [Route("api/[controller]/[action]")]
+    [Route("[controller]/[action]")]
     [ApiController]
     [Authorize(Roles = "Заведующий_корпусом")]
     public class HeadOfCorpuseController : Controller

+ 1 - 1
OnlineMetodist.API/Controllers/MethodicalCommissionsController.cs

@@ -13,7 +13,7 @@ using OnlineMetodist.API.Services;
 
 namespace OnlineMetodist.API.Controllers
 {
-	[Route("api/[controller]")]
+	[Route("[controller]")]
 	[ApiController]
 	public class MethodicalCommissionsController : ControllerBase
 	{

+ 1 - 1
OnlineMetodist.API/Controllers/ReportingPeriodController.cs

@@ -9,7 +9,7 @@ using OnlineMetodist.API.Models;
 
 namespace OnlineMetodist.API.Controllers
 {
-	[Route("api/[controller]")]
+	[Route("[controller]")]
 	[ApiController]
 	public class ReportingPeriodController : ControllerBase
 	{

+ 1 - 1
OnlineMetodist.API/Controllers/RolesController.cs

@@ -7,7 +7,7 @@ using OnlineMetodist.API.Data;
 namespace OnlineMetodist.API.Controllers
 {
 	[ApiController]
-	[Route("api/[controller]")]
+	[Route("[controller]")]
 	[Authorize(Roles = "Администратор")]
 	public class RolesController : ControllerBase
 	{

+ 1 - 1
OnlineMetodist.API/Controllers/ValuesFormsController.cs

@@ -6,7 +6,7 @@ using OnlineMetodist.API.Enums;
 namespace OnlineMetodist.API.Controllers
 {
 	[Authorize]
-	[Route("api/[controller]/[action]")]
+	[Route("[controller]/[action]")]
 	[ApiController]
 	public class ValuesFormsController : ControllerBase
 	{

+ 4 - 11
OnlineMetodist.API/Models/MethodicalCommission.cs

@@ -1,24 +1,17 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using System.Text;
+using System.ComponentModel.DataAnnotations;
 using System.Text.Json.Serialization;
-using System.Threading.Tasks;
 
 namespace OnlineMetodist.API.Models
 {
     public class MethodicalCommission
     {
 		[Required]
-		[Display(Name = "Id")]
 		public Guid Id { get; set; }
 		[Required]
-		[Display(Name = "Название МК")]
 		public string Name { get; set; } = null!;
-		public Guid? IdHead { get; set; }
-
-		[JsonIgnore]
+        [JsonIgnore]
+        public Guid? IdHead { get; set; }
+		
 		public Employee? HeadMC { get; set; }
 		[JsonIgnore]
 		public ICollection<Employee> Employees { get; set; } = new List<Employee>();

+ 0 - 3
OnlineMetodist.API/Program.cs

@@ -155,9 +155,6 @@ app.UseDeveloperExceptionPage();
 app.UseSwagger();
 app.UseSwaggerUI(options =>
 {
-	//options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
-	//options.RoutePrefix = string.Empty;
-
 	options.SwaggerEndpoint("./v1/swagger.json", "v1"); //Îòíîñèòåëüíûé ïóòü äî ïîëüçîâàòåëüñêîãî èíòåðôåéñà
 });
 

+ 1 - 1
OnlineMetodist.WebClient/Pages/Events/Details.cshtml

@@ -152,5 +152,5 @@
 </div>
 <div>
 	<a asp-page="./Edit" asp-route-id="@Model.Event.Id">Изменить</a> |
-	<a asp-page="./Index">Back to List</a>
+	<a asp-page="./Index">Назад к списку</a>
 </div>

+ 28 - 8
OnlineMetodist.WebClient/Pages/Events/Details.cshtml.cs

@@ -2,12 +2,20 @@ using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc.RazorPages;
 using OnlineMetodist.WebClient.Models.Events;
 using System;
+using System.Net.Http;
 using System.Text.Json;
 
 namespace OnlineMetodist.WebClient.Pages.Events
 {
     public class DetailsModel : PageModel
     {
+        private readonly IHttpClientFactory _httpClientFactory;
+
+        public DetailsModel(IHttpClientFactory httpClientFactory)
+        {
+            _httpClientFactory = httpClientFactory;
+        }
+
         [BindProperty]
         public Event Event { get; set; }
         [BindProperty]
@@ -20,26 +28,38 @@ namespace OnlineMetodist.WebClient.Pages.Events
         public Publication Publication { get; set; }
 
         [Route("Speaker/{id:int}")]
-        public IActionResult OnGet(Event selection)
+        public async Task<IActionResult> OnGet(Guid id)
         {
-            if(selection == null)
+            if(id == null)
             {
                 return NotFound();
             }
-            
-            switch (selection.FormOfWork.Name)
+
+            var httpClient = _httpClientFactory.CreateClient("OnlineMetodistApi");
+            var headers = HttpContext.Request.Headers.FirstOrDefault(x => x.Key == "Authorization");
+            if (headers.Key == null) return Forbid();
+            httpClient.DefaultRequestHeaders.Add("Authorization", headers.Value.ToList());
+            var response = await httpClient.GetAsync($"Events/GetEvent/{id}");
+
+            // if (response.StatusCode == System.Net.HttpStatusCode.Forbidden) return Forbid();
+            if (!response.IsSuccessStatusCode) return BadRequest();// StatusCode(int.Parse(response.StatusCode.ToString()));
+
+            Event = await response.Content.ReadFromJsonAsync<Event>();
+            if (Event == null) return NotFound();
+
+            switch (Event.FormOfWork.Name)
             {
                 case "Ïðîâåäåíèå":
-                    Holding = JsonSerializer.Deserialize<Holding>(selection.Specifications);
+                    Holding = JsonSerializer.Deserialize<Holding>(Event.Specifications);
                     break;
                 case "Ïóáëèêàöèÿ":
-                    Publication = JsonSerializer.Deserialize<Publication>(selection.Specifications);
+                    Publication = JsonSerializer.Deserialize<Publication>(Event.Specifications);
                     break;
                 case "Ó÷àñòèå":
-                    Participation = JsonSerializer.Deserialize<Participation>(selection.Specifications);
+                    Participation = JsonSerializer.Deserialize<Participation>(Event.Specifications);
                     break;
                 case "Ñòàæèðîâêà":
-                    Internship = JsonSerializer.Deserialize<Internship>(selection.Specifications);
+                    Internship = JsonSerializer.Deserialize<Internship>(Event.Specifications);
                     break;
                 default:
                     return NotFound();

+ 4 - 4
OnlineMetodist.WebClient/Pages/Events/Index.cshtml

@@ -17,7 +17,7 @@
             <th>Статус одобренности</th>
             <th>Коэффициент</th>
             <th>Студент</th>
-            @* <th>Отправить на проверку</th> *@
+            <th>Отправить на проверку</th>
         </tr>
         @foreach (var item in Model.Events)
         {
@@ -29,9 +29,9 @@
                 <td>@item.Coefficient</td>
                 <td>@item.Student</td>
                 <td>
-                    <a asp-page="./Edit" asp-route-selection="@item">Изменить</a> |
-                    <a asp-page="./Details" asp-route-selection="@item">Подробнее</a> |
-                    <a asp-page="./Delete" asp-route-id="@item.Id">Удалить</a>
+                    <a asp-page="./Edit" asp-route-id="@item.Id">Изменить</a> |
+                    <a asp-page="./Details" asp-route-id="@item.Id">Подробнее</a> |
+                    <button type="submit" asp-page-handler="delete" asp-route-id="@item.Id">Удалить</button>
                 </td>
             </tr>
         }

+ 14 - 0
OnlineMetodist.WebClient/Pages/Events/Index.cshtml.cs

@@ -35,6 +35,20 @@ namespace OnlineMetodist.WebClient.Pages.Events
 			}
 			if (response.StatusCode == System.Net.HttpStatusCode.Forbidden) return Forbid();
 			return BadRequest();
+		}		
+		public async Task<IActionResult> OnPostDeleteAsync(Guid id)
+        {			
+			var httpClient = _httpClientFactory.CreateClient("OnlineMetodistApi");
+			var headers = HttpContext.Request.Headers.FirstOrDefault(x => x.Key == "Authorization");
+			if(headers.Key == null) return Forbid();
+			httpClient.DefaultRequestHeaders.Add("Authorization", headers.Value.ToList());
+			var response = await httpClient.GetAsync($"Events/DeleteEvent/{id}");
+			if (response.IsSuccessStatusCode)
+			{
+				return Page();
+			}
+			if (response.StatusCode == System.Net.HttpStatusCode.Forbidden) return Forbid();
+			return BadRequest();
 		}
     }
 }

+ 2 - 2
OnlineMetodist.WebClient/appsettings.json

@@ -1,6 +1,6 @@
 {
-  //"ApiConnectionString": "https://iis.ngknn.ru/NGKNN/ТаранАА/api/",
-  "ApiConnectionString": "https://localhost:7205/api/",
+  "ApiConnectionString": "https://iis.ngknn.ru/NGKNN/ТаранАА/api/",
+  //"ApiConnectionString": "https://localhost:7205/api/",
 
   "JwtTokenSettings": {
     "ValidIssuer": "ExampleIssuer", //заменить на ссылку