Task_Tracker_SUBD/TaskTrackerRestAPI/TaskTrackerClientApp/Controllers/EmployeeController.cs
2023-05-17 10:48:52 +04:00

101 lines
2.3 KiB
C#

using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.SearchModels;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerClientApp.Controllers
{
public class EmployeeController : Controller
{
private readonly ILogger<EmployeeController> _logger;
public EmployeeController(ILogger<EmployeeController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult CreateEmployee()
{
return View();
}
[HttpPost]
public void CreateEmployee(string name, string jobtitle, string email)
{
if (APIClient.Company == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/employee/createemployee", new
EmployeeBindingModel
{
CompanyId = APIClient.Company.Id,
Name = name,
JobTitle = jobtitle,
Email = email
});
Response.Redirect("/Home/Employees");
}
[HttpPost]
public void DeleteEmployee(int id)
{
if (APIClient.Company == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/employee/deleteemployee", new
EmployeeSearchModel
{
CompanyId = APIClient.Company.Id,
Name = "f",
Id = id
});
Response.Redirect("/Home/Employees");
}
[HttpGet]
public IActionResult UpdateEmployee()
{
return View();
}
[HttpPost]
public void UpdateEmployee(int id, string name, string state)
{
if (APIClient.Company == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/employee/updateemployee", new
ProjectBindingModel
{
CompanyId = APIClient.Company.Id,
Name = name,
State = state,
Id = id
});
Response.Redirect("/Home/Index");
}
[HttpGet]
public void ReportEmployee(int id)
{
if (APIClient.Company == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest($"api/task/gettaskemployeelist?id={id}", id);
Response.Redirect("/Home/ReportEmployee");
}
}
}